MySQL — PHP вставка не работает

Я пытаюсь вставить данные в MySQL, но не работает,
нет ошибок, которые отображаются ниже, это php скрипт

    $mysqli = new mysqli('localhost','root','','realestate');

if($mysqli->connect_error){
printf("can not connect database %s\n",$mysqli->connect_error);
exit();
}

if (isset($_POST['submit'])){

$a_name=$_POST['a_name'];
$a_number=$_POST['a_number'];
$email=$_POST['email'];
$password=$_POST['password'];$target_dir="uploads/";
$target_file=$target_dir . basename($_FILES["a_image"]["name"]);
$temp_file=$_FILES["a_image"]["name"];

move_uploaded_file($_FILES["a_image"]["tmp_name"], $target_file );

$query="INSERT INTO agent (a_name,a_number,email,password,a_image)
VALUES ('$a_name',$a_number,'$email','$password','$temp_file')";
$insert = $mysqli->query($query);

0

Решение

error_reporting(E_ALL);//show all errors

$mysqli = new mysqli('localhost','root','','realestate');

if($mysqli->connect_error){
printf("can not connect database %s\n",$mysqli->connect_error);
exit();
}

if (isset($_POST['submit'])){
//make sure $_POST is not null
var_dump('Posted variables are '. $_POST.' and files are '. $_FILES);//Comment out after debugging
$a_name=$_POST['a_name'];
$a_number=$_POST['a_number'];
$email=$_POST['email'];
$password=$_POST['password'];$target_dir="uploads/";
$target_file=$target_dir . basename($_FILES["a_image"]["name"]);
$temp_file=$_FILES["a_image"]["name"];//make sure this is not null

move_uploaded_file($_FILES["a_image"]["tmp_name"], $target_file );

$query="INSERT INTO `agent` (`a_name`,`a_number`,`email`,`password`,`a_image`)
VALUES ('$a_name','$a_number','$email','$password','$temp_file')";

if($mysqli->query($query) == true){//check for success
echo 'Success';//display message of success
} else {
echo $mysqli->error;//display error message
}

//The above code is prone to SQL injection. Below is using prepared statements:
// prepare and bind
$stmt = $mysqli->prepare("INSERT INTO `agent`(`a_name`,`a_number`,`email`,`password`,`a_image`) VALUES (?, ?, ?,?,?)");
$stmt->bind_param("sssss", $a_name, $a_number, $email, $password, $temp_file);

$stmt->execute();
0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]