Jump to content


Photo

Need help with a signUp system


  • Please log in to reply
2 replies to this topic

#1 noobstar

noobstar
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts
  • LocationMelbourne, Australia

Posted 18 August 2006 - 08:34 AM

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:

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

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 :)

#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 18 August 2006 - 08:58 AM

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:

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


#3 noobstar

noobstar
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts
  • LocationMelbourne, Australia

Posted 18 August 2006 - 09:04 AM

Woops your correct sorry i was thinking that every username should be unique (which it is lol i just realized) and therefore i made that userid, bad habbit :(

Anyways sorry for the trouble.

Thx though ^_^




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users