Jump to content

Quick Question On PHP Register and Login Scripts - MYSQL Error


VeronMan

Recommended Posts

  • Replies 57
  • Created
  • Last Reply

Do you have to create a table called users, Of course if you are trying to insert or pull table from the users table. Read up on SQL bud, you have to have a table created with a structure before you can put anything into it/pull from it.

Link to comment
Share on other sites

not everyone learns mysql because they are learning php, it is just that most people now are using mysql instead of flat-file.

 

VeronMan, i suggest you follow The Bat's suggestion on reading up on the mysql documentation, then if you have more trouble come back.

 

search google for things like:

create mysql table in php

 

or something along those lines.

Link to comment
Share on other sites

Ok, after reading up on MYSQL and phpMyAdmin, I decided to use phpMyAdmin, simply because it's "easy" to use, and I have no real interest in learning MYSQL right now.

 

So, I got into phpMyAdmin, created my database called 107887, and now I need to add tables to the database. How exactly do I do that? From my assumptions, you need to add a table for every value you want to store through the registration, so I would need a table called firstname, lastname, password, reppassword, email etc, etc.

 

Is this correct? This is the phpMyAdmin Interface which I'm stuck on, so my question is?

 

Is the above correct, and if so, how do I create tables, and know what values to enter

into the fields in phpMyAdmin?

 

Link to a screenshot included below of the phpMyAdmin interface of when I clicked "go" I named the table firstname as you can see, and selected the number of fields to be 1.

 

Screenshot: http://img172.imageshack.us/img172/9559/phpmyadminshotbe8.jpg

Link to comment
Share on other sites

Okay, i've been using phpMyAdmin tirelessly now, and I think i'm almost there. Now, after trying to register, I get the error: Unknown columm 'code' in 'field list'

 

The error appears after you enter your details and click Submit on the page at http://veron.sitesled.com/register.html

 

What's the problem now? Here's the register.php script that i'm using, it might help you solve my problem:

 

<?
include 'config.php';

