noobstar Posted August 18, 2006 Share Posted August 18, 2006 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 :) Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 18, 2006 Share Posted August 18, 2006 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] Quote Link to comment Share on other sites More sharing options...
noobstar Posted August 18, 2006 Author Share Posted August 18, 2006 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 ^_^ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.