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.

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')")

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

?>

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.