douchou8935 2013-07-17 22:40
浏览 53
已采纳

PHP + MySQL UPDATE查询(多列)不起作用

Ok, it's probably something simple that I'm overlooking, but I've combed through this so many times..!

Just a simple update via a PHP form, pulls in variables, builds query:

// Connect
$connect = mysql_connect('host','login','passwd');
if (!$connect) { $errors .= "Not connected : ".mysql_error(); }
$database = mysql_select_db('db', $connect);
if (!$database) { $errors .= "Could not get to that database: ".mysql_error(); }

// Update database table
$info = "UPDATE `gsa_officers` SET `term` = '2012-2013', `office` = 'President', `type` = 'Poop', `dept` = 'Visual Arts', `name` = 'Matthew W. Jarvis', `email` = 'president@gsa.ucsd.edu', `blurb` = 'Serves as Chair of both the GSA Executive Committee and Council, oversees the direction of the organization and ensures the execution of its responsibilities and commitments.', `picture` = 'http://gsa.ucsd.edu/sites/gsa.ucsd.edu/files/mat%20w%20jarvis.jpg' WHERE `id` = 1";
$query = mysqli_query($info);
if (!$query) { $errors .= "Bad query: ".mysql_error(); }
mysql_close($connect);

I get no errors, it only prints out: "Bad query: "

What am I missing/doing wrong? Any extra eyeballs are appreciated ^_^

  • 写回答

4条回答 默认 最新

  • douaoren4402 2013-07-17 22:46
    关注

    You're using mysql_connect() to connect to your database server and select the db. Then you use mysqli_query() to run the query, then mysql_error() to report the error. You can't mix these API's.

    You should use mysqli_* functions throughout, because the mysql_* functions are deprecated and will be removed from a future version of PHP.

    Example:

    // Connect
    $mysqli = new mysqli('host','login','passwd','db');
    if ($mysqli->connect_error) { $errors .= "Not connected : ".$mysqli->connect_error; }
    
    // Update database table
    $info = "UPDATE `gsa_officers` SET `term` = '2012-2013', `office` = 'President',
      `type` = 'Poop', `dept` = 'Visual Arts', `name` = 'Matthew W. Jarvis', 
      `email` = 'president@gsa.ucsd.edu', 
      `blurb` = 'Serves as Chair of both the GSA Executive Committee and Council, oversees the direction of the organization and ensures the execution of its responsibilities and commitments.',
      `picture` = 'http://gsa.ucsd.edu/sites/gsa.ucsd.edu/files/mat%20w%20jarvis.jpg' 
      WHERE `id` = 1";
    if (!$mysqli->query($info)) {
        $errors .= "Bad query: ".$mysqli->error;
    }
    $mysqli->close();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100