Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems inserting info into MySQL Database 1

Status
Not open for further replies.

chieftan

MIS
Dec 18, 2002
292
GB
Hopefully someone can help me. I have an issue where I have developed a webpage with input required and have also created a database in MySQL and a table called Customer. When I fill in the info on the form and submit the information, the page comes back as successful but when I check the Database there is no entry.
However, when I go to MySQLAdmin and use the SQL query seperate from the webpage it works correctly.

Here is the code (with obvious bits omitted):-

<?php
//create short variable names
$username="web21-blackcat";
$password="blackcat";
$database="web21-blackcat";

$first=$_POST['firstname'];
$last=$_POST['lastname'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$city=$_POST['city'];
$postcode=$_POST['postcode'];
$county=$_POST['county'];
$phone=$_POST['telnumber'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];

mysql_connect(localhost,$username,$password);

@mysql_select_db($database) or die( "Unable to select database");

// insert INTO Customer (CustomerID, First_name,Last_name) VALUES ('1 ','clive','fred')

$query = "INSERT INTO Customer (first_name, last_name, address_1, address_2, city, postcode, county, tel_number, alternate_number, e_mail)
VALUES ('$first','$last','$address1','$address2','$city','$postcode','$county','$phone','$mobile','$email')";

?>
</body>

Could anyone help me solve what is wrong here.

Thanks
 
You need to execute your query, not just assign it to a variable:
Code:
  mysql_query ($query) or die ("Error running query: " . mysql_error());
 
I entered the following code and it worked

mysql_query($query);

Thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top