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
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