SQL addage

Associate
Joined
19 Oct 2005
Posts
528
G,day

Im adding some data to a mysql table which has a auto increment field. When i add the data using the php the table increments by one, but no other data is inserted from the PHP page. The php page drags data from a form on a html page. username,forename, password and email are the name of the fields in the html page.
thankyou muchly for any help

Code:
<?php
include("db_connect.php");
// Connect to the database.
//If the form was submitted, process it.
//Pick up the values from the previous form
$username =$_REQUEST['CustName'];
$forename =$_REQUEST['CustAddress'];
$password =$_REQUEST['CustTelNo'];
$email =$_REQUEST['CustE-mail'];

$query = "insert into Customer values
  ('$CustNumber','$CustName', '$CustAddress', '$CustTelNo', '$CustE-mail')";
  if (@mysql_query ($query))
    {
	echo 'The Customer has been added.';
	}
  else
    {
	echo 'The Customer could not be added because - ' . mysql_error();
	}
?>
 
hmmmmmmmmmmmmmm

If i specify the value will it still take the value from the html form? I added the blank space for the auto-increment but the database is still blank.

Code:
<?php
include("db_connect.php");
// Connect to the database.
//If the form was submitted, process it.
//Pick up the values from the previous form
$username =$_REQUEST['CustName'];
$forename =$_REQUEST['CustAddress'];
$password =$_REQUEST['CustTelNo'];
$email =$_REQUEST['CustE-mail'];

$query = "insert into Customer values
  ('','$CustName', '$CustAddress', '$CustTelNo', '$CustE-mail')";
  if (@mysql_query ($query))
    {
	echo 'The Customer has been added.';
	}
  else
    {
	echo 'The Customer could not be added because - ' . mysql_error();
	}
?>
 
Last edited:
hmmmmmmmmmmmmmm

So its still giving me blank database fields except the aut-increment

Code:
<?php
include("db_connect.php");
// Connect to the database.
//If the form was submitted, process it.
//Pick up the values from the previous form
$forename =$_REQUEST['CustName'];
$surname =$_REQUEST['CustAddress'];
$email =$_REQUEST['CustE-mail'];
$maiden =$_REQUEST['CustTelNo'];


$query = "insert into Customer values
  ('','$CustName', '$CustAddress', '$CustTelNo', '$CustE-mail')";
  if (@mysql_query ($query))
    {
	echo 'The Customer has been added.';
	}
  else
    {
	echo 'The Customer could not be added because - ' . mysql_error();
	}
?>

Its like the code isnt picking up the fields from the previous form? I have added the html form below


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<title>SCOTIA AIRWAYS</title>
	<link rel="stylesheet" type="text/css" href="layout.css" />
	<SCRIPT language=javascript>

function Validate() 
{
Message = ""
Message = Message + CheckName()
Message = Message + Checksurname()
Message = Message + CheckEmail()
Message = Message + Checkpasswords()
//Message = Message + Checkpassword2()
Message = Message + Checkmaiden()

if (Message == "") 
	{
	return true
	}
else 
	{
	alert(Message)
	return false
	}
}

function CheckName() {
var UserName = document.form1.forename.value

if (UserName == "") {
Message = "Something's wrong with your forename" + "\n"
}
else {
Message = ""
}
return Message

}

function Checksurname() {
var surname = document.form1.surname.value

if (surname == "") {
Message = "Something's wrong with your surname" + "\n"
}
else {
Message = ""
}
return Message

}

function CheckEmail() {
email = document.form1.email.value
AtPos = email.indexOf("@")
StopPos = email.lastIndexOf(".")
Message = ""
if (email == "") {
Message = "Not a valid Email address" + "\n"
}
if (AtPos == -1 || StopPos == -1) {
Message = "Not a valid email address"  + "\n"
}
if (StopPos < AtPos) {
Message = "Not a valid email address"  + "\n"
}
if (StopPos - AtPos == 1) {
Message = "Not a valid email address"  + "\n"
} 
return Message
}

function Checkpasswords() {
password = document.form1.password.value
password2 = document.form1.password2.value

txt = ""

if (password == "") {
Message = "Not a valid password" + "\n"
}
else

if (password == password2) {
Message = ""
}
else {
Message = "passwords dont match" + "\n"
}

return Message

}









//function Checkpassword2() {
//var Checkpassword2 = document.form1.password2.value

//if (Checkpassword2 == "") {
//Checkpassword2 = "please enter password" + "\n"
//}
//else {
//Message = ""
//}
//return Message
//
//}







function Checkmaiden() {
var maiden = document.form1.maiden.value

if (maiden == "") {
Message = "please enter a maiden name" + "\n"
}
else {
Message = ""
}
return Message
}


</SCRIPT>
	</head>
