Jump to content

[SOLVED] Help with my account creation page


SirEddie

Recommended Posts

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.

Link to comment
Share on other sites

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')")
Link to comment
Share on other sites

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());

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'].

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.