Jump to content

issues with a create new account page


vmicchia

Recommended Posts

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

Link to comment
Share on other sites

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";
}
?>

Link to comment
Share on other sites

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

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.