duanli9930 2016-10-06 04:30
浏览 47

PHP MySql更新查询不起作用,说: - 未定义索引[重复]

This question already has an answer here:

I have follow the tutorial of it where i want to update my database using two php files.

<?php
while($row = mysqli_fetch_array($records))
{
    echo "<tr><form action =update.php method=post>";
    echo "<td><input type=text name=Cname value='".$row['CustomerName']."'></td>";
    echo "<td><input type=number name=size min=1 value='".$row['TableSize']."'></td>";
    echo "<td><input type=date name=Adate value='".$row['DateA']."'></td>";
    echo "<td><input type=time name=Atime value='".$row['TimeA']."'></td>";
    echo "<td><input type=tel name=phonenumber value='".$row['PhoneNumber']."'></td>";
    echo "<input type=hidden name=id value='".$row['TableID']."'>";
    echo "<td><input type=submit>";
    echo"</form></tr>";
}
?>

this is what i use for the first php file as for the update.php:

<?php

$con = mysqli_connect('127.0.0.1','root','');

mysqli_select_db($con,'restaurant');

$sql = "UPDATE addtable SET CustomerName='$_POST[Cname]', TableSize='$_POST[size]', DateA='$_POST[Adate]',TimeA='$_POST[Atime]',PhoneNumber='$_POST[phonenumber]', WHERE TableID=$_POST[id]";

if(mysqli_query($con,$sql))
    header("refresh:1; url=AssignBooking.php");
else
    echo "Not Update";

?>

but the $sql line just doesn't work as it says that

Undefined index: Cname and other indexes too.

</div>
  • 写回答

2条回答 默认 最新

  • douwen5951 2016-10-06 04:36
    关注

    According to your code put the name attributes value ' single quote.

    <?php
    while($row = mysqli_fetch_array($records))
    {
        echo "<tr><form action =update.php method=post>";
        echo "<td><input type=text name='Cname' value='".$row['CustomerName']."'></td>";
        echo "<td><input type=number name='size' min=1 value='".$row['TableSize']."'></td>";
        echo "<td><input type=date name='Adate' value='".$row['DateA']."'></td>";
        echo "<td><input type=time name='Atime' value='".$row['TimeA']."'></td>";
        echo "<td><input type=tel name='phonenumber' value='".$row['PhoneNumber']."'></td>";
        echo "<input type=hidden name="id" value='".$row['TableID']."'>";
        echo "<td><input type=submit>";
        echo"</form></tr>";
    }
    ?>
    

    Put quotes accordingly

    UPDATE addtable SET CustomerName='".$_POST['Cname']."',TableSize='".$_POST['size']."',    DateA='".$_POST['Adate']."',TimeA='".$_POST['Atime']."',PhoneNumber='".$_POST['phonenumber']."' WHERE TableID=$_POST['id'];
    
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源