Answer the question
In order to leave comments, you need to log in
Why is PHP not writing to the database?
Hello! PHP is zero. I asked the familiar simplest example to throw in, pass the test ....
I sent the soap, I did the reading from the table, but the insertion into the table already hurt my forehead .... well, no way, tell me what's wrong:
<?php
$servername = "localhost";
$username = "23423434";
$password = "4234234234";
$dbname = "study_db";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Ошибка соединения с БД: " . $conn->connect_error);
}
//данные
/*$user_name = mysql_real_escape_string($user_name);
$user_email = mysql_real_escape_string($user_email);
$subject = mysql_real_escape_string($subject);
$message = mysql_real_escape_string($message);*/
/*$sql = "INSERT INTO Main (from_name, from_email, subject, message)
VALUES ('$user_name', '$user_email', '$subject', '$message')";*/
$sql = "INSERT INTO Main (from_name, from_email, subject, message)
VALUES ('John', 'Doe', 'johnexample.com', 'sdsd')";
if ($conn->query($sql) === TRUE) {
echo "Новая запись создана успешно";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
//Ajax post data to server
$.post('test.php', post_data, function(response){
if(response.type == 'error'){ //load json data from server and output message
output = '<div class="error">Ошибка</div>';
}else{
output = '<div class="success">Успешно</div>';
//reset values in all input fields
$("#contact_form input[required=true], #contact_form textarea[required=true]").val('');
$("#contact_form #contact_body").slideUp(); //hide form after success
}
$("#contact_form #contact_results").hide().html(output).slideDown();
}, 'json');
mysql_query("SET NAMES 'utf8';");
mysql_query("SET CHARACTER SET 'utf8';");
mysql_query("SET SESSION collation_connection = 'utf8_general_ci';");
Answer the question
In order to leave comments, you need to log in
you need variables from whom, message, subject, insert into the plate ...
pass exam...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question