vmicchia Posted February 27, 2009 Share Posted February 27, 2009 I'm having some trouble with a create new account page. Here's my php to create the account: <?php //connect to the db include("DBConn_php.inc"); //start session session_start(); //get the data from the form $userID=$_POST["login"]; $psw1=$_POST["password"]; $psw2=$_POST["confirmPassword"]; $firstName=$_POST["firstName"]; $lastName=$_POST["lastName"]; $email=$_POST["email"]; $newsletter=$_POST["newsletter"]; $billID=$_POST["billID"]; $billName=$_POST["billName"]; $billAddress=$_POST["billAddress"]; $billAddress2=$_POST["billAddress2"]; $billCity=$_POST["billCity"]; $billState=$_POST["billState"]; $billZip=$_POST["billZip"]; $cardType=$_POST["cardType"]; $cardNumber=$_POST["cardNumber"]; $expDate=$_POST["expDate"]; $shipID=$_POST["shipID"]; $shipName=$_POST["shipName"]; $shipAddress=$_POST["shipAddress"]; $shipAddress2=$_POST["shipAddress2"]; $shipState=$_POST["shipState"]; $shipCity=$_POST["shipCity"]; $shipZip=$_POST["shipZip"]; //set a query to check login $sql = mysql_query("SELECT Login FROM employess WHERE Login='".$userID."'"); //check if the passwords match if($psw1==$psw2){ if(mysql_num_rows($sql) > 0 ) { //check if there is already an entry for that username echo "Username is already taken"; } else { //form insert statement $sql="INSERT INTO employee(Login, Passwd, FirstName, LastName, Email, NewsLetter) VALUES('".$userID."','".$psw1."','".$firstName."','".$lastName."','".$email."','".$newsletter."')"; $sql="INSERT INTO billing(BillingID, Login, BillName, BillAddress1, BillAddress2, BillCity, BillState, BillZip, CardType, CardNumber, ExpDate) VALUES('".$billID."','".$userID."','".$billName."','".$billName."','".$billAddress."','".$billAddress2."','".$billCity."','".$billState."','".$billZip."','".$cardType."','".$cardNumber."','".$expDate."')"; $sql="INSERT INTO address(AddressID, Login, Name, Address1, Address2, City, State, Zip) VALUES('".$shipID."','".$userID."','".$shipName."','".$shipAddress."','".$shipAddress2."','".$shipCity."','".$shipState."','".$shipZip."')"; //insert user into the db $result=mysql_Query($sql); //message to user $_SESSION["messge"]="User added successfully"; //redirect header("Location:success.php"); } }else{ //let them know passwords do not match echo "passwords do not match"; } ?> It connects with a database that has tables of employees, billing, and address. As for the errors I am getting they are first of all it says that all my variables are undefined indexes. and then i have 2 more errors: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\Inetpub\wwwroot\356\vmicchia1k\Project1\createNewAccount.php on line 40 Warning: Cannot modify header information - headers already sent by (output started at c:\Inetpub\wwwroot\356\vmicchia1k\Project1\createNewAccount.php:10) in c:\Inetpub\wwwroot\356\vmicchia1k\Project1\createNewAccount.php on line 59 I'm really lost as to how to fix this. THanks for the help in advance Quote Link to comment Share on other sites More sharing options...
trq Posted February 27, 2009 Share Posted February 27, 2009 Did you read the big header sticky at the top of this board? Quote Link to comment Share on other sites More sharing options...
vmicchia Posted February 27, 2009 Author Share Posted February 27, 2009 I assume you mean the header thing and yes I did I apologize that I even put that I can figure it out it's the rest but thank you for the understanding and help. Quote Link to comment Share on other sites More sharing options...
unrelenting Posted February 27, 2009 Share Posted February 27, 2009 Is employess supposed to be spelled that way? If not, then there is likely your num_rows error. Quote Link to comment Share on other sites More sharing options...
vmicchia Posted February 27, 2009 Author Share Posted February 27, 2009 no it was not but i commented it out and a lot more of the code to just the basics and I get the same errors. Here is the new code: <?php //connect to the db include("DBConn_php.inc"); //start session session_start(); //get the data from the form $userID=$_POST["login"]; $psw1=$_POST["password"]; $psw2=$_POST["confirmPassword"]; $firstName=$_POST["firstName"]; $lastName=$_POST["lastName"]; $email=$_POST["email"]; $newsletter=$_POST["newsletter"]; if($psw1==$psw2){ //form insert statement $sql="INSERT INTO employee(Login, Passwd, FirstName, LastName, Email, NewsLetter) VALUES('".$userID."','".$psw1."','".$firstName."','".$lastName."','".$email."','".$newsletter."')"; //insert user into the db $result=mysql_Query($sql); //message to user $_SESSION["messge"]="User added successfully"; //redirect header("Location:index.php"); }else{ //let them know passwords do not match echo "passwords do not match"; } ?> Quote Link to comment Share on other sites More sharing options...
vmicchia Posted February 27, 2009 Author Share Posted February 27, 2009 I guess my biggest problem that I don;t understand is the errors for the variables: Notice: Undefined index: login in c:\Inetpub\wwwroot\356\vmicchia1k\Project1\createNewAccount.php on line 9 Quote Link to comment Share on other sites More sharing options...
unrelenting Posted February 27, 2009 Share Posted February 27, 2009 It must not be getting you submitted variables correctly. Try echoing out those variables and see what they hold. Quote Link to comment Share on other sites More sharing options...
vmicchia Posted February 27, 2009 Author Share Posted February 27, 2009 When I try to echo it, it just gives me the same error for my echo statement. Quote Link to comment Share on other sites More sharing options...
unrelenting Posted February 27, 2009 Share Posted February 27, 2009 When I try to echo it, it just gives me the same error for my echo statement. Post your form page code. Quote Link to comment Share on other sites More sharing options...
vmicchia Posted February 27, 2009 Author Share Posted February 27, 2009 <h1>Create New Account</h1> <hr /> <h2>Login Information</h2></div> <form name="createNewAccount" action="createNewAccount2.php"> <table> <tr> <td align="right">First Name:</td><td><input name="firstName" type="text" size="30" maxlength="25" value="<? if(!empty($_SESSION['firstName'])){ echo $_SESSION['firstName']; } ?>" /></td> </tr> <tr> <td align="right">Last Name:</td><td><input name="lastName" type="text" size="30" maxlength="30" value="<? if(!empty($_SESSION['lastName'])){ echo $_SESSION['lastName']; } ?>" /></td> </tr> <tr> <td align="right">e-mail:</td><td><input name="email" type="text" size="30" maxlength="40" value="<? if(!empty($_SESSION['email'])){ echo $_SESSION['email']; } ?>" /></td> </tr> <tr> <td align="right">Desired Login:</td><td><input name="login" type="text" size="30" maxlength="15" /></td> </tr> <tr> <td align="right">Password:</td><td><input name="password" type="text" size="30" maxlength="15" /></td> </tr> <tr> <td align="right">Confirm Password:</td><td><input name="confirmPassword" type="text" size="30" maxlength="15" /></td> </tr> <tr> <td align="right">Newsletter?</td><td align="left"><input name="newsletter[]" type="checkbox" value="true" /></td> </tr> <tr> <td colspan="2" align="center"><input name="submit" type="submit" value="Submit" /></td> </tr> <tr> <td colspan="2" align="center"><input name="reset" type="reset" value="Reset" /></td> </table> </form> Quote Link to comment Share on other sites More sharing options...
unrelenting Posted February 27, 2009 Share Posted February 27, 2009 Add this to your form tag.. method="post" I also noticed that in your form you point to createNewAccount2.php but all of your posted errors it says createNewAccount.php. Quote Link to comment Share on other sites More sharing options...
vmicchia Posted February 27, 2009 Author Share Posted February 27, 2009 Yeah i noticed the method thing I'm dumb and as for the 2 one I had created a new one trying things out. I think I have most of it figured out thanks. I'm still getting an error but nothing as major. 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.