Jump to content

[SOLVED] help with login form


Rother2005

Recommended Posts

hi im new to PHP, im just having a play about really before i begin college next year

ive tried to do a login form, real basic just one page with a form to compelete and once you submit the data goes into the database

ive got this so far:

<?php
include('connect1.inc');?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Booze Cruise Reg</title>

</head>
<body>

<?php
if(!$_POST['register']){echo'<p align="center"><strong>Member Registration</strong></p>
<form name="form1" method="POST" action="">
<p align="center">Username: <input type="text" name="username"></p>
<p align="center">Password: <input type="text" name="password"></p>
<p align="center">Firsname: <input type="text" name="firstname"></p>
<p align="center">Surname:  <input type="text" name="surname"></p>
<p align="center">Address1: <input type="text" name="address1"></p>
<p align="center">Address2: <input type="text" name="address2"></p>
<p align="center">Town:    <input type="text" name="town"></p>
<p align="center">County:  <input type="text" name="county"></p>
<p align="center">Postcode: <input type="text" name="postcode"></p>
<p align="center">Tel No:  <input type="text" name="telno"></p>
<p align="center">Mobile:  <input type="text" name="mobile"></p>
<p align="center">Email:    <input type="text" name="email"></p>
<p align="center"><input type="submit" name="register" value="Enter Details"></p></form>';}

else{$username=$_POST['username'];$password=$_POST['password'];$firstname=$_POST['firstname'];$surname=$_POST['surname'];$address1=$_POST['address1'];$address2=$_POST['address2'];$town=$_POST['town'];$county=$_POST['county'];
$postcode=$_POST['postcode'];$telno=$_POST['telno'];$mobile=$_POST['mobile'];$email=$_POST['email'];

$sql = "INSERT INTO member(Username,Password,Firstname,Surname,Address 1,Address 2,Town,County,Postcode,Tel No,Mobile,Email)
VALUES ('"$_POST['username']."',$_POST['password']."',$_POST['firstname']."',$_POST['surname']."',$_POST['address1']."',$_POST['address2']."',=$_POST['town']."',$_POST['county']."',$_POST['postcode']."',$_POST['telno']."',$_POST['mobile']."',$_POST['email']."')";

mysql_query($sql)             

or die("Couldn't execute query - add new member. Sorry $username");

echo("You are registered! $username");}?>

</body>
</html>

the error i get is "Couldn't execute query - add new member. Sorry $username" , the $username works no probs and displays it on the next screen so its writing the data to memory (if that what is does!!) but not to my database now ive been tryin for 3 weeks so finally ive broken down with stress and thought i need help  ???

here is the .inc file also:

<?php
$connection=mysql_connect("localhost","root","");
mysql_select_db(booze) or die(mysql_error());
?>

many thanks in advance
Link to comment
https://forums.phpfreaks.com/topic/32408-solved-help-with-login-form/
Share on other sites

I see something there... the quotes are kind of messed up.

Replace
[quote]VALUES ('"$_POST['username']."',$_POST['password']."',$_POST['firstname']."',$_POST['surname']."',$_POST['address1']."',$_POST['address2']."',=$_POST['town']."',$_POST['county']."',$_POST['postcode']."',$_POST['telno']."',$_POST['mobile']."',$_POST['email']."')";[/quote]

With:[quote]
VALUES ('".$_POST['username']."','".$_POST['password']."','".$_POST['firstname']."','".$_POST['surname']."','".$_POST['address1']."','".$_POST['address2']."','".$_POST['town']."','".$_POST['county']."','".$_POST['postcode']."','".$_POST['telno']."','".$_POST['mobile']."','".$_POST['email']."')";[/quote]

Basically, you missed some dots and some single and double quotes. One tip though, you assigned each of these POST values to variables earlier, you could use those to avoid confusion:
[quote]VALUES ('$username','$password','$firstname','$surname','$address1','$address2','$town','$county','$postcode','$telno','$mobile','$email')";[/quote]

And, again, please don't use .inc as a include extension. It's dangerous :D
ok ur a star for helping

this new error is coming up

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1,Address 2,Town,County,Postcode,Tel No,Mobile,Email) VALUES ('a','b','c','d',' at line 1

ive check my spelling in the database and it matches the one on the insert into line (line 31) is the space a problem 'address 1'?

HAPPY NEW YEAR!!

ps i used the VALUES ('$username','$password','$firstname','$surname','$address1','$address2','$town','$county','$postcode','$telno','$mobile','$email')"; line

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.