Jump to content

PHP/MySQL/HTML sign-in/register form problem


skbanta

Recommended Posts

Yes, but this line is only inserting 2 of them, you need to add the others to it.

 

$insert = mysql_query("insert into $table values ('', '".$_POST['username']."',

'".$_POST['password']."')")

or die("Could not insert data because ".mysql_error());

 

Link to comment
Share on other sites

I added the rest of my fields and now come up with this error:

 

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/www/bantaproject.100webspace.net/register.php on line 26

 

This is my code:

 

// insert the data
$insert = mysql_query("insert into $table values ('', '".$_POST['username']."',
'".$_POST['password']."','".$_POST['email']."','".$_POST['address']"','".$_POST['city']"','
".$_POST['state']"','".$_POST['zip']"')")
or die("Could not insert data because ".mysql_error());

Link to comment
Share on other sites

// insert the data
$insert = mysql_query("insert into $table values ('', '".$_POST['username']."',
'".$_POST['password']."','".$_POST['email']."','".$_POST['address']"','".$_POST['city']"','
".$_POST['state']"','".$_POST['zip']."')")
or die("Could not insert data because ".mysql_error());

Link to comment
Share on other sites

// insert the data
$insert = mysql_query("insert into $table values ('', '".$_POST['username']."',
'".$_POST['password']."','".$_POST['email']."','".$_POST['address']"','".$_POST['city']"','
".$_POST['state']"','".$_POST['zip']."')")
or die("Could not insert data because ".mysql_error());

I added this and all the periods after each post, but now I get "Could not insert data because Column count doesn't match value count at row 1" again.  I am truly stumped as to what to do.

Link to comment
Share on other sites

// insert the data
$insert = mysql_query("insert into $table values ('".$_POST['username']."',
'".$_POST['password']."','".$_POST['email']."','".$_POST['address']"','".$_POST['city']"','
".$_POST['state']"','".$_POST['zip']."')")
or die("Could not insert data because ".mysql_error());

Link to comment
Share on other sites

Ok, thanks a lot for that part, I got the database to work, but now the log in wont work. it comes up with this error: "Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/www/bantaproject.100webspace.net/login.php on line 26"

 

here is the log-in code:

<?php

include("config.php"); 

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry); 

if ($num_rows <= 0) { 
echo "Sorry, your username or password is incorrect.<br>";
echo "<a href=index.html>Try again</a>";
echo "or";
echo "<a href=register.html>Register</a>
exit; 
} else {

setcookie("loggedin", "TRUE", time()+(3600 * 24));
setcookie("mysite_username", "$username");
echo "You are now logged in!<br>"; 
}
?>

 

(I hope this is one of the last times I have to code a register/log in system)

 

Link to comment
Share on other sites

<?php

include("config.php"); 

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry); 

if ($num_rows <= 0) { 
echo "Sorry, your username or password is incorrect.<br>";
echo "<a href=index.html>Try again</a>";
echo "or";
echo "<a href=register.html>Register</a>";
exit; 
} else {

setcookie("loggedin", "TRUE", time()+(3600 * 24));
setcookie("mysite_username", "$username");
echo "You are now logged in!<br>"; 
}
?>

Link to comment
Share on other sites

<?php

include("config.php"); 

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

$match = "select id from $table where username = '".$_POST['username']."'
and password = '".$_POST['password']."';"; 

$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry); 

if ($num_rows <= 0) { 
echo "Sorry, your username or password is incorrect.<br>";
echo "<a href=index.html>Try again</a>";
echo "or";
echo "<a href=register.html>Register</a>";
exit; 
} else {

setcookie("loggedin", "TRUE", time()+(3600 * 24));
setcookie("mysite_username", "$username");
echo "You are now logged in!<br>"; 
}
?>

There.

Link to comment
Share on other sites

Hmm...try this:

 

Find:

$match = "select id from $table where username = '".$_POST['username']."'

and password = '".$_POST['password']."';";

 

Replace

$match = "select id from $table where username = '".$_POST['username']."'

and password = '".$_POST['password']."'";

Link to comment
Share on other sites

Still can't get it to work. I look in my database and the username is empty and the password is in my email.  The whole row is moved one spot except id and password and username just aren't there.  I had a friend register too, but only one item shows up in the table.

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.