PHP 查询插入 '0' 值到 mysql 表

标签 php mysql

enter image description here我的 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);
?>

插入后我收到,member_id = 0; question_id = 0 ;答案 = NULL

最佳答案

如果你用的是mysql,应该是:

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

但尝试使用 mysqli,因为 mysql 已被弃用。

关于PHP 查询插入 '0' 值到 mysql 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20969278/

相关文章:

PHP 表单输入时不将数据发送到 MySQL

mysql - DataAdapter 缺少记录

php - 为什么在 PHP 框架中使用依赖注入(inject)组件

PHP 包含(JavaScript 和 CSS 文件)

php - 为什么 Laravel 的 App::getLocale() 方法不一致?

php - mysql查询哪个最好

php - Ajax中POST返回值获取类名

java - 首次登录 : HTTP Status 500 - Request processing failed; nested exception is org. springframework.transaction.CannotCreateTransactionException

PHP 不会 POST 到 MySQL 数据库。

mysql - Rails 开发 - 无法连接到 'localhost' (10061) 上的 MySQL 服务器