duanmeng1950 2016-05-23 22:05
浏览 113

MySQL INSERT语句未执行[重复]

This question already has an answer here:

I cannot for the love of god figure out why this statement is not executing. When I limit it to

mysql_query("INSERT INTO my_pets() VALUES ()", $con);

it fires just fine, creating an empty row (NULL in every cell), but as soon as I give it columns and values, it refuses. See below.

Can someone point out a mistake or any other reason this (seemingly) correct code isn't firing when columns and values are specified?

Premises:

  • $h, $un, $pw, and $db are all fine, as I have copied it from documents that work as we speak.
  • There are no typos or mistakes in upper/lower case characters of column names and such.

The code:

<?php

session_start();

$h="...";      // Host name
$un="...";     // Mysql username
$pw="...";     // Mysql password
$db="...";     // Database name

$con = mysql_connect("$h", "$un", "$pw")or die("cannot connect"); 
mysql_select_db("$db")or die("cannot select DB");

$name = "Pip";
$gender = "F";
$species = "Dog";

mysql_query("INSERT INTO my_pets (name, gender, species) VALUES ('$name', '$gender', '$species')", $con);

mysql_close($con);

?>
</div>
  • 写回答

1条回答 默认 最新

  • dongzhanlu8890 2016-05-23 22:23
    关注

    Obtained from PHP Documentation, If you're using PHP 7.0.0, mysql_query will no longer work:

    Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: mysqli_query() PDO::query()

    Good / Important note from someone who cares: This function should not be used for any future code and should be replaced for existing code, so I would recommend you change to PDO.

    评论

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?