dsxgby126001 2014-06-04 23:05
浏览 19
已采纳

UPDATE查询无法运行php + mysql [关闭]

I am trying UPDATE to update my data with the following code. There might be problem in UPDATE query, but I checked syntax, modified it, but still its not working. Please Help.

FORM.php

<?php
require_once 'conn.php';
$var = $_GET['q'];
$varmod = 'tid="'.$var.'"';
$query = "SELECT * FROM temptable WHERE $varmod";
$result = mysql_query($query, $db) or die(mysql_error($db));
while ($row = mysql_fetch_assoc($result)) {
    $head = $row['thead'];
    $text = $row['ttext'];
    echo "<div id='main'>";
    echo "<form action='show.php?q=".$row['tid']."' method='POST'>";
    echo "<textarea name='thead' id='thead'>$head</textarea><br>";
    echo "<textarea name='ttext' >$text</textarea><br>";
    echo "<input type='submit' value='Update' /></form></div>";
}
?>

show.php

<?php
$title = $_POST['thead']; 
$text = $_POST['ttext'];
$date = date("Y-m-d");  
require_once 'conn.php';

if(isset($title)){  
    if (isset($_GET['q'])) {
        $temp = $_GET['q'];
        $query = "UPDATE temptable SET thead=\"$title\" AND ttext=\"$text\" WHERE tid=\"$temp\"";
    }
    else{
    $query= "INSERT INTO temptable
    (thead, ttext, tdate) 
    VALUES (\"$title\", \"$text\", \"$date\")";
    }
    $result = mysql_query($query, $db) or die(mysql_error($db));
}

Well INSERT query is working well.

  • 写回答

2条回答 默认 最新

  • dongshanxun6479 2014-06-04 23:14
    关注

    Mysql Update queries must be like this ;

    "UPDATE targettable SET column='$var1', column2='$var2' WHERE targetcolumn='$target'";
    

    Try this it will help you..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

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