soycharliente Posted January 8, 2007 Share Posted January 8, 2007 Can anyone see why this code isn't working? No errors generated. The database table just doesn't update. Hostname, username, password, and dbname are all correct as well.I have a table called 'users' with fields named 'name', 'classes', and 'help'.Looking at this code makes my eyes hurt. If anyone can provide any help, I'll love you forever. Thanks in advance.[code]<?phpif ($_GET['action'] == "update") { $update = TRUE;}$current = $_POST['current'];$help = $_POST['helpwith'];if ($update) { //Connect To Database $hostname = "...."; $username = "..."; $password = "..."; $dbname = "..."; mysql_connect($hostname, $username, $password) OR DIE ("Unable to connect! Please try again."); mysql_select_db($dbname); $temp = $HTTP_SESSION_VARS["LoggedInUser"]; $query = "UPDATE users SET classes='" . quote_smart($current) . "', help='" . quote_smart($help) . "' WHERE name='$temp'"; $result = mysql_query($query);}?><html><body><form action="classes.php?action=update" method="post"><?phpecho "<textarea name=\"current\" rows=\"4\" cols=\"20\" maxlength=\"300\">some text</textarea>\n";echo "<textarea name=\"helpwith\" rows=\"4\" cols=\"40\" maxlength=\"300\">some text</textarea>\n";echo "<input type=\"submit\" value=\"Update\" /> <a href=\"classes.php\">cancel</a>\n";?></form></body></html><?phpfunction quote_smart($value) { // Stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote if not a number or a numeric string if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value) . "'"; } return $value;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33317-solved-database-update-not-working/ Share on other sites More sharing options...
matto Posted January 8, 2007 Share Posted January 8, 2007 try changing this line[code]if ($_GET['action'] == "update") [/code]to this:[code]if (isset($_POST['update')) { [/code]and remove the ?action= part from your form tag then change the following:[code]echo "<input type=\"submit\" value=\"Update\" /> <a href=\"classes.php\">cancel</a>\n"[/code]to[code]echo "<input type=\"submit\" name=\"update\" value=\"Update\" /> <a href=\"classes.php\">cancel</a>\n"[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33317-solved-database-update-not-working/#findComment-155670 Share on other sites More sharing options...
soycharliente Posted January 8, 2007 Author Share Posted January 8, 2007 Nope. Still has the same effect. I think I'm going to just scratch the whole page and start over from the beginning adding things little by little. Funny thing is that the whole page was working for two weeks before today. Quote Link to comment https://forums.phpfreaks.com/topic/33317-solved-database-update-not-working/#findComment-155673 Share on other sites More sharing options...
matto Posted January 8, 2007 Share Posted January 8, 2007 btw: you should be using $_SESSION['LoggedInUser'] not $HTTP_SESSION_VARS['LoggedInUser']Have you by chance tried it without the using the quote_smart() function ?If you post what you have now I will help you get it working if you like..... Quote Link to comment https://forums.phpfreaks.com/topic/33317-solved-database-update-not-working/#findComment-155674 Share on other sites More sharing options...
soycharliente Posted January 8, 2007 Author Share Posted January 8, 2007 I attached the entire file below rather than pasting it into the reply window. The code I had originally posted was just a section of the page. Maybe it's a problem in another place.[attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/33317-solved-database-update-not-working/#findComment-155791 Share on other sites More sharing options...
soycharliente Posted January 8, 2007 Author Share Posted January 8, 2007 I fixed it. Thanks matto for the help. I stopped using quote_smart and used solely the mysql_real_escape_string function. The only problem with that is that it inserts a \ into whatever the data they tried to post is. If they then clicked edit and then update (or just left the \ in, it would escape the \ with another \ to that it would display the first one thereby displaying a second one. AHHH!!!). But, I don't really care because it's not a site for a company.I'm will mark this as solved at the end of today, but if anyone knows how to get rid of that problem I just mentioned please let me know.Would using stripslahes negate the use of mysql_real_escape_string in a bad way?Say I did something like...[code]<?php$test = "Hello. I don't know your name.";$safe = mysql_real_escape_string($test); //outputs "Hello. I don\'t know your name." to the screen$strip = stripslashes($safe); //outputs "Hello. I don't know your name." to the screen?>[/code]It does in fact remove the extra \'s, but does that negate making it a "safe string"?@matto: What's the diff between $_HTTP_SESSION_VARS and $_SESSION? Quote Link to comment https://forums.phpfreaks.com/topic/33317-solved-database-update-not-working/#findComment-155975 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 strip_slashes() Quote Link to comment https://forums.phpfreaks.com/topic/33317-solved-database-update-not-working/#findComment-155976 Share on other sites More sharing options...
matto Posted January 8, 2007 Share Posted January 8, 2007 This is a very old way of doing thingssession_register("LoggedInUser");There is no need to register session vars anymore, you can simply do the following:$_SESSION["LoggedInUser"] = whatever;You may also want to consider using something like the following to fix your slashes problem:[code]if (!get_magic_quotes_gpc()) { $lastname = addslashes($_POST['lastname']);} else { $lastname = $_POST['lastname'];}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33317-solved-database-update-not-working/#findComment-155985 Share on other sites More sharing options...
soycharliente Posted January 8, 2007 Author Share Posted January 8, 2007 [quote author=jesirose link=topic=121485.msg499936#msg499936 date=1168283281]strip_slashes()[/quote]Is this page incorrect?http://us2.php.net/manual/en/function.stripslashes.php Quote Link to comment https://forums.phpfreaks.com/topic/33317-solved-database-update-not-working/#findComment-155987 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 I added a _, whatever. It's stripslashes then. I swear you didn't have that in your code when I suggested it... Quote Link to comment https://forums.phpfreaks.com/topic/33317-solved-database-update-not-working/#findComment-156006 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.