tet3828 Posted October 26, 2006 Share Posted October 26, 2006 The script below gives the user a visual of items in the mySQL database I've setup.I added an edit button to the script (commented below)what script do I need to add in order to modify the entities of an item's row in the DB when the edit button is pressed? :-\<?phpif(!isset($_POST['submit'])){die("<html><body><form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\"><select name=\"cat\"><option value=\"Holiday\">Holiday</option><option value=\"Animals\">Animals</option></select><input type=\"submit\" name=\"submit\" value=\"Search!\"></form></body></html>");}$qry = "SELECT itemName,itemPrice,itemSmall FROM `products` WHERE itemCat='".$_POST['cat']."'";$result = mysql_query($qry) or die(mysql_error());while($row = mysql_fetch_array($result)){ echo "<table border=\"1\"><tr><td>".$row['itemName']."</td></tr>"; echo "<tr><td><img src=\"".$row['itemSmall']."\" /></td>"; echo "</tr><tr><td>Price: $".$row['itemPrice']."</td>"; echo "</tr>"; echo "<tr><td> <input type=\"submit\" name=\"submit\" value=\"Edit This Item\"> \\\EDIT button </form>"; echo "</td></tr>"; echo "<br>"; echo "<br>"; }echo "</table>";?> Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted October 26, 2006 Share Posted October 26, 2006 UPDATE `table_name` WHERE id=$id_variable SET `field_you_are_editing`=$new_data LIMIT 1assuming you have a form that gets the old data, & posts it as $new_data when it has been edited and submitted. That's just the SQL. if you need some help with the php, i'll help you, but as long as you have that SQL, all you should do is really just run the query. Quote Link to comment Share on other sites More sharing options...
tet3828 Posted October 26, 2006 Author Share Posted October 26, 2006 yep I deff need help with the php. do I have to put some sort of form action inside the while loop? Quote Link to comment Share on other sites More sharing options...
tet3828 Posted October 26, 2006 Author Share Posted October 26, 2006 and if it makes a difference...the currently stored entities on the mySQL table 'products'is as followsitemNameitemDescitemIDitemPriceitemCatitemSubitemAvalitemSmallitemImage Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted October 27, 2006 Share Posted October 27, 2006 oh i'm sorry, i was confused as to what you were trying to do:this doesn't have to be in a form at allwhat you need to do isstill keep the loop that shows the info for each row, that part is finemake a file called edit.php (you'll know what to do with this in a second)now instead of a button, i'd use a link that says "edit"; now, inside the while loop where you have the link make it <a href="edit.php?id=$row['itemID']">(with the properly escaped characters of course)now in your edit.php file, where you have the text form to update the row, use the following query to select the row:[code]<?php$id = $_GET['id'];//put your connection stuff and all that here, i'll skip to the query$sql = "SELECT * FROM `products` WHERE `itemID`=\"$id\"";//then echo the data into your textarea?>[/code]hopefully i've cleared up the method of using the id in a linkas you can see, all you do is call the itemID value into the edit.php?id=itemID part of the link, and that value is picked up by the $_GET variable in edit.php, and used to select the data from that row. Quote Link to comment Share on other sites More sharing options...
tet3828 Posted October 27, 2006 Author Share Posted October 27, 2006 you php ppl rock my frickin socks ThankX-Trev Quote Link to comment Share on other sites More sharing options...
tet3828 Posted October 28, 2006 Author Share Posted October 28, 2006 in the commented line below.... why is the whole H REF tag being echoed insted of the actual link between the tags? echo "<table border=\"1\"><tr><td>".$row['itemName']."</td></tr>"; echo "<tr><td><img src=\"".$row['itemSmall']."\" /></td>"; echo "</tr><tr><td>Price: $".$row['itemPrice']."</td>"; echo "</tr>"; echo "<tr><td><a href=\"edit.php?id=".$row['itemId']." />Edit This Item</a>"; \\\\this line actually echos the whole a href tag, what am I doing wrong? echo "</td></tr>"; echo "<br>"; echo "<br>"; Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted October 28, 2006 Share Posted October 28, 2006 because you don't use [/url] for one thing, you use [code]</a>[/code]. also, anchor tags aren't self closing, so there shouldn't be a slash at the end of your link tag. 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.