PHP not working with database
I have a problem with a PHP script I wrote. The problem is, it does not insert the information gathered into a database. Below is the code and a few more details.
Above is my code, the config.php file contains the database details and connection. Whenever I run this, the data never gets stored into the table "people". I have tried echoing all values and they are correct, I have echoed the actual query, and that comes up fine.
// Retrieve our data from POST
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$dateOB = $_POST['dateOB'];
$telNumber = $_POST['telNumber'];
$mobNumber = $_POST['mobNumber'];
$email = $_POST['email'];
$addressLine1 = $_POST['addressLine1'];
$postcode = $_POST['postcode'];
$docName = $_POST['docName'];
$docAddressLine1 = $_POST['docAddressLine1'];
$docPostcode = $_POST['docPostcode'];
$docContact = $_POST['docContact'];
// Insert into table
$query = "INSERT INTO people ( firstName, lastName, dateOB, telNumber, mobNumber, email, addressLine1, postcode, docName, docAddressLine1, docPostcode, docContact )
VALUES ( '$firstName' , '$lastName' , '$dateOB', '$telNumber' , '$mobNumber', '$email' , '$addressLine1', '$postcode' , '$docName', '$docAddressLine1' , '$docPostcode', '$docContact' );";
Please if anyone knows what's going on with this could you help out?
$result = mysql_query($query) or die($query . "<br><br>" . mysql_error());
to make sure the query is being processed without errors and, if not, what the error is.
Is the config.php actually opening the connection to the database? I do not see an "open database connection" code in your sample.
o . Q
_—__ "You live and you learn; or you don't live long." - Lazarus Long
MySQL table name always requires ``
In your case $query = "INSERT INTO `people` ...
I dont think your helping us to help you by leaving off your db connection script AND not having SQL errors displayed.
Always remember to throw an error message...
For ex: $result=mysql_query($query);
printf("cannot insert data");
This will let you know where the probem is !
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)