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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 . 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.