BrianM Posted May 2, 2008 Share Posted May 2, 2008 Here is my code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Examples </title> </head> <?php if(!isset($_POST['text'])) { echo "<form action='/examples/index.php' method='post'>"; echo "<input type='text' name='text'>"; echo "<input type='submit'>"; echo "</form>"; } else { $text = mysql_escape_string($_POST['text']); $mysql_connect = mysql_connect('localhost', 'brian', ''); mysql_query("UPDATE `08-12345-1` SET Req=($text) WHERE PermitProcess='COUNTY PRE-APP MEETING'", $mysql_connect); mysql_close($mysql_connect); echo "The record was updated in your MySQL database!"; } ?> <body> </body> </html> I execute UPDATE `08-12345-1` SET Req='some_text' WHERE PermitProcess='COUNTY PRE-APP MEETING' in the phpMyAdmin query window and it works just fine, updates the table in my browser, but when I go to use the same statement in this script, it doesn't want to cooperate... :| anyone see any problem with it? I'll be really excited if somebody can figure this out, as I've been at this same part of my website for about a week now, with no further progress due to this problem. Quote Link to comment https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/ Share on other sites More sharing options...
Fadion Posted May 2, 2008 Share Posted May 2, 2008 SET Req=($text) shoud be: SET Req='$text' And by the way, mysql_query() doesnt need the connection resource as the second parameter, it will make the query by default in the last opened connection. Quote Link to comment https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/#findComment-531890 Share on other sites More sharing options...
BrianM Posted May 2, 2008 Author Share Posted May 2, 2008 AHHHH!!!! Still doesn't work. I'm about to pull my hair out Arg. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Examples </title> </head> <?php if(!isset($_POST['text'])) { echo "<form action='/examples/index.php' method='post'>"; echo "<input type='text' name='text'>"; echo "<input type='submit'>"; echo "</form>"; } else { $text = mysql_escape_string($_POST['text']); $mysql_connect = mysql_connect('localhost', 'brian', ''); mysql_query("UPDATE `08-12345-1` SET Req='$text' WHERE PermitProcess='COUNTY PRE-APP MEETING'"); mysql_close($mysql_connect); echo "The record was updated in your MySQL database!"; } ?> <body> </body> </html> This is what I have now, after changing what you stated. I just don't understand why it works in the query window in phpMyAdmin but not when put into this script... >.> Quote Link to comment https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/#findComment-531895 Share on other sites More sharing options...
rhodesa Posted May 2, 2008 Share Posted May 2, 2008 replace these lines: $mysql_connect = mysql_connect('localhost', 'brian', '') or die("Failed to connect"); $text = mysql_escape_string($_POST['text']); mysql_query("UPDATE `08-12345-1` SET Req='$text' WHERE PermitProcess='COUNTY PRE-APP MEETING'") or die("Update error: ".mysql_error()); mysql_close($mysql_connect); Quote Link to comment https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/#findComment-531897 Share on other sites More sharing options...
PFMaBiSmAd Posted May 2, 2008 Share Posted May 2, 2008 $text won't be set to anything because you are using mysql_escape_string() before you have a connection to a mysql server. When learning php, developing php code, or debugging php code, do yourself a favor and turn off full php error_reporting and the display_errors setting to get php to help you. Quote Link to comment https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/#findComment-531898 Share on other sites More sharing options...
BrianM Posted May 2, 2008 Author Share Posted May 2, 2008 Now it's telling me no database selected >.> I clearly see I have one selected `08-12345-1` .. what's wrong with it now? :[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Examples </title> </head> <?php if(!isset($_POST['text'])) { echo "<form action='/examples/index.php' method='post'>"; echo "<input type='text' name='text'>"; echo "<input type='submit'>"; echo "</form>"; } else { $mysql_connect = mysql_connect('localhost', 'brian', '') or die("Failed to connect"); $text = mysql_escape_string($_POST['text']); mysql_query("UPDATE `08-12345-1` SET Req='$text' WHERE PermitProcess='COUNTY PRE-APP MEETING'") or die("Update error: ".mysql_error()); mysql_close($mysql_connect); echo "The record was updated in your MySQL database!"; } ?> <body> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/#findComment-531909 Share on other sites More sharing options...
Fadion Posted May 2, 2008 Share Posted May 2, 2008 lol, didnt see in first place that the little script is full of errors. What about mysql_select_db()? Quote Link to comment https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/#findComment-531912 Share on other sites More sharing options...
rhodesa Posted May 2, 2008 Share Posted May 2, 2008 yeah...what is the name of your database? put this right after the connect: mysql_select_db('db_name'); replacing 'db_name' with the name of your database obviously Quote Link to comment https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/#findComment-531918 Share on other sites More sharing options...
BrianM Posted May 2, 2008 Author Share Posted May 2, 2008 HOLY JESUS!!! Praise the Guru gods, >.> heh I never even saw that lol I'm sure that'll fix my problem lol, let me try. Quote Link to comment https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/#findComment-531921 Share on other sites More sharing options...
craygo Posted May 2, 2008 Share Posted May 2, 2008 You selected the TABLE in your UPDATE statement but you have not selected the database where that table is. As rhodesa said add the line in your connections string. Quote Link to comment https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/#findComment-531923 Share on other sites More sharing options...
BrianM Posted May 2, 2008 Author Share Posted May 2, 2008 Alas! She's working. A huge thank you to all of you who contributed towards my success!!! Quote Link to comment https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/#findComment-531926 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.