if(isset($_POST['submit']))
{
$first		= addslashes(trim($_POST['firstname']));
$surname	= addslashes(trim($_POST['surname']));
$username	= addslashes(trim($_POST['username']));
$email		= addslashes(trim($_POST['email']));
$pass		= addslashes(trim($_POST['password']));
$conf		= addslashes(trim($_POST['confirm']));
$activ		= addslashes(trim($_POST['activation']));
$date = date("d/m/y");

$errormsg='Errors:\n';
# pop up window if password is not equal to confirmed password
if ( $_POST['password'] == $_POST['confirm'] )
{$error1=0;}else{
	$error1=1;
	$errormsg=$errormsg.'Passwords were not the same\n';
	#echo '<script>alert("Your passwords were not the same, please enter the same password in each field.");</script>';
	#echo '<script>history.back(1);</script>';
	#exit;
}

# encode the password
$password = md5($pass);	

# pop up window if any field was left empty
if ((((( empty($first) ) || ( empty($surname) ) || ( empty($username) ) || ( empty($email) ) || ( empty($password) )))))
{
	$error2=1;
	$errormsg=$errormsg.'One or more fields were left empty\n';
	#echo '<script>alert("One or more fields was left empty, please try again.");</script>';
	#echo '<script>history.back(1);</script>';
	#exit;
}else{$error2=0;}

# pop up window if an invalid email address was entered
if((!strstr($email , "@")) || (!strstr($email , ".")))
{
	$error3=1;
	$errormsg=$errormsg.'Invalid email address\n';
	#echo '<script>alert("You entered an invalid email address. Please try again.");</script>';
	#echo '<script>history.back(1);</script>';
	#exit;
}else{$error3=0;}

# check if username is already in use in the database and pop up if there is
$q = mysql_query("SELECT * FROM Users WHERE Username = '$username'") or die(mysql_error());
if(mysql_num_rows($q) > 0)
{
	$error4=1;
	$errormsg=$errormsg.'Username already in use\n';
	#echo '<script>alert("The username you entered is already in use, please try again.");</script>';
	#echo '<script>history.back(1);</script>';
	#exit;		
}else{$error4=0;}

# check if activation code is correct
$q1 = mysql_query("SELECT code FROM codes WHERE id = 1") or die(mysql_error());
$q2 = mysql_query("SELECT code FROM codes WHERE id = 2") or die(mysql_error());

$row1 = mysql_fetch_array($q1);
$row2 = mysql_fetch_array($q2);

if ( $_POST['activation'] == $row1['code'] ){
	$code = 0;
	$error5=0;
}elseif ( $_POST['activation'] == $row2['code'] ){
	$code = 9;
	$error5=0;
}else
{
	$error5=1;
	$errormsg=$errormsg.'Activation code incorrect\n';
	#echo '<script>alert("Your activation code was incorrect, please enter the correct code to register.");</script>';
	#echo '<script>history.back(1);</script>';
	#exit;
}

if ($error1 || $error2 || $error3 || $error4 || $error5){
	echo '<script>alert("'.$errormsg.'");</script>';
	echo '<script>history.back(1);</script>';
	exit;
}

$name = $first . ' ' . $surname;

$query = mysql_query("INSERT INTO Users (Username, Password, Name, Email, Date, Level) VALUES ('$username','$password','$name','$email','$date','$code')") or die(mysql_error());	

if($query)
{
	echo '	<html>
			<head>
			<title>Success</title>
			<link href="style.css" rel="stylesheet" type="text/css">
			</head>			
			<body>
			<div id="success">
			<p>Success! You are now a registered member</p>
			<p>Click <a href="login.php">here</a> to login</p>
			</div>
			</body>
			</html>
			';					
} else {
	echo '
			<html>
			<head>
			<title>Error</title>
			<link href="style.css" rel="stylesheet" type="text/css">
			</head>	
			<body>				
			<div id="error">
			<p>We are sorry, there appears to be a problem with our script at the moment.</p>
			<p>Your data was not lost. Username: '.$username.' | Password: '.$pass.' | Email: '.$email.' | Full name: '.$name.'</p>
			<p>Please try again by clicking <a href="login.php">here</a>.</p>
			</div>
			</body>
			</html>
			';	
}
} else {
?>
<html>
<head>
<title>Register</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="head">the registration page</div>
<br>
<div id="main"> 
  <p>Welcome to the registration, fill out the form below and hit Submit. All fields are required,so fill them all out! </p>
  <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
  <table width="100%"  border="0" cellpadding="0" cellspacing="0">
	<tr class="firstRow">
	  <td width="50%">First name </td>
	  <td width="50%"><input name="firstname" type="text" class="textBox" id="firstname"></td>
	</tr>
	<tr class="secondRow">
	  <td>Surname</td>
	  <td><input name="surname" type="text" class="textBox" id="surname"></td>
	</tr>
	<tr class="firstRow">
	  <td>Email Address </td>
	  <td><input name="email" type="text" class="textBox" id="email"></td>
	</tr>
	<tr class="secondRow">
	  <td>Username</td>
	  <td><input name="username" type="text" class="textBox" id="username"></td>
    </tr>
	<tr class="firstRow">
	  <td>Password</td>
	  <td><input name="password" type="password" class="textBox" id="password"></td>
	</tr>
	<tr class="secondRow">
	  <td>Confirm Password </td>
	  <td><input name="confirm" type="password" class="textBox" id="confirm"></td>
	</tr>
	<tr class="firstRow">
	  <td>User Activation Code *</td>
	  <td><input name="activation" type="password" class="textBox" id="activation"></td>
	</tr>
	<tr class="secondRow">
	  <td>Register</td>
	  <td><input name="submit" type="submit" class="textBox" value="Submit"></td>
	</tr>
	<tr class="firstRow">
	  <td>* Activation codes assessed by your administrator</td>
	  <td>If you are already registered click <a href="login.php">here</a> to login</td>
	</tr>
  </table>
  </form>
</div>
</div>	
</body>
</html>
<?
}
?>

Link to comment
Share on other sites

in the Table codes their should be a field called code

 

But also their should be 2 entries..

 

with you created these manually was a sql file supplied ?

 

# check if activation code is correct

$q1 = mysql_query("SELECT code FROM codes WHERE id = 1") or die(mysql_error());

$q2 = mysql_query("SELECT code FROM codes WHERE id = 2") or die(mysql_error());

Link to comment
Share on other sites

the Entries i have no idea, mut have ID 1 and 2,

 

i asked if you had and SQL file,  sometimes developer dump the database setup to a SQL file you can just import into phpmyadmin and it does the work for you.. either that or a detailed doc..

Link to comment
Share on other sites

Ah, no, I have no SQL file. There's no doc either. :(

 

So now i've added a table called codes, and in that table there's a field called code.

 

Now, i'm getting the error: Unknown column 'id' in 'where clause'

 

What's the problem with this?  :-\

Link to comment
Share on other sites

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.