繁体   English   中英

无法将行插入数据库

[英]Can't insert the row into database

为什么我无法插入数据库? 我的代码出了什么问题?

<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);
}

不推荐使用mysql_connect ,而是使用mysqli

我看到你基本上想要插入7个元素,但只宣称6个......

INSERT INTO orders(name, contact, address, spoon, tanabe, fujitsubo) <-- @@!!SIX!!@@ VALUES ('$name','$contact','$address','$spoon','$tanabe','$fujitsubo','$total') <-- @@!!SEVEN!!@@

你的提交按钮即。 HTML输入元素<input type="submit" ... ...>必须具有要包含在$_POST数组中的"name"属性。

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

没有它if(isset($_POST['submit']))永远不会解析为true。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM