SirEddie Posted July 24, 2007 Share Posted July 24, 2007 Hi all, I am having a problem with the account creation page I am making. Here is the file you fill in details: account.php <title>Account Creation</title> <link rel="stylesheet" type="text/css" href="style.css" /> <div id="formaccount" align="center"> <form action="accountcreate.php" class="accform"> Account Name: <br /> <input type="text" name="Username" class="usernameform" maxlength="16" /><br /><br /> Password: <br /> <input type="password" name="Password" class="passwordform" maxlength="16" /><br /><br /> E-mail: <br /> <input type="text" name="Email" class="emailform" /><br /><br /> Game Type: <br /> <select name="GameType" class="gametypeform"> <option value="8">Burning Crusade</option> <option value="0">Non-Burning Crusade</option> </select><br /><br /> <input type="submit" value="Submit" name="submit" /> </form> </div> Thats all fine. Now this is the file with the code to make the account: accountcreate.php: <?php include ("config.php"); mysql_connect ($db_host, $db_user, $db_pass) or die('Error: ' . mysql_error()); mysql_select_db ('antrix') or die('Error: ' . mysql_error()); ?> <?php $username = $_POST['Username']; $password = $_POST['Password']; $email = $_POST['Email']; $type = $_POST['GameType']; mysql_query ("INSERT INTO `accounts` (`login`, `password`, `email`, `flags`) VALUES ($username, $password, $email, $type)") or die("Error: " . mysql_error()); ?> The error I get is: Error: 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 ' , , )' at line 1. Now, the MySQL table is like this: Acct, Login, Password, GM, Lastlogin, Lastip, email, flags Is there something wrong with the query code? Or do you need every column to be queried. I ahve no idea. Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 24, 2007 Share Posted July 24, 2007 You need to have the values in single quotes ' this: mysql_query ("INSERT INTO `accounts` (`login`, `password`, `email`, `flags`) VALUES ($username, $password, $email, $type)") must be changed to this mysql_query ("INSERT INTO `accounts` (`login`, `password`, `email`, `flags`) VALUES ('$username', '$password', '$email', '$type')") Quote Link to comment Share on other sites More sharing options...
simcoweb Posted July 24, 2007 Share Posted July 24, 2007 Try this: <?php include ("config.php"); mysql_connect ($db_host, $db_user, $db_pass) or die('Error: ' . mysql_error()); mysql_select_db ('antrix') or die('Error: ' . mysql_error()); ?> <?php $username = $_POST['Username']; $password = $_POST['Password']; $email = $_POST['Email']; $type = $_POST['GameType']; $sql = "INSERT INTO accounts (login, password, email, flags) VALUES ('$username', '$password', '$email', '$type')" or die("Error: " . mysql_error()); $results = mysql_query($sql) or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
SirEddie Posted July 24, 2007 Author Share Posted July 24, 2007 Thanks.. Ill try now and let yous know. Quote Link to comment Share on other sites More sharing options...
SirEddie Posted July 24, 2007 Author Share Posted July 24, 2007 Both of them give me this now: Incorrect integer value: '' for column 'flags' at row 1 Flags should be 8 or 0, maybe I am parsing from the HTML option secition (game type) wrong. Also, it doesn't add login, password or email into the thing. Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 24, 2007 Share Posted July 24, 2007 I get it know, just must have set the flag column as an integer so you cant pass a string value. change: $type = $_POST['GameType']; to: $type = intval($_POST['GameType']); In this way you pass to $type the integer value of $_POST['GameType']. Quote Link to comment Share on other sites More sharing options...
SirEddie Posted July 24, 2007 Author Share Posted July 24, 2007 Hmm.. that stopped the error. Now all it does is stay 0, and none of the other places (login, password and email) dont get filled in. Is there something wrong with my parsing from the account.php to accountcreate.php? Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 25, 2007 Share Posted July 25, 2007 You are getting the variables right with $_POST and you have constructed a right query. From what i can see you have not set a method for the form, so maybe that is causing problems. What i mean: Replace <form action="accountcreate.php" class="accform"> With <form action="accountcreate.php" method="post" class="accform"> Im assuming this causes the data not to be passed to the variables because you have no method for the form (post or get). Quote Link to comment Share on other sites More sharing options...
SirEddie Posted July 26, 2007 Author Share Posted July 26, 2007 thanks, I'll try that. Seems right, I think I left that out Lol Edit:: Thanks a lot. I can't believe I left that out lol. Thanks. 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.