dpw50696 2018-03-30 17:41
浏览 51

为什么SQL代码没有运行?

I'm making a website which asks input from user using this html code:

<form>
     <input type="text" name="question1input1" />
</form>

But when I ran it on the second page using this php to upload into database:

$que1in1 = $_POST['question1input1'];

if ($que1in1 == "x-coordinate") {

    $answer = '<text style=\'color: yellowgreen;\'>x-coordinate</text>';

    $score = 1;

    $snumber = $_SESSION['DcYnuJmQKJkkBPEY'];

    $sql2 = "UPDATE `chapter 9 pre-test` SET `score1` = '$score' WHERE `chapter 9 pre-test`.`snumber`='$snumber';";

    $sql3 = "UPDATE `chapter 9 pre-test` SET `1` = '".$answer."' WHERE `chapter 9 pre-test`.`snumber`='$snumber';";

    if ($con->query($sql2) == TRUE) {}

    else {echo "something happened... ".$score;}

    if ($con->query($sql3) == TRUE) {}

    else {echo "something happened... ".$answer;}

}

$sql2 returning as success, but $sql3 returning as an error.

  • 写回答

1条回答 默认 最新

  • duanpo6079 2018-03-30 17:50
    关注

    try changing your html code in $answer to use double quote since you are using single quote as a string delimiter in your update query

    $answer = '<text style="color: yellowgreen;">x-coordinate</text>';
    

    and if this is the cause of this problem, I suggest you use PDO and prepared statements instead. this will not happen if you are using prepared statements

    评论

报告相同问题?

悬赏问题

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