duanlan8763 2017-12-13 13:56
浏览 98

检查与MariaDB服务器版本对应的手册,以便在'WHERE id =' 附近使用正确的语法

I am new to php and cannot get this! I'm attempting to edit data on an edit page which will be stored through an update page onto mySQL.

<?php

include("secure/connect.php");


$newtitle = mysqli_real_escape_string($conn, ($_POST['title']));
$newinfo = mysqli_real_escape_string($conn,($_POST['info']));
$newprice = mysqli_real_escape_string($conn,($_POST['price']));
$newmenu_img = mysqli_real_escape_string($conn,($_POST['menu_img']));



$id = mysqli_real_escape_string($conn, ($_POST['rowid']));



//setup a SQL query
$query= "UPDATE  cocktails SET title='$newtitle', info='$newinfo',       price='$newprice', menu_img='$newmenu_img', WHERE id='$id'";

$result = mysqli_query($conn, $query) or die(mysqli_error($conn));


mysqli_close($conn);
?>    

I keep getting the error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE id=' Notice: Undefined variable: iddata in /var/www/vh' at line 1

  • 写回答

1条回答 默认 最新

  • dsljpwi494719 2017-12-13 14:00
    关注

    If your parameters are OK, removing comma(,) in this line

    UPDATE cocktails SET title='$newtitle', info='$newinfo', price='$newprice', menu_img='$newmenu_img', WHERE id='$id'
    

    before WHERE will do the job. Note that MariaDB will start code in error message from exactly the part that gives error - in your case it tries to parse WHERE part as continuation of list of parameters.

    Your code is also vulnerable to SQL code injection, so check out this answer before sending your code into production server.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度