4 Replies - 377 Views - Last Post: 25 April 2013 - 05:30 PM Rate Topic: -----

#1 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 128
  • Joined: 30-January 13

need help linking pages

Posted 25 April 2013 - 01:00 AM

I am fairly new to php and my sql but learning quite quick. This is my problem though I am trying to set up a members only site that will be written through php and hold the users information in my sql. I've set up my sql and written several pages of code but for some reason when a user is at the home page and they click the link to sign up as a new member they are taken directly to the members page without even creating a new user name and password. When they click the link they should be taken to the form and if they meet all requirments they should then be taken to the memebers page and their information should be saved in tblusers. I have posted my code please let me know if you see anything that could be causing this or if you need more info it is driving me crazy and I know it has to be something minor.
This is my code for my new member form I've called it new.php
<?php
function FormDisplay($strMessage="Please fill in all feilds"){
echo"<p><strong>".$strMessage."</strong></p>\n";
echo"<form method=\"post\" action=\"".$PHP_SELF."\" >\n";
echo"<table>\n";
echo"<tr>\n";
echo"<td>First name</td>\n";
echo"<td><input type=\"text\" name=\"firstname\" value=\"". $_POST['firstname']."\"/> \n";
echo"</td>\n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td>Last name</td>\n";
echo"<td><input type=\"text\" name=\"lastname\" value=\"". $_POST['lastname']."\"/></td> \n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td>Username:</td>\n";
echo"<td><input type=\"text\" name=\"username\" value=\"". $_POST['username']."\"/></td> \n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td>Email</td>\n";
echo"<td><input type=\"text\" name=\"email\" value=\"". $_POST['email']."\"/></td> \n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td>Password</td>\n";
echo"<td><input type=\"password\" name=\"password1\" /></td> \n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td nowrap=\"nowrap\">Repeat Password:</td>\n";
echo"<td><input type=\"password\" name=\"password2\" /></td> \n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td>Address</td>\n";
echo"<td><input type=\"text\" name=\"address\" value=\"". $_POST['address']."\"/></td> \n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td>City</td>\n";
echo"<td><input type=\"text\" name=\"city\" value=\"". $_POST['city']."\"/></td> \n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td>State</td>\n";
echo"<td><input type=\"text\" name=\"State\" value=\"". $_POST['state']."\"/></td> \n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td>Zip</td>\n";
echo"<td><input type=\"text\" name=\"zip\" value=\"". $_POST['zip']."\"/></td> \n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td>Phone</td>\n";
echo"<td><input type=\"text\" name=\"phone\" value=\"". $_POST['phone']."\"/></td> \n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td>&nbsp;</td>\n";
echo"<td><input type=\"submit\" name=\"submit\" value=\"Sign me up!!!\" class=\"submit\"</td>";
echo"</tr>\n";
echo"</table>\n";
echo"</form>/n";
}
if ($_POST['submit']!=""){
if ($_POST['fname']=="" || $_POST['lname']=="" || $_POST['username']=="" || $_POST['email']=="" || $_POST['password']=="" || $_POST['ConfirmPassword']=="" ||  $_POST['address']=="" || $_POST['city']=="" || $_POST['State']=="" ||  $_POST['zip']=="" || $_POST['phone']=="");
$error=1;
}
else if ( $_POST['password1']!=$_POST['password2']){
$error=2;
}
else{
$hostname="localhost"; //It is local host with wamp server and most other servers
$database="contacts";
$mysql_login="login_name";
$mysql_password="sql_password";
if (!($db = mysql_connect($hostname, $mysql_login , $mysql_password))){
echo"error on connect";
}
else{
if (!(mysql_select_db($database,$db))){
echo mysql_error();
echo"<br>error on db connection";
}
else{
$SQL="Insert into tblUsers (firstname,lastname,username,email,password1,password2,address,city,State,zip,phone,signupDate) values('".$_POST['firstname']."'.'".$_POST['lastname']."'.'".$_POST['username']."'.'".$_POST['email']."'.PASSWORD('".$_POST['password1']."').'".$_POST['address']."'.'".$_POST['city']."'.'".$_POST['State']."'.'".$_POST['zip']."'.'".$_POST['phone']."'.NOW())";
mysql_query($SQL);
if (is_numeric(mysql_insert_id())){
header("Location:memberworthy.php?name=".$_POST['username']);
}
else{
echo"There had been an error contact the administrator.";
}
mysql_close($db);
}
}
}
?>
<html>
<head>
<title>
</title>
</head>
<body>
<?php
if ($error==1){
FormDisplay("You must enter all feilds");
}
elseif ($error==2){
FormDisplay("Your Passwords did not match");
}
else{
FormDisplay();
}
?>
</body>
</html>

