axx5 Posted July 3, 2009 Share Posted July 3, 2009 $query = "INSERT INTO Test VALUES (5," . $INFO1 . "," $INFO2 . "," . $INFO3 . "," . $INFO4 . "," . $INFO5) Any idea why i get this error when adding this query? (the error comes after the connection has been made so the file does connect to the database, there must be though a problem with how its formatted? Quote Link to comment Share on other sites More sharing options...
dezkit Posted July 3, 2009 Share Posted July 3, 2009 $query = "INSERT INTO Test VALUES (5," . $INFO1 . "," $INFO2 . "," . $INFO3 . "," . $INFO4 . "," . $INFO5 . ")"; Quote Link to comment Share on other sites More sharing options...
axx5 Posted July 3, 2009 Author Share Posted July 3, 2009 Stilll get a error. Heres the full code. $mysql = mysql_connect("127.0.0.1", "root", "") $query = mysql_query("INSERT INTO Test VALUES (5," . $INFO1 . "," $INFO2 . "," . $INFO3 . "," . $INFO4 . "," . $INFO5 . ")"); The error comes up on the $query line. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted July 3, 2009 Share Posted July 3, 2009 If any of the $INFO values you're inserting into the table are strings, then they need to be quoted Quote Link to comment Share on other sites More sharing options...
gevans Posted July 3, 2009 Share Posted July 3, 2009 What's the error? and do you select a database? http://www.php.net/manual/en/function.mysql-select-db.php Quote Link to comment Share on other sites More sharing options...
axx5 Posted July 3, 2009 Author Share Posted July 3, 2009 How come it works with this though? mysql_query("INSERT INTO `Test`.`user` (`id`, `name`, `password`, `ip`, `date`, `registered`) VALUES (NULL, 'test', 'test', 'test', 'test', 'test 'test', 'test')", $c); But if i adjust this even a little bit it doesn't work. why does this above example work yet this doesn't? mysql_query("INSERT INTO" . $webdbname . "`user` (`id`, `name`, `password`, `ip`, `date`, `registered`) VALUES (NULL," . $sname . "," . $spassword . "," . $sip . "," . $date)", $c);[/code] Quote Link to comment Share on other sites More sharing options...
gevans Posted July 3, 2009 Share Posted July 3, 2009 What's the error? Quote Link to comment Share on other sites More sharing options...
gevans Posted July 3, 2009 Share Posted July 3, 2009 You're not putting quotes around the value strings; <?php $mysql = mysql_connect("127.0.0.1", "root", "") $query = mysql_query("INSERT INTO Test VALUES (5, '$INFO1', '$INFO2', '$INFO3', '$INFO4', '$INFO5')"); Quote Link to comment Share on other sites More sharing options...
axx5 Posted July 3, 2009 Author Share Posted July 3, 2009 Man this is driving me crazy. Can someone just post a full example with all the code, connect, select, add? I can't get to work when $ strings are added Quote Link to comment Share on other sites More sharing options...
gevans Posted July 3, 2009 Share Posted July 3, 2009 Again, what error are you getting, and try my example Quote Link to comment Share on other sites More sharing options...
axx5 Posted July 3, 2009 Author Share Posted July 3, 2009 Again, what error are you getting, and try my example I am not getting a error any more, it just doesn't send the data to the database when $strings are inserted. Which is why i asked if you could supply a full demonstration doing it. Quote Link to comment Share on other sites More sharing options...
Zane Posted July 3, 2009 Share Posted July 3, 2009 you are missing a semicolon here $mysql = mysql_connect("127.0.0.1", "root", "") Quote Link to comment Share on other sites More sharing options...
axx5 Posted July 3, 2009 Author Share Posted July 3, 2009 You're not putting quotes around the value strings; <?php $mysql = mysql_connect("127.0.0.1", "root", "") $query = mysql_query("INSERT INTO Test VALUES (5, '$INFO1', '$INFO2', '$INFO3', '$INFO4', '$INFO5')"); That fixes it but then if i add quotes on 'date("Y:m:d")' it doesn't work, ideas? Quote Link to comment Share on other sites More sharing options...
mattal999 Posted July 3, 2009 Share Posted July 3, 2009 It does that because you don't excape the double quotes. Replace 'date("Y:m:d")' With '".date("Y:m:d")."' 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.