<body>
<div id="wrap">
	<div id="header">
    <h1><img src="bannerforscotiatesttestcopy.jpg" width="600" height="200"></h1>
  </div>
	<div id="nav">
		<ul>
			<li><a href="HOME.htm">Home</a></li>
			<li><a href="REGISTER.htm">Register</a></li>
			<li><a href="LOGIN.htm">Login</a></li>
			<li><a href="VIEWAVAILIBLEFLIGHTS.htm">View Availible Flights</a></li>
			<li><a href="CONTACT.htm">Contact</a></li>
			<li><a href="calculate.htm">Calculate</a></li>
		</ul>
	</div>
	
  <div id="main"> 
    <h2>Welcome...</h2>
    <p>Please Register Below</p>
    <form name="form1" onsubmit="return Validate()" method="post" action="registerphp.php">
      <p><font color="#FF0000"> 
        <input name="forename" type="text" id="forename" />
        Customer Name</font></p>
      <p><font color="#FF0000"> 
        <textarea name="surname" id="surname"></textarea>
        Customer Address</font></p>
      <p><font color="#FF0000"><br />
        <input name="email" type="text" id="email" />
        e-mail address <br />
        <input name="password" type="password" id="password" />
        password<br />
        <input type="password" name="password2" id="password2" />
        confirmation of the password </font></p>
      <p><font color="#FF0000"><br />
        <input type="text" name="maiden" id="maiden" />
        Customer Telephone Number (for security purposes) </font></p>
      <p><font color="#FF0000"> 
        <input type="submit" name="Submit" value="Submit" />
        <input type="reset" name="Submit2" value="Reset" />
        </font></p>
    </form>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
  </div>
	<div id="sidebar">
		<h3>Availible Flights</h3>
		
    <p>Book Your Flight With Scotia Today</p>
		</div>
	<div id="footer">
		
    <p>Copyright: Andrew Comrie 2006</p>
	</div>
</div>
</body>
</html>

any help appreciated! I am getting driven mad.
 
array(7) { ["forename"]=> string(4) "dfsd" ["surname"]=> string(7) "sdfsfss" ["email"]=> string(18) "[email protected]" ["password"]=> string(3) "123" ["password2"]=> string(3) "123" ["maiden"]=> string(6) "sdfsdf" ["Submit"]=> string(6) "Submit" }

Does that mean i should get rid of the textfields not going into the database?
 
hmmmmmmmmmmmm

ok i have done that, now when i submit the php page just shows a blank page.

Code:
<?php
include("db_connect.php");
// Connect to the database.
//If the form was submitted, process it.
//Pick up the values from the previous form
var_dump($_POST);
$CustName =$_POST['forename'];
$CustAddress =$_POST['surname'];
$CustE-mail =$_POST['email'];
$CustTelNo =$_POST['maiden'];


$query = "INSERT INTO Customer values ('','$CustName', '$CustAddress', '$CustTelNo', '$CustE-mail')";
  if (@mysql_query ($query))
    {
	echo 'The Customer has been added.';
	}
  else
    {
	echo 'The Customer could not be added because - ' . mysql_error();
	}
?>
 
Last edited:
hmmmmmmmmmm

Code:
<?php
include("db_connect.php");
// Connect to the database.
//If the form was submitted, process it.
//Pick up the values from the previous form
var_dump($_POST);
$CustName =$_POST['forename'];
$CustAddress =$_POST['surname'];
$CustTelNo =$_POST['maiden'];
$CustEmail =$_POST['email'];



mysql_query("INSERT INTO customer ('CustName','CustAddress','CustTelNo','CustEmail')   values('$CustName','$CustAddress','$CustTelNo','$CustEmail')")
  if (@mysql_query($query))
    {
	echo 'The Customer has been added.';
	}
  else
    {
	echo 'The Customer could not be added because - ' . mysql_error();
	}
?>

right ok should it look like that? I have done that but it still comes up with a blank page.
 
hmmmmmmmmmmmmmmm

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 ''CustName','CustAddress','CustTelNo','CustEmail') values('andrew','asdasd','1231' at line 1

Code:
<?php
include("db_connect.php");
// Connect to the database.
//If the form was submitted, process it.
//Pick up the values from the previous form
var_dump($_POST);
$CustName =$_POST['forename'];
$CustAddress =$_POST['surname'];
$CustTelNo =$_POST['maiden'];
$CustEmail =$_POST['email'];


if (@mysql_query("INSERT INTO Customer ('CustName','CustAddress','CustTelNo','CustEmail') values('$CustName','$CustAddress','$CustTelNo','$CustEmail')"))
    {
	echo 'The Customer has been added.';
	}
  else
    {
	echo 'The Customer could not be added because - ' . mysql_error();
	}
?>
 
hmmmmmmmmmmmmmm

Ok i have got it down to just this error now.

ou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@asdas.com)' at line 1

Thats the part where i enter the e-mail address.

Code:
<?php
include("db_connect.php");
// Connect to the database.
//If the form was submitted, process it.
//Pick up the values from the previous form
var_dump($_POST);
$CustName =$_POST['forename'];
$CustAddress =$_POST['surname'];
$CustTelNo =$_POST['maiden'];
$CustEmail =$_POST['email'];


if (@mysql_query("INSERT INTO Customer(CustName,CustAddress,CustTelNo,CustEmail) values($CustName, $CustAddress, $CustTelNo, $CustEmail)"))
    {
	echo 'The Customer has been added.';
	}
  else
    {
	echo 'The Customer could not be added because - ' . mysql_error();
	}
?>
 
hmmmmmmmmmmm

Code:
<?php
include("db_connect.php");
// Connect to the database.
//If the form was submitted, process it.
//Pick up the values from the previous form
var_dump($_POST);
$CustName = mysql_real_escape_string($_POST['forename']);
$CustAddress = mysql_real_escape_string($_POST['surname']);
$CustTelNo = mysql_real_escape_string($_POST['maiden']);
$CustEmail = mysql_real_escape_string($_POST['email']);


if (@mysql_query("INSERT INTO Customer(CustName, CustAddress, CustTelNo, CustEmail) VALUES($CustName, $CustAddress, $CustTelNo, $CustEmail)"))
    {
	echo 'The Customer has been added.';
	}
  else
    {
	echo 'The Customer could not be added because - ' . mysql_error();
	}
?>

Escaped it. Still got the same problem as above.
 
Back
Top Bottom