tet3828 Posted November 1, 2006 Share Posted November 1, 2006 My script is driving me nuts >:(The script gets the an item number from a previous page and displays all its stored info as an html table. Great! that part is cool.Then below the table is some html/php forms that give the use the option to modify the data.However, instead of modifying the data I am pinpointing; it ereases it from the mySQL database. why is this happening and what can I do to get the result I am expecting?I am obviously approaching this incorrectly. pls help me get back on track here. thanx againthe script:<?php/// Store Passed Data as $id$id = $_GET['id'];/// Select data from mySQL table$qry = "SELECT itemName,itemCat,itemSub,itemId,itemPrice,itemDesc,itemSmall FROM `products` WHERE `itemId`=\"$id\"";$result = mysql_query($qry) or die(mysql_error());/// page headerecho "Listed below is the stored data for the item #$id <br /> Use the fields below the item table to modify the information.";echo "<br /> ";echo "<br />";echo "<br />";/// Display item data loopwhile($row = mysql_fetch_array($result)){ echo "<table border=\"1\"><tr><td>".$row['itemName']."<td>".$row['itemId']."</td></td></tr>"; echo "<tr><td><img src=\"".$row['itemSmall']."\" /></td><td valign=top width=150>Description:<br />".$row['itemDesc']."</td>"; echo "</tr><tr><td>Price: $".$row['itemPrice']."</td><td>Avilibility: </td></tr>"; echo "<tr><td width=150>Catagory: ".$row['itemCat']."</td><td width=150>Sub-Catagory:".$row['itemSub']."</td></tr>";}echo "</table>";echo "<br /> ";/// modification form and query?><?phpif (!isset($_POST['submit'])){$newId = $_POST['newId'];$query = "UPDATE products SET itemName='$newId' WHERE `itemId`=\"$id\"";$result2 = mysql_query($query);if ($result2) echo "<p>Update done.</p>";else echo "<p>yeah that sux, shit didn't work</p>";}?> <form method="post" action="<?php echo $PHP_SELF;?>"><p>Item Name:<br /></p><input type="text" name="newName" size="10" maxlength="10" value="" /><input type="submit" name="submit" value="Modify" /></form></body> Quote Link to comment Share on other sites More sharing options...
btherl Posted November 1, 2006 Share Posted November 1, 2006 You need to expicility add any variable you want to access after the form submit to the form itself. In this case, I think you need:[code]<form>...<input type=hidden name=itemId value="<? echo $itemId ?>">..</form>[/code]Then when that form is submitted, $_POST['itemId'] will be available.The point here is that variable available the first time your script is run (in response to a GET request), are NOT available the second time, unless you explicitly make them available. You could also use sessions to store the values you want to keep between script requests. Quote Link to comment Share on other sites More sharing options...
tet3828 Posted November 1, 2006 Author Share Posted November 1, 2006 I tried to read up on posting and getting info but im still not fully grasping the concept. I added the line to explictlly modify the item... worked great. The script now changes the data in my MySQL database.However, I don't understand why the submit button is not working?Also when the page is refreshed after pressing enter for the field. it doesn't change the value in my table until the second time I submit data with the enter key? ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.