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). Quote Link to comment 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'"; ?> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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; ?> Quote Link to comment 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.. Quote Link to comment 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") Quote Link to comment 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... Quote Link to comment 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? Quote Link to comment 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) Quote Link to comment 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. :-\ Quote Link to comment 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,,, Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
justAnoob Posted May 9, 2009 Author Share Posted May 9, 2009 here there it is,,, lol,, thanks. Quote Link to comment 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... Quote Link to comment 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... Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 9, 2009 Share Posted May 9, 2009 Edit - Wouldn't that be problematic? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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) Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. 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.