scmeeker Posted June 30, 2010 Share Posted June 30, 2010 When the update button is clicked, it access this code to update the table BUT its not updating the table. No information is changed and just goes back to what was there on the previous page. The username is the session variable. Any suggestions?? $item_bio = mysql_real_escape_string($_POST[bio]);; $item_other_artists = mysql_real_escape_string($_POST[other_artists]); $sql="UPDATE store SET bio = '$item_bio', other_artists = '$item_other_artists' WHERE username = '".$_GET["username"]."'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } header("location:update.php?username=".$_SESSION['username'].""); Quote Link to comment https://forums.phpfreaks.com/topic/206233-having-trouble-getting-form-to-update-database/ Share on other sites More sharing options...
Pikachu2000 Posted June 30, 2010 Share Posted June 30, 2010 If the username is store in the $_SESSION var, shouldn't this: WHERE username = '".$_GET["username"]."'" Be this:? WHERE username = '".$_SESSION["username"]."'" Quote Link to comment https://forums.phpfreaks.com/topic/206233-having-trouble-getting-form-to-update-database/#findComment-1078970 Share on other sites More sharing options...
scmeeker Posted June 30, 2010 Author Share Posted June 30, 2010 Okay, I changed that. Then when I clicked the "update" button, it cleared out the data in the database that was in the "bio" and "other_artists" and came up blank. So now it is communicating but not updating the information. Hmmmm...any other suggestions? I'm going to post the form too. Can I send the session variable through the "form action"? How would I do that? <form action=artist_profile_update.php> <br /> <span class="titles">bio</span><br /> <span class="smallfont">ignore this</span><br /> <p> <textarea name="bio" rows=10 cols=90><?php echo $display_block = "$item_bio" ?></textarea></p> <br /> <span class="titles"></span><br /> <span class="smallfont"> ignore</span><br /> <p> <textarea name="other_artists" rows=10 cols=90><?php echo $display_block = "$item_other_artists" ?></textarea></p> <br /> <br /> <input type="submit" name="Submit" value="Update"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/206233-having-trouble-getting-form-to-update-database/#findComment-1078977 Share on other sites More sharing options...
gizmola Posted June 30, 2010 Share Posted June 30, 2010 I'm not clear on how this form fits into things, but you can pass a form item using a hidden field if you're just looking for a way to get it out through the POST variables. There's no advantage to that over reading it directly from the $_SESSION, and often people are doing that help with security. These statements don't make any sense: Either echo $display_block or $item_bio. Don't know where those variables are suppossed to get their values from, as their not in evidence in the script, and thus would be empty and not set. Quote Link to comment https://forums.phpfreaks.com/topic/206233-having-trouble-getting-form-to-update-database/#findComment-1078982 Share on other sites More sharing options...
scmeeker Posted June 30, 2010 Author Share Posted June 30, 2010 That is retrieving information that is already in the database. Quote Link to comment https://forums.phpfreaks.com/topic/206233-having-trouble-getting-form-to-update-database/#findComment-1078984 Share on other sites More sharing options...
Pikachu2000 Posted June 30, 2010 Share Posted June 30, 2010 Okay, I changed that. Then when I clicked the "update" button, it cleared out the data in the database that was in the "bio" and "other_artists" and came up blank. So now it is communicating but not updating the information. Hmmmm...any other suggestions? I'm going to post the form too. Can I send the session variable through the "form action"? How would I do that? <form action=artist_profile_update.php> <br /> <span class="titles">bio</span><br /> <span class="smallfont">ignore this</span><br /> <p> <textarea name="bio" rows=10 cols=90><?php echo $display_block = "$item_bio" ?></textarea></p> <br /> <span class="titles"></span><br /> <span class="smallfont"> ignore</span><br /> <p> <textarea name="other_artists" rows=10 cols=90><?php echo $display_block = "$item_other_artists" ?></textarea></p> <br /> <br /> <input type="submit" name="Submit" value="Update"> </form> If the form cleared the values from the database fields, that would indicate the $item_bio and $item_other_artists variables contain no values. The UPDATE query is then setting those field values to match. Quote Link to comment https://forums.phpfreaks.com/topic/206233-having-trouble-getting-form-to-update-database/#findComment-1079220 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.