xtopolis Posted May 9, 2009 Share Posted May 9, 2009 Items should have a unique id for themselves (such as an auto incrementing primary key) so that you can edit other information (such as item name) without changing the item's uniqueness. That would solve some problems. Otherwise you will have to do it your way, changing the name at the beginning , but looking for the old name ($gotit) to search on.. (bad practice). Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830052 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 the items do have a id ... god i feel stupid...... but I'm pretty sure I tried do it that way.. <?php $sql = "UPDATE abcxyz SET item_name = '$item_name', description = '$description', in_return = '$in_return' WHERE id = '$something'"; ?> Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830055 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 So I should do a query to get the id eh? Sorry,,, I'm still a newb to PHP... some stuff I know,, but there is a lot I still need to learn. Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830057 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 Edit - Doesn't make sense. You're updating item_name while using a WHERE clause to check for it. Get in an id. Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830058 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 ken2k7 what do you mean? xtopolis do you know what he is saying? Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830061 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 Okay, before you had your WHERE clause set to "WHERE id='$something'", your WHERE clause went something like "WHERE item_name='$gotit'" right? Well, say you have these item_names in the DB: one two three Then you update one to four. Problem now becomes you're using WHERE to check for where item_name is four and you don't have one. Maybe if you used the OLD item_name, it would work. But ID is the way to go because you should never change an ID field. Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830063 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 So something like this to get the variable? <?php $sqlquery ="SELECT id FROM abcxyz WHERE item_name ='$item_name', description = '$description', in_return = '$in_return' LIMIT 1"; $result=mysql_query($sqlquery); $gotit = $result; ?> Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830064 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 disregard the last post,, I'll work on it... I get confused pretty easily.. Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830065 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 Try this - mysql_query("UPDATE abcxyz SET item_name = '$item_name', description = '$description', in_return = '$in_return' WHERE user_id = '" . $_SESSION['id'] . "' LIMIT 1") Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830067 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 there is nothing there to try,,,, i can see any code in your post... Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830068 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 there is nothing there to try,,,, i can see any code in your post... What do you mean? Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830069 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 your last post said try this... but there is nothing there just a textfield smashed together with no scroll bar(up and down) Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830071 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 Try this - mysql_query("UPDATE abcxyz SET item_name = '$item_name', description = '$description', in_return = '$in_return' WHERE user_id = '" . $_SESSION['id'] . "' LIMIT 1") I see it just fine. :-\ Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830073 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 um,, not me.,,,,, lol try putting a bunch of empty lines before your post,,, Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830074 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 <?php mysql_query("UPDATE abcxyz SET item_name = '$item_name', description = '$description', in_return = '$in_return' WHERE user_id = '" . $_SESSION['id'] . "' LIMIT 1"); Do you see that? Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830075 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 here there it is,,, lol,, thanks. Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830077 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 the only problem with that is that I can't use the user_id to find the info in the database,, only because a user may have more than item in the database,,, so wouldn't it be better to find the actual id of that specific item by saying something like select id where item_name =$item_name, description =$description etc... Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830079 Share on other sites More sharing options...
xtopolis Posted May 9, 2009 Share Posted May 9, 2009 Yes. You should update based on the items id, not name. When you're updating now, you're trying to change the name, while looking for the changed name... Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830083 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 Edit - Wouldn't that be problematic? Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830087 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 Wouldn't this be the way to go.... <?php $sql = "UPDATE abcxyz SET item_name = '$item_name', description = '$description', in_return = '$in_return' WHERE id = '$findid'"; ?> And then do a query for $findid Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830092 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 You don't see the problem with this set up? You have *multiple* input fields with the same name generated via the while loop. So if the user has 3 entries, the while loop runs 3 times and there will be 3 duplicate entries of each name field. So if you just select them using $_POST, you only get the last one. Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830093 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 I don't understand what your saying,,, please don't get mad(lol) Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830098 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 while ($row = mysql_fetch_array($sql)) { echo "<tr><td width='188' height='180'><div align='center'>"; echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />'; echo "</div></td><td width='188'><div align='center'>"; echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />'; echo "</div></td><td width='188'><div align='center'>"; echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" />'; echo "</div></td><td width='188'><div align='center'>"; echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" />'; echo "</div></td><td width='190'><div align='center'>"; echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" />'; echo "</div></td></tr><tr><td height='43' colspan='4'>"; echo '<strong>Item Name:</strong> <input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />'; echo "</td><td><div align='center'>"; echo '<input type="submit" name="submit" id="submit" value="Update Trade">'; echo "</div></td></tr><tr><td height='116' colspan='4'>"; echo '<strong>Description:</strong> <textarea name="description" cols="75" rows="5">' . $row['description'] . '</textarea>'; echo "</td><td><div align='center'>"; echo "</div></td></tr><tr><td height='124' colspan='4'>"; echo '<strong>Seeking:</strong> <textarea name="in_return" cols="75" rows="5">' . $row['in_return'] . ' </textarea>'; echo "</td><td><div align='center'>"; echo "</div></td></tr><tr><td colspan='4'>"; //echo "save delete buttons"; echo "</td><td><div align='center'>"; echo "</td></tr>"; } ALL of that is in a while loop. Say there are 3 entries. That means each one of those echo statement will be ran trice. Following so far? Well if they are, then you would see that all the fields have the same name attribute - in_return, description, submit, etc. If you then submit the form and use $_POST['description'], you will *only* get the description of the *last* textarea instead of the first and or second. So you missed out on those data. Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830101 Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 But only 1 item will be in front of the user at a time to be able to update,,, and if you are updating an item by selecting the items id,, it should only edit that specific item.......yes there is a while loop there and all the items will be displayed on the page,,, but I'm taking this one step at a time,,,after we can get this to work,,, I will setup a next and previous button so only 1 item is viewable to edit at a time. Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830104 Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 Well right now, I have no idea how to do the update SQL. You need to narrow it down to one entry per page first. In that one entry, add a hidden field that contains the items id. Link to comment https://forums.phpfreaks.com/topic/157313-solved-mysql-edit-update/page/2/#findComment-830105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.