This is the code for my home page which has the link to new.php
<html>
<head>
<title></title>
</head>
<body>
<h3>already a member? Please sign in!</h3>
<p><a href="new.php">Sign Up!</a></p>
<?php
If ($_GET['mode']==1){
echo"<p>Please enter your name and password</p>";
}
else if ($_GET['mode']==2){
echo"<p>Your user name and password combination does not match our records. Please try again!</p>";
}
else if ($_GET['mode']==3){
$username=$_GET['username'];
echo"<P>".$username.", please use your user name and password to sign in</p>";
}
?>


<form method="post" action="login.php">
			Username: <input type="text" name="uName" />
			<br />
			Password: <input type="password" name="pWord" />
			<br />
			<input type="submit" name="submit" value="submit" />
		</form>
	</body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: need help linking pages

#2 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 128
  • Joined: 30-January 13

Re: need help linking pages

Posted 25 April 2013 - 01:08 AM

ok I think I figured it out I think I was using the wrong name and password becuase I changed the password and now its taking me to the correct page but the wrong name is being used I guess lol I knew it had to be something dumb.
Was This Post Helpful? 0
  • +
  • -

#3 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 128
  • Joined: 30-January 13

Re: need help linking pages

Posted 25 April 2013 - 01:15 AM

nevermind it is when the name and password are correct it screws up if anyone can help sorry.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3515
  • View blog
  • Posts: 10,141
  • Joined: 08-June 10

Re: need help linking pages

Posted 25 April 2013 - 02:51 AM

ok, some issues I see:
  • the mysql extension is outdated and officially deprecated. you should use the more modern PDO or MySQLi extensions instead.
  • your SQL is highly susceptible to SQL Injection.
  • $PHP_SELF does not exist, unless you use register_globals, which is a high security risk (and IIRC removed as of PHP 5.4).
  • if a query fails, the querying function/method (here mysql_query()) returns false. you should always check that.
  • you should not echo inside a function (maybe except rare cases, which do not apply here), esp. if you have lots of text. the better way is to use a template for the HTML (i.e. load it from a text file and replace the values of interest (cf. sprintf()))
  • itís "fields", not "feilds".
  • in case of an (DB) error, you echo content prior to the HTML body, which is invalid.
  • the SQL PASSWORD() function is meant to set the password of the SQL user, not to make user passwords. the currently best approach for storing user passwords is using a bcrypt hash (in PHP this is done via the crypt() function using the Blowfish algorithm. there is a nice library named PHPass to ease its use)
  • Iím sure the database is not sensibly normalised.
  • mysql_insert_id() returns 0 if there is no insert ID available. only if there is no connection it will return false. that is, in your case the redirect is always triggered.
  • and of course your member page (login.php) must authenticate the user.
  • I recommend the use of Exceptions over error variables.

I think I can find more, but that should cover the most important issues.
Was This Post Helpful? 3
  • +
  • -

#5 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 128
  • Joined: 30-January 13

Re: need help linking pages

Posted 25 April 2013 - 05:30 PM

Thank you for the reply I am pretty new to this and trying to learn it and I think all these errors will give me a good start.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1