php - INSERT INTO TBL_payments undefined index 和父子外键

标签 php mysql

所以...这是我的代码:

$paymentType=$_POST["paymentType"]; // in the first two lines the $_POST data is copied into normal variables to make it easier to handle
$paymentMethod=$_POST["paymentMethod"];
$amount=$_POST["amount"];
$date=$_POST["date"];
$other=$_POST["other"];

$mysqlserver="localhost"; // in the next six lines the connection to the server is set up just like before and the database is chosen
$mysqlusername="jakedean";
$mysqlpassword="jakedean";
$link=mysql_connect($mysqlserver, $mysqlusername, $mysqlpassword) or die ("Error connecting to mysql server: ".mysql_error());

$dbname = 'jakedean';
mysql_select_db($dbname, $link) or die ("Error selecting specified database on mysql server: ".mysql_error());
            // the query which inserts the new data (from the variables) is set up and run

$addPaymentquery="INSERT INTO TBL_payments
    (paymentType, paymentMethod, amount, date, other)
    VALUES 
    ('$paymentType', '$paymentMethod', '$amount', '$date', '$other')";
mysql_query($addPaymentquery) or die("Query to insert new Payment into TBL_payments failed with this error: ".mysql_error());            


echo "<p class=\"thicker2\">You added a new Payment to Person ID:$personId! The Payment information added was:</p><p class=\"bold\">Payment Type:</p> <p class=\"thicker\">$paymentType</p> 
        <p class=\"bold\">Payment Method:</p> <p class=\"thicker\">$paymentMethod</p><p class=\"bold\">Amount Paid:</p> <p class=\"thicker\">$amount</p><p class=\"bold\">Date of Payment:</p> <p class=\"thicker\">$date</p>
        <p class=\"bold\">Additional Comments:</p> <p class=\"thicker\">$other</p>";

错误是未定义索引的组合和无法更新子行,因为我错误地关联了 sql 表...

错误信息:

Error message

我不知道这是否有帮助,但在我的数据库中,不同表中的一些字段具有相同的名称...

几天来我一直在尝试解决这个问题,但我无法弄清楚,这是我建立的第一个数据库!感谢任何回复!

最佳答案

undefined index 是因为您试图从数组中获取不存在的属性。 数据库错误(带有外键的错误)是因为您的 TBL_payments 必须与 TBL_people 相关 - 这意味着您必须设置 TBL_paymentspersonId 到您当前用户的id(登录的那个人或者这笔付款所属的那个人)。
更新:
而且,当然,不要使用已弃用的,正如评论中提到的那样!

关于php - INSERT INTO TBL_payments undefined index 和父子外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34087003/

相关文章:

php - 如何回显由 php 表单发送的变量

mysql - 向我解释一下last_insert_id(expr) 的作用

MySQL:在group_concat中使用concat时如何排序?

php - 带 SQL 的 WordPress 插件

php - 在php中取消设置编码数组后没有索引的json

php - 从对象数组变量调用静态方法

java - 将本地机器名放入 mySQL 表中

mysql - mysql中带有负数的模数运算符?

sql - MySQL 查询 : Select existing months from database and complete dynamically with the rest of year's month

php - 网站访问数据库设计