maralynnj Posted August 14, 2009 Share Posted August 14, 2009 Here's what I've got: SQL argument is attempting to insert data into a database called 'notifications'. PHP CODE: include 'AAPWconfig.php'; // host, user, pass, database include 'AAPWopendb.php'; // conn mysql_connect $sqlNTF="INSERT INTO notifications SET 'kind_ntf'='$IDntfK', 'status_ntf'='new', 'assigned_ntf'='$assigned', 'addedby_ntf'='$IDusr', 'notes_ntf'='$notes', 'date_ntf'=now(), 'same_ntf'='same'"; $resultNTF=mysql_query($sqlNTF); if($resultNTF){echo "INSERT argument NTF is successful ";} else {echo "INSERT argument NTF is not successful ";} echo $sqlNTF; $IDntf = mysql_insert_id(); mysql_close(); It informs me that "INSERT argument NTF is not successful. And the $sqlNTF echos out to: INSERT INTO notifications SET 'kind_ntf'='21', 'status_ntf'='new', 'assigned_ntf'='20', 'addedby_ntf'='48', 'notes_ntf'='Submitted By: Joe Troubleshoot Email: joe@maralynnj.com View User Additional Notes: General Information Request to include the following: ~Things to know about water quality ~Central water home / business integration ~Other (described below): Additional Notes: Test Comments ', 'date_ntf'=now(), 'same_ntf'='same' The thing is, this exact query has worked for me on other pages. The mysql works just fine if I use PhpMyAdmin to query it, AND there are other querys on the same page with the same supporting php code (including config and opendb). So. I am at a loss...actually...i want to go plant trees in Alaska and give up on the computer altogether. Any brilliant solutions to my little php/mysql problem?? I'm almost afraid to hope that it's something obvious that I'm just missing and missing and missing and missing. Anyway...thanks! Quote Link to comment https://forums.phpfreaks.com/topic/170191-works-in-phpmyadmin-but-not-from-web-page/ Share on other sites More sharing options...
smerny Posted August 14, 2009 Share Posted August 14, 2009 you should always use mysql_error() if the query does not work to see whats wrong... try this though INSERT INTO notifications (kind_ntf, status_ntf, assigned_ntf ...etc) VALUES ('".$IDntfK."', '".new."', '".$assigned."' ...etc) btw, you were using the format that one would normally use to UPDATE a mysql row (minus the WHERE) Quote Link to comment https://forums.phpfreaks.com/topic/170191-works-in-phpmyadmin-but-not-from-web-page/#findComment-897759 Share on other sites More sharing options...
maralynnj Posted August 14, 2009 Author Share Posted August 14, 2009 mysql_error echos out to: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''kind_ntf'='21', 'status_ntf'='new', 'assigned_ntf'='20', 'addedby_ntf'='49', 'n' at line 1 I will try your suggestion on the syntax change and let you know how it goes. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/170191-works-in-phpmyadmin-but-not-from-web-page/#findComment-897762 Share on other sites More sharing options...
maralynnj Posted August 14, 2009 Author Share Posted August 14, 2009 Here's the revised query: include 'AAPWconfig.php'; // host, user, pass, database include 'AAPWopendb.php'; // conn mysql_connect $sqlNTF="INSERT INTO notifications SET (id_ntf, kind_ntf, status_ntf, assigned_ntf, addedby_ntf, notes_ntf, date_ntf, same_ntf) VALUES ( NULL, '".$IDntfK."', 'new', '".$assigned."', '".$IDusr."', '".$notes."', now(), 'same' )"; if($resultNTF){echo "INSERT argument NTF is successful ";} else {echo "INSERT argument NTF is not successful ";} echo $sqlNTF."<br /><br />"; echo mysql_error(); $IDntf = mysql_insert_id(); mysql_close(); Still no luck. If I take the output from the "echo $sqlNTF" which echos my sql statement back to me: INSERT INTO notifications SET (id_ntf, kind_ntf, status_ntf, assigned_ntf, addedby_ntf, notes_ntf, date_ntf, same_ntf) VALUES ( NULL, '21', 'new', '20', '50', 'Submitted By: Bob Test Email: bob@maralynnj.com View User Additional Notes: General Information Request to include the following: Additional Notes: Test comments ', now(), 'same' ) It returns the following error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(id_ntf, kind_ntf, status_ntf, assigned_ntf, addedby_ntf, notes_ntf, date_ntf, s' at line 1 I'm obviously off on my syntax somewhere...but i can't tell where...could it be in my use of the now()?? but i use that all the time...seems strange...any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/170191-works-in-phpmyadmin-but-not-from-web-page/#findComment-897776 Share on other sites More sharing options...
smerny Posted August 14, 2009 Share Posted August 14, 2009 don't use SET Quote Link to comment https://forums.phpfreaks.com/topic/170191-works-in-phpmyadmin-but-not-from-web-page/#findComment-897779 Share on other sites More sharing options...
maralynnj Posted August 14, 2009 Author Share Posted August 14, 2009 I honestly am not sure why this worked, but it did. You probably know. include 'AAPWconfig.php'; // host, user, pass, database include 'AAPWopendb.php'; // conn mysql_connect $sqlNTF="INSERT INTO notifications SET kind_ntf='$IDntfK', status_ntf='new', assigned_ntf='$assigned', addedby_ntf='$IDusr', notes_ntf='$notes', date_ntf=now(), same_ntf='same'"; $resultNTF=mysql_query($sqlNTF); $IDntf = mysql_insert_id(); mysql_close(); Thank you for your help!! Quote Link to comment https://forums.phpfreaks.com/topic/170191-works-in-phpmyadmin-but-not-from-web-page/#findComment-897784 Share on other sites More sharing options...
smerny Posted August 14, 2009 Share Posted August 14, 2009 because you removed the quotes from the field names Quote Link to comment https://forums.phpfreaks.com/topic/170191-works-in-phpmyadmin-but-not-from-web-page/#findComment-897786 Share on other sites More sharing options...
aschk Posted August 14, 2009 Share Posted August 14, 2009 Indeed, MySQL interprets anything enclosed by single quote (') as a literal. Thus you weren't actually supplying field names, merely supply strings which happened to contain the name of the field, and what was actually happening would have been that it was doing a comparison, e.g. 'kind_ntf' = '$IDntfK' => would be false So you were in fact probably doing: INSERT INTO notifications SET false, false, false, false, false, false, false Hope that clarifies it for you... Quote Link to comment https://forums.phpfreaks.com/topic/170191-works-in-phpmyadmin-but-not-from-web-page/#findComment-898099 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.