This PHP isnt adding a row to my table

F

-fool-

Guest
register.php
PHP:
<?php 
include('includes/header.php'); 
$error = $_GET['error']; 
if(strlen($error) != 0) 
{ 
     
    echo str_replace("_", " ", $error); 
} 
?> 
<form name="input" action="registrar.php" method="get"> 
<br>Username: <input type="text" name="usernam"> 
<br>Password: <input type="password" name="passwor"> 
<br><input type="submit" value="Register"> 
</form> 
<?php 
include('includes/footer.php'); 
?>

registrar.php
PHP:
<?php
include('includes/vars.php');

mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
@mysql_select_db(MYSQL_DATABASE) or die( "Unable to select database");

$username = $_GET['usernam'];
$password = $_GET['passwor'];
if(strlen($username == 0) || strlen($password) == 0)
{
	mysql_close();
	header("Location: register.php?error=You_made_a_mistake");
}

$result = mysql_query("SELECT * FROM users");
$i = mysql_numrows($result);
$j = 0;

while($j < $i)
{
	if($username == mysql_result($result,$j,"username"))
	{
		$badName = true;
		break;
	}
	$j++;
}

if($badName == true)
{
	mysql_close();
	header("Location: register.php?error=Username_already_taken");
}
else
{
	//id(int), username(varchar), password(varchar), quotesnumber(int), access(int)
	$query = "INSERT INTO users VALUES ($i, $username, $password, 0, 0)";
	mysql_query($query);
	mysql_close();
	header("Location: register.php?error=Success");
}
?>
 
P

Persen

Guest
I can't see anything wrong, but try with NULL instead of ''
 
F

-fool-

Guest
i got rid of most of the table fields and still same thing. nothing happens :eek:
 
P

Persen

Guest
You need to use '' around the fields. What i meant, was to use NULL instead of the blank ' pairs.
 

mixmax2

RedArmyGangsta
Reaction score
31
I don't know if this my fix it, but try this, i remember having a similar problem and this worked for me.
When i tried to insert only a certain amount of values, like say theres 4 fields to a row, username, password, avatar, bubblepuff


If i try to insert values only into username, password, and bubblepuff, it NEVER works, so to solve my problems i insert all 4, and just leave avatar as "" (A Blank Value") So if you arent insert every available value, there might be the problem.
 

mixmax2

RedArmyGangsta
Reaction score
31
Then let my post be a solution for someone who finds this thread through google, and has the same problem :p :rolleyes:
 
F

-fool-

Guest
i actually couldnt get it to work and gave up... now i have a way of registering people into a table my next step i guess is a login system. i should use session variables for that right?
 

mixmax2

RedArmyGangsta
Reaction score
31
-fool- said:
i actually couldnt get it to work and gave up... now i have a way of registering people into a table my next step i guess is a login system. i should use session variables for that right?

Yeah, I use Cookies that last an hour.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top