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