Jump to content

Need help inputing data into a database useing php/SQL


david_php_nub

Recommended Posts

OK i have a web site where i want people to input they details into a data base.

 

The html page is

 

<HTML>
<HEAD>
<TITLE>Get in contact</TITLE>
</HEAD>
<BODY>
<br>
<br>
<br>
<img style="position:absolute;top:0;left:0;z-index:-1" src="http://hermes.hud.ac.uk/c0670061/pic1.jpg">
<H1><CENTER><font color="#0000A0" face="Script MT Bold" size="6">
Contact Us
</font></CENTER></H1>
<br>
<br>
<br>
<br>
<H1><CENTER><font color="black" face="Constantia" size="4">
If you are interested in our service please input your details for us to get in touch with you. <br>
Alternately you can get in touch with us <a href="http://hermes.hud.ac.uk/c0670061/Companydetails.html">hear</a>
</font></CENTER></H1>
<br>
<form action="Details.php" method=post>

<CENTER><table border=0>
<tr>
<td width=150>First Name</td>
<td>
<input type="text" name="fname" size="10" maxlength="10">
</td>
</tr>
<tr>
<td width=150>Last Name</td>
<td>
<input type="text" name="lname" size="10" maxlength="10">
</td>
</tr>
<tr>
<td width=150>Address</td>
<td>
<textarea name="address" cols="40" rows="5">
</textarea><br>
</td>
</tr>
<tr>
<td width=150>Phone Number</td>
<td>
<input type="text" name="pnumber" size="15" maxlength="15">
</td>
</tr>
<tr>
<td width=150>Email</td>
<td>
<input type="text" name="email" size="30" maxlength="30">
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value"submit"></td>
</tr>
</TABLE></CENTER>

<CENTER><TABLE BORDER = “1”>
<tr>
<td>
<A HREF  = "http://hermes.hud.ac.uk/c0670061/homepage.html">Home</A>
</td>
<td>
<A HREF  = "http://hermes.hud.ac.uk/c0670061/Admin.html">Admin</A>
</td>
<td>
<A HREF  = "http://hermes.hud.ac.uk/c0670061/Companydetails.html">Company Details</A>
</td>
</tr>
</TABLE></CENTER>


</BODY>
</HTML>

 

And the details.PHP page is

 

<?php
$firstName = $_REQUEST['fname'];
$lastName = $_REQUEST['lname'];
$address = $_REQUEST['address'];
$phoneNumber = $_REQUEST['pnumber'];
$email = $_REQUEST['email'];

$db = mysql_connect("localhost", "*****", "*****") or die("Could not connect to database");

mysql_select_db("******");

$result = mysql_query("INSERT INTO Client Details (First_Name, Last_Name, Address, Phone_Number, Email) VALUES ('$firstName', '$lastName', '$address', '$phoneNumber', '$email')");
mysql_close($db);
if($result === false) {
print_r(mysql_error()); 
echo "no add";
}
else {
echo "Good it bloody added";
}
?>

 

details of the database in myphp

 

Table: Client Details

Field  Type Collation Attributes Null Default Extra Action

  First_Name  varchar(15) latin1_swedish_ci  Yes  NULL               

  Last_Name  varchar(15) latin1_swedish_ci  Yes  NULL               

  Address  text latin1_swedish_ci  Yes  NULL               

  Phone_Number  int(15)    Yes  NULL               

  Email  varchar(30) latin1_swedish_ci  No                 

Check All  /  Uncheck All    With selected:         

 

The problem is the data is not being saved and the page comes back with "no add"

 

I hope someone can help thanks.

 

alter mysql query...

tablename should not space...

Client Details change it as ClientDetails

 

$result = mysql_query("INSERT INTO ClientDetails (First_Name, Last_Name, Address, Phone_Number, Email) VALUES ('$firstName', '$lastName', '$address', '$phoneNumber', '$email')");

 

ok i have changed the database name to "Client_Details"

 

and changed to

 

$result = mysql_query("INSERT INTO 'Client_Details' (First_Name, Last_Name, Address, Phone_Number, Email) VALUES ('$firstName', '$lastName', '$address', '$phoneNumber', '$email')");

 

and also trayed

 

$result = mysql_query("INSERT INTO Client_Details (First_Name, Last_Name, Address, Phone_Number, Email) VALUES ('$firstName', '$lastName', '$address', '$phoneNumber', '$email')");

 

both show the echo "no add" when i try to input some data, but there are no SQL errors showing up in the myphpadmin.

 

 

DO THIS....

 

$result = mysql_query("INSERT INTO Client_Details (First_Name, Last_Name, Address, Phone_Number, Email) VALUES ('$firstName', '$lastName', '$address', '$phoneNumber', '$email')");

 

if(!$result ) {

//print_r(mysql_error());

echo "no add";

}

else {

echo "Good it bloody added";

}

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.