Jump to content

Need help with a signUp system


noobstar

Recommended Posts

Hi everyone :)

Im fairly new to the php scene and thought this would be a nice place to ask my question.

Im using the latest version of wampserver to run all my php files and phpmyadmin to make my databases.

Oki to my question, with my signup system it is supposed to assign an automatic 'userid' using a loop and it works 50/50 the code is below if that will help you figure it out:

[code]<html>
<body>
<?php
$host= 'localhost';
$user = 'root';
$passwd = '';
$my_database = 'login';

$userid = $_POST['userid'];
$username = $_POST['username'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$city = $_POST['city'];
$postcode = $_POST['postcode'];

$connect = mysql_connect($host, $user, $passwd);
$table_name = 'user';

for($userid=1;$userid <= 10;$userid++)
{
$sql= "INSERT INTO `user` ( `userid` , `username` , `password` , `firstname` , `lastname`, `address`, `city`, `postcode` ) "
. " VALUES ( '$userid', '$username', '$password', '$firstname', '$lastname', '$address', '$city', '$postcode');";
}

mysql_select_db($my_database);
$results_id = mysql_query($sql, $connect);
if ($results_id)
{
print 'SignUp Successfull!<p />';
}
else
{
die ("Query=$sql failed! <p />");
}

echo "<form name='add' method='POST' action='login.php'>";
echo "<input type='submit' value='Back'>";
echo "</form>";

mysql_close($connect);
?>
</table>
</body>
</html>[/code]

I am using a html site with all the text boxes and once the person hits on submit it then goes to the signup.php script which then adds all the text or numbers from the text boxes from the html into the database. The code works but with the loop everytime i make up a persons username, password etc. the userid comes up as 10. I've tried using a for loop also but it didn't work (loops aren't my strong side :()

Any help is appreciated Thx :)
Link to comment
https://forums.phpfreaks.com/topic/17926-need-help-with-a-signup-system/
Share on other sites

Im struggling to understand why you'd need a loop; surely one person isn't going to sign up more than one account?

Try something like this:

[code]
<html>
<body>
<?php
$host= 'localhost';
$user = 'root';
$passwd = '';
$my_database = 'login';

$userid = $_POST['userid'];
$username = $_POST['username'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$city = $_POST['city'];
$postcode = $_POST['postcode'];

$connect = mysql_connect($host, $user, $passwd);
mysql_select_db($my_database);//moved this here becuase i would say it is confusing to have it further down the script.
$table_name = 'user';

$sql= "INSERT INTO `user` ( `userid` , `username` , `password` , `firstname` , `lastname`, `address`, `city`, `postcode` ) "
. " VALUES ( '$userid', '$username', '$password', '$firstname', '$lastname', '$address', '$city', '$postcode');";
}

$results_id = mysql_query($sql);
if ($results_id)
{
print 'SignUp Successfull!<p />';
}
else
{
die ("Query=$sql failed! <p />");
}

echo "<form name='add' method='POST' action='login.php'>";
echo "<input type='submit' value='Back'>";
echo "</form>";

mysql_close($connect);
?>
</table>
</body>
</html>
[/code]

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.