Hello everyone, I am doing an assingment for my uni and i am frustrated, since i cant make my php script to communicate with my database and put the information inside.
Bellow is my code:
<?php
$dbserver="localhost";
$dbusername="hsp1amt";
$dbuserpassword="1503020";
$dbname="hsp1amt_db";
$mysqli_obj=new mysqli($dbserver,$dbusername,$dbuserpassword,$dbname) or die ("Cannot connect to database");
$firstname= $_POST["firstname"]; //Extract info from the field named firstname and assign it to PHP variable
$lastname= $_POST["lastname"];
$address= $_POST["address"];
$email= $_POST["email"];
$dateofbirth= $_POST["dateofbirth"];
$nhsnumber= $_POST["nhsnumber"];
$assessmentdate= $_POST["assessmentdate"];
$weight= $_POST["weight"];
$height= $_POST["height"];
$sex= $_POST["sex"];
$smoker= $_POST["smoker"];
// Calculate the BMI value
$bmi = $weight / ($height*$height);
$sqlstatement="INSERT INTO assingment2 VALUES
(‘$firstname’,’$lastname’,’$address’,’$email’,’$dateofbirth’,’$nhsnumber’, ‘$assessmentdate’,’$weight’,’$height’, ‘$bmi’, ‘$sex’, ‘$smoker’ )";
$result = $mysqli_obj->query($sqlstatement) or die ("Couldn’t issue SQL INSERT query");
$mysqli_obj->close();
print "<br/>Thank you for submitting your form.";
?>
I have checked your query and the issue which you are getting is in the Syntax of query which you writing. In your query you are not mentioning the database fields name. You can take example from the below query:
$sqlstatement="INSERT INTO assingment2 (firstname, lastname, address, email, dateofbirth, nhsnumber, assessmentdate, weight, height, bmi, sex, smoker) VALUES
(’$firstname’,’$lastname’,’$address’,’$email’,’$dateofbirth’,’$nhsnumber’, ’$assessmentdate’,’$weight’,’$height’, ’$bmi’, ’$sex’, ’$smoker’ )";
I tried your way, it still gives me: Couldn’t issue SQL INSERT query
Then, you need to confirm the table fields which you have created in your database.
I have uploaded a picture for you of my database:
http://www.filedropper.com/database_3
Please I did it all day, everything I think is exactly the same and I dont get, why they are not communicating with each other
What is the php and mysql version you are using?
Also send me the screenshot of the error which you are getting.