This is my code:
<?php
$link = mysqli_connect("localhost", "user", "pw", "dbname");
//if( mysqli_connect_error()){
//echo "There was an error";
//}else{
//echo "Database connection successful"; }
// Check connection
if ($link->connect_error) {
die("Connection failed: " . $link->connect_error);
}
//The problem started after I added the following code
mysqli_query($link,"INSERT INTO posts (name, email, phonenumber, billAddress, billCity, billProvince, billPC)
VALUES ('$_POST[name]', '$_POST[email]', '$_POST[phonenumber]', '$_POST[billAddress]', '$_POST[billCity]', '$_POST[billProvince]', '$_POST[billPC]')";
?>
Before adding the last bit of code, it was working fine. After I added the code and hit refresh, I received http 500 error. It also said my webpage isn't working and my webpage is currently unable to handle the request.
I am not sure if it is my coding problem or something else. Please help and thank you in advance.
You have missed out a closing bracket:
mysqli_query($link,"INSERT INTO posts (name, email, phonenumber, billAddress, billCity, billProvince, billPC))
VALUES ('$_POST[name]', '$_POST[email]', '$_POST[phonenumber]', '$_POST[billAddress]', '$_POST[billCity]', '$_POST[billProvince]', '$_POST[billPC]')";
Also, remember to escape the string using mysqli_real_escape_string()
to prevent MySQL Injection.
Tip: You should turn on Error Reporting by adding this code to the top of your PHP files which will assist you in finding errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.