dqwh2717 2014-02-20 16:35
浏览 14
已采纳

无法将行插入数据库

Why I can't insert into the database? What's wrong with my code?

<form action = "" method ="POST">                                           
    <center>                                               
        <b>Name</b><br><br>Quantity: <input type = "text" name = "name" style = "width: 155px"><br><br>                                         
        <b>Contact Number</b><br><br>Quantity: <input type = "text" name = "contact" style = "width: 155px" ><br><br>                                           
        <b>Address</b><br><br>Quantity: <input type = "text" name = "address" style = "width: 155px"><br><br>
        <b>Spoon N1(₱25000.00)</b><br><br>Quantity: <input type = "text" name = "Squantity" style = "width: 155px" value = "0"><br><br>
        <b>Tanabe Hypermedallion(₱15000.00)</b><br><br>Quantity: <input type = "text" name = "Tquantity" style = "width: 155px" value = "0"><br><br>
        <b>Fujitsubo Legalis R(₱15000.00)</b><br><br>Quantity: <input type = "text" name = "Fquantity" style = "width: 155px" value = "0"><br><br>
        <b>GCash Transaction No.</b><br>:      
        <input type = "text" name = "quantity" style = "width: 155px"><br><br>
        <input type = "submit" value = "submit">
    </center>
</form>

<?php
if(isset($_POST['submit']))
{
    $name = empty($_POST['name']) ? die ("Input a name"): mysql_escape_string($_POST['name']);
    $contact = empty($_POST['contact']) ? die ("Input a contact number"): mysql_escape_string($_POST['contact']);
    $address = empty($_POST['address']) ? die ("Input a address"): mysql_escape_string($_POST['address']);
    $spoon = empty($_POST['Squantity']) ? die ("Input a value"): mysql_escape_string($_POST['Squantity']);
    $tanabe = empty($_POST['Tquantity']) ? die ("Input a value"): mysql_escape_string($_POST['Tquantity']);
    $fujitsubo =empty($_POST['Fquantity']) ? die ("Input a value"): mysql_escape_string($_POST['Fquantity']);
    $total = ($spoon * 25000) + ($tanabe * 15000) + ($fujitsubo * 15000);
    $host = "localhost";
    $user = "root";
    $pass = "password";
    $db = "eurocare";
    $con = mysql_connect($host,$user,$pass,$db) or die ("Unable to connect");
    $conn = mysql_select_db($db,$con);
    $query = "INSERT INTO orders(name, contact, address, spoon, tanabe, fujitsubo) VALUES ('$name','$contact','$address','$spoon','$tanabe','$fujitsubo','$total')";
    $result = mysql_query($query,$con) or die("Error in Query : $query ." .mysql_error());
    exit; 
    mysql_close($con);
}
  • 写回答

2条回答 默认 最新

  • dongtun1872 2014-02-20 16:43
    关注

    Your submit button ie. HTML input element <input type="submit" ... ...> has to have the "name" attribute to be included in the $_POST array.

    <input type = "submit" value = "submit" name="submit">
    

    Without it if(isset($_POST['submit'])) would never resolve to true.

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

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作