简体   繁体   English

PHP查询在MySQL表中插入“ 0”值

[英]PHP query insert '0' value to mysql table

在此处输入图片说明 My php file inserts into table row 0 values, I cannot find solution for that. 我的php文件将插入表第0行的值,但我找不到解决方案。

<?php
$selected_button = $_POST['a'];

$conn = mysql_connect('localhost','root','');
if(!$conn )
{
  die('Could not connect: ' . mysql_error());
}
  $sql = "INSERT INTO answers (member_id, question_id, answer) VALUES (1, 2,'$selected_button')";

mysql_select_db('ipad',$conn);
$result = mysql_query($sql, $conn);
if(!$result)
{
    return false;
}
return true;


mysql_close($conn);
?>

after insert i receive, member_id = 0 ; 我插入后收到,member_id = 0; question_id = 0 ; question_id = 0; answer = NULL 答案= NULL

If you are using mysql, it should be: 如果使用的是mysql,则应为:

$result = mysql_query($sql, $conn);

But try to use mysqli as mysql is deprecated. 但是,由于不建议使用mysql,请尝试使用mysqli。

There is no query running right now. 目前没有任何查询在运行。 query is first paramter in mysql_query. 查询是mysql_query中的第一个参数。 $result = mysql_query($sql,$conn);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM