Forum Moderators: coopster

Message Too Old, No Replies

Can I get some help with an update form?

         

tyles

7:42 pm on May 14, 2008 (gmt 0)

10+ Year Member



It seems to work with no errors in Firefox, but will not work in IE. It seems to display fine, but after changing information and submitting I'm getting

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/wwwcard/public_html/admin/edit.php on line 28

and it's showing the form with no information in it and no changes are made.

My table consists of 8 fields, two of which are image urls and do not need updated. I'm very new to php and have pretty much pieced this together from various tutorials I've found. It does update in Firefox, but my client uses IE.

<?php
session_start();
if(!session_is_registered('myusername')){
header("location:index.php");
}
?>
<html>
<head>
<title>Card-Couture :: Administration</title>
<link rel=stylesheet type="text/css" href="../style.css" />
<style type="text/css">@import url(../style.css);</style>
</HEAD>
</head>
<body>
<div id="header"><a href="index.php"><img src="images/card-couture.gif" class="logo"></a></div>
<div id="container2">

<div id="content">
<?
//connect to database
include 'opendb.php';
{
if (!isset($_POST["submit"]))
{
$id = $_GET[id];
$sql = "SELECT * FROM store_items WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result)
?>

<form action="edit.php" method="post">
<input type="hidden" name="id" value="<?php echo $myrow["id"] ?>">
<img src="../image/<?php echo $myrow["item_thumb"] ?>">
<br>
<br>
Card Name:<br>
<input name="item_title" size="40" maxlength="255" value="<?php echo $myrow["item_title"] ?>" >
<br>
<br>
You must select the correct form.<br>
Form Type:<br>
<select name="item_form">
<option value="birth"> Birth Announcement</option>
<option value="multiple"> Multiples Announcement</option>
<option value="invitation"> Invitation</option>
<option value="save_the_date"> Save-the-Date</option>
<option value="graduation"> Graduation</option>
<option value="holiday"> Holiday</option>
<option value="keepsake"> Keepsake</option>
<option value="notecard"> Notecard</option>
<option value="business"> Business</option>
</select>
<br>
<br>
Description:<br>
<textarea name="item_desc" rows="7" cols="30" value="<?php echo $myrow["item_desc"] ?>"></textarea>
<br>
<br>
Product ID: (to identify card at Mal's)</strong><br>
<input type="text" name="prodid" size=30 value="<?php echo $myrow["prodid"] ?>">
<br>
<br>
You must select the correct category.<br>
Category:<br>
<select name="cat_id">
<option value="8"> Birth Announcements - Girl</option>
<option value="9"> Birth Announcements - Boy</option>
<option value="10"> Birth Announcements - Multiples</option>
<option value="3"> Invitations</option>
<option value="5"> Save-the-Date</option>
<option value="4"> Graduation</option>
<option value="17"> Holiday & Seasonal - Christmas</option>
<option value="18"> Holiday & Seasonal - Easter</option>
<option value="19"> Holiday & Seasonal - Valentine</option>
<option value="20"> Holiday & Seasonal - Other</option>
<option value="6"> Keepsake Cards</option>
<option value="12"> Petit Couture - Artwork Notecards</option>
<option value="13"> Petit Couture - Petit Business Cards</option>
</select>
<br>
<br>


<input type="image" src="../images/submit.gif" alt="submit" border="0" name="submit" value="Submit">

</form>

<? } ?>

<?
if(isset($_POST['submit']))
{
$item_title = mysql_real_escape_string($_POST['item_title']);
$item_form = mysql_real_escape_string($_POST['item_form']);
$item_desc = mysql_real_escape_string($_POST['item_desc']);
$prodid = mysql_real_escape_string($_POST['prodid']);
$cat_id = mysql_real_escape_string($_POST['cat_id']);

$id = mysql_real_escape_string($_POST['id']);

$sql = "UPDATE store_items SET cat_id='$cat_id',item_title='$item_title',item_desc='$item_desc',item_form='$item_form',prodid='$prodid' WHERE id=$id";

$return = mysql_query($sql);
echo "Card has been updated!<br><br>Return to <a href=\"card-list.php\">Card List</a><br>Return to <a href=\"adminindex.php\">Admin Index</a>";
}
}
?>
</div>
<div id="footer"></div>
</div>
<div id="credit"><p>&copy 2008 example.com &nbsp;&nbsp;&nbsp; Created by <a href="http://www.example.com">example.com</a></p></div>
</body>
</html>

[edited by: eelixduppy at 7:48 pm (utc) on May 14, 2008]
[edit reason] please use example.com [/edit]

d40sithui

8:56 pm on May 14, 2008 (gmt 0)

10+ Year Member



well after taking a quick look: at line 28, it seems you did not end with a semicolon.
but thats not consistent with the error that you reported. $results is not valid, which means the query is not valid, which in turn probably means that the $id is not valid.

tyles

1:08 am on May 15, 2008 (gmt 0)

10+ Year Member



Yikes, that probably got dropped during my attempt to fix it. Ok, the page is accessed via ..../admin/edit.php?id=203 I put the semicolon in and it still errors the same way in IE and does not update anything. No errors and updates do occur in Firefox.

dreamcatcher

2:51 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try enclosing your id var in single quotes:

id='$id'";

dc

tyles

5:51 pm on May 15, 2008 (gmt 0)

10+ Year Member



The single quote didn't do anything. However, as I was pouring over the code again, I realized I was using an image for the "submit" button. I remembered reading about using if(isset($_POST['submit_x'])) when using an image for submit. Now it does update, but also shows the form after updating so I'll need to work on that part. I do have a curiousity question now, can you tell me the reason behind or purpose for submit_x for IE?

Thank you! It seems asking for help always tends to make the issue jump right out!

chorny

8:14 pm on May 15, 2008 (gmt 0)

10+ Year Member



tyles, you need to check return values for errors. In general, mysql is deprecated, use PDO.