slpctrl Posted August 29, 2012 Share Posted August 29, 2012 I've recently been getting back into PHP, and I've racked my brain over this incredibly simple piece of code, and can't figure out why I can't insert. <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } $user = "********"; $pass = md5("********"); $email = "******@live.com"; mysql_select_db("users", $con) or die("unable to select DB"); mysql_query("INSERT INTO users ('user', 'pass', 'email') VALUES ($user,$pass,$email)") or die("Can't insert info into DB " mysql_error()); mysql_close($con); ?> I know my error is within the insert command...I just don't understand why this isn't working. I've even copied the code straight from W3schools, and it still doesn't work. My MYSQL version is 5.5.24 mod edit: removed user/pass/email details Link to comment https://forums.phpfreaks.com/topic/267725-cant-insert-into-db/ Share on other sites More sharing options...
xyph Posted August 29, 2012 Share Posted August 29, 2012 Literal strings must be quoted in a query. Column names should not be quoted. Link to comment https://forums.phpfreaks.com/topic/267725-cant-insert-into-db/#findComment-1373456 Share on other sites More sharing options...
Christian F. Posted August 29, 2012 Share Posted August 29, 2012 You should also read the article in xyph's signature. Link to comment https://forums.phpfreaks.com/topic/267725-cant-insert-into-db/#findComment-1373459 Share on other sites More sharing options...
slpctrl Posted August 29, 2012 Author Share Posted August 29, 2012 <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } $user = "********"; $pass = md5("********"); $email = "******@live.com"; mysql_select_db("users", $con) or die("unable to select DB"); mysql_query("INSERT INTO users (user, pass, email) VALUES ('$user', '$pass', '$email')") or die("Can't insert info into DB " mysql_error()); mysql_close($con); ?> mod edit: removed user/pass/email details Link to comment https://forums.phpfreaks.com/topic/267725-cant-insert-into-db/#findComment-1373461 Share on other sites More sharing options...
slpctrl Posted August 29, 2012 Author Share Posted August 29, 2012 Thanks for removing those details...after a second I realized, oh sh...oh wow, why did I not filter those out x_x Link to comment https://forums.phpfreaks.com/topic/267725-cant-insert-into-db/#findComment-1373462 Share on other sites More sharing options...
PFMaBiSmAd Posted August 29, 2012 Share Posted August 29, 2012 I recommend that you go and change your password ASAP. A number of the views of this thread are bot scripts and search engine spiders that read and cache the content and it's only a matter of time before someone logs into your mail account. Link to comment https://forums.phpfreaks.com/topic/267725-cant-insert-into-db/#findComment-1373464 Share on other sites More sharing options...
slpctrl Posted August 29, 2012 Author Share Posted August 29, 2012 ^That actually wasn't my password thank god, but I do use it somewhere . Anyways, I got it thanks all . Link to comment https://forums.phpfreaks.com/topic/267725-cant-insert-into-db/#findComment-1373466 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.