davidknag Posted July 21, 2010 Share Posted July 21, 2010 Could Anyone tell me what's wrong with this besides the fact that it is not connect to any database? it does not do anything when i click the button. <?php if ($_GET['register'] == 'true') { registerUser(); } function registerUser() { mysql_connect('server', 'username', 'password', 'database'); $username = $_POST['username']; $password = md5($_POST['password']); $sql = "INSERT INTO accounts (login, password, email, gm, flags) VALUES ($username, $password, $email, 0, 24);"; mysql_query($sql); } ?> <div class="form"> <form action="<?php $_SERVER['PHP_SELF']."?register=true" ?>" method="post"> Username: <input type="text" name="username"> <br></br> <br></br> Email: <input type="text" name="email"> <br></br> <br></br> Password: <input type="password" name="password"> <br></br> <br></br> <input type="submit" value="Register!"> </form> thanks if you can help Quote Link to comment https://forums.phpfreaks.com/topic/208364-phpsql-registration/ Share on other sites More sharing options...
trq Posted July 21, 2010 Share Posted July 21, 2010 Your query is failing because of incorrect syntax. String values need to be surrounded by quotes. Quote Link to comment https://forums.phpfreaks.com/topic/208364-phpsql-registration/#findComment-1088895 Share on other sites More sharing options...
Carlton Posted July 21, 2010 Share Posted July 21, 2010 $sql = "INSERT INTO accounts (login, password, email, gm, flags) VALUES (" .$username . "," . $password . "," . $email . ", 0, 24');"; Quote Link to comment https://forums.phpfreaks.com/topic/208364-phpsql-registration/#findComment-1088923 Share on other sites More sharing options...
trq Posted July 21, 2010 Share Posted July 21, 2010 $sql = "INSERT INTO accounts (login, password, email, gm, flags) VALUES (" .$username . "," . $password . "," . $email . ", 0, 24');"; That would fail for exactly the same reason. Quote Link to comment https://forums.phpfreaks.com/topic/208364-phpsql-registration/#findComment-1088926 Share on other sites More sharing options...
Carlton Posted July 21, 2010 Share Posted July 21, 2010 $sql = "INSERT INTO accounts (login, password, email, gm, flags) VALUES (" .$username . "," . $password . "," . $email . ", 0, 24');"; That would fail for exactly the same reason. Show me where and why. Quote Link to comment https://forums.phpfreaks.com/topic/208364-phpsql-registration/#findComment-1088928 Share on other sites More sharing options...
trq Posted July 21, 2010 Share Posted July 21, 2010 String values need to be surrounded by quotes So, it should be: $sql = "INSERT INTO accounts (login, password, email, gm, flags) VALUES ('$username', '$password', '$email', 0, 24);"; or, doing it your way: $sql = "INSERT INTO accounts (login, password, email, gm, flags) VALUES ('" .$username . "','" . $password . "','" . $email . "', 0, 24');"; Quote Link to comment https://forums.phpfreaks.com/topic/208364-phpsql-registration/#findComment-1088936 Share on other sites More sharing options...
PFMaBiSmAd Posted July 21, 2010 Share Posted July 21, 2010 Actually, since Carlton adding a rouge single quote after the last value in the query, the corrected 'his way' code would still generate an error. Quote Link to comment https://forums.phpfreaks.com/topic/208364-phpsql-registration/#findComment-1089182 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.