加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 两个错误 – 在自定义管理面板上标记按钮附带的项目

发布时间:2020-12-13 16:54:38 所属栏目:PHP教程 来源:网络整理
导读:我用它自己的数据库创建了一个管理面板. 在preorder.php页面上连接到另一个(它自己的)数据库,在用户填写表单和条带处理订单后,我检查收费是否像这样支付; if ($charge-paid == true) { $amountReadable = $amount / 100; // to add in decimal points echo '
我用它自己的数据库创建了一个管理面板.

在preorder.php页面上连接到另一个(它自己的)数据库,在用户填写表单和条带处理订单后,我检查收费是否像这样支付;

if ($charge->paid == true) {
    $amountReadable = $amount / 100; // to add in decimal points
    echo '<div class="alert alert-success">Your card was successfully billed for $'.$amountReadable.'</div>';
    $status = "paid";

然后我连接到主数据库和管理数据库(它们都有’orders’表)并插入此查询:

$connect = mysql_connect("localhost",DB_USER,DB_PASS);
 if (!$connect){
 die('Could not connect: ' . mysql_error());
 }

 mysql_select_db(DB_NAME,$connect);

 $query = "INSERT INTO 'DB_NAME'.`orders` (`email`,`name`,`qty`,`product`,`amount`,`stripe_customer_id`,`stripe_charge_id`,`address1`,`address2`,`city`,`state`,`zip`,`timestamp`,`status`) VALUES ('$email','$cardName','$qty','$product','$amountReadable','$customer->id','$charge->id','$cardAddress1','$cardAddress2','$cardCity','$cardState','$cardZipcode',CURRENT_TIMESTAMP`,$status);";

 mysql_query($query);

 if (mysql_errno()) {
 $error = "MySQL error ".mysql_errno().": ".mysql_error()."n<br>When executing:<br>n$queryn<br>";
 exit;   
 }
 mysql_close($connect);

 //insert into db for admin
 $connect = mysql_connect("--------","------","-------");
 if (!$connect){
 die('Could not connect: ' . mysql_error());
 }

 mysql_select_db(database2,$connect);

 $query = "INSERT INTO 'database2'.`orders` (`email`,CURRENT_TIMESTAMP,$status);";

然后在具有自己的数据库(上面的数据库2)的管理面板上,(orders.php)我将这些数据拉入这样的引导表中:

编辑1#:我将管理面板中的orders.php更改为:

$result = mysqli_query($con,"SELECT * FROM orders");

echo "<table border='1' data-toggle='table'>
<tr>
<th>id</th>
<th>email</th>
<th>name</th>
<th>qty</th>
<th>product</th>
<th>amount</th>
<th>address1</th>
<th>address2</th>
<th>city</th>
<th>state</th>
<th>zip</th>
<th>status</th>
</tr>";

 while($row = mysqli_fetch_array($result))
 {
 echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['qty'] . "</td>";
  echo "<td>" . $row['product'] . "</td>";
  echo "<td>" . $row['amount'] . "</td>";
  echo "<td>" . $row['address1'] . "</td>";
  echo "<td>" . $row['address2'] . "</td>";
  echo "<td>" . $row['city'] . "</td>";
  echo "<td>" . $row['state'] . "</td>";
  echo "<td>" . $row['zip'] . "</td>";
  echo "<td>" . $row['status']. "</td>";
  echo "<td><form action='markshipped.php' method='POST'><input type='hidden' name='status' value='".$row["id"]."'/><input type='submit' name='submit-btn' value='Mark Item Shipped' /><form></td>";
  echo "</tr>";
 }
echo "</table>";

那么我的markshipped.php是:

<?php
$con=mysqli_connect("----","----","----");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con,"UPDATE orders SET status='shipped' WHERE id=$id");

mysqli_close($con);
?>

我仍然不太熟悉php / mysql,不幸的是我无法测试它,直到有人购买任何东西,因为条纹测试模式没有一张卡片无法通过表格…

所以我的问题主要是:

我有两个错误说:

1.未定义变量:第9行/admin/orders/markshipped.php中的id

– 这是这一行:mysqli_query($con,“UPDATE命令SET status =’shipping’WHERE id = $id”);

2.未定义的索引:第88行的/admin/orders/orders.php中的状态

– 这是:echo“< td>” . $行[“状态”. “< / TD>” 中;

显然我设置$status =“付费”;错误和/或错误的地方.

如何正确设置这些项目以便能够将项目标记为“已付款”,然后在单击每行上的“标记项目已发送”按钮后将其更改为“已发货”?你能发现我的代码中的任何其他错误吗?

非常感谢你的时间!

解决方法

您需要使用以下命令获取$_POST [‘status’]:

$id = $_POST['status'];

在markshipped.php中运行您的查询.我会将隐藏输入字段的名称更改为“id”并获取$_POST [‘id’],因为您要提交ID.

你有一个`在这一行(第一次插入查询):

CURRENT_TIMESTAMP`<<<<here,$status

并且需要删除此/更好地将列设置为mysql中的on_update_current_timestamp

$status需要在”,我想$id是一个整数,所以你可以不用”.

你正在混合mysql_和mysqli_,我强烈建议你重写mysqli_中的整个代码,特别是你的插入语句,你真的应该使用预处理语句和mysqli_. mysql_是折旧且不安全的.您可以接受sql注入

为什么你设置id = NULL?这应该是一个自动增量字段,您不应该在查询中将其设置为null.

如果您将对象数据放入数据库,我将使用“{$customer-> id}”或设置

$customer_id = $customer->id;

在查询之前,可以更轻松地检查您的查询

您无需指定

INSERT INTO **’database2’**.订单

database2,db已被选中 – 再次:使用mysqli_和prepared语句代替!

例:

$customer_id = $customer->id;
$charge_id = $charge->id;
$stmt = $sql->prepare("INSERT INTO `orders` (`email`,`status`) VALUES (?,?,?)");
$stmt->bind_param('ssissssssssss',$email,$cardName,$qty,$product,$amountReadable,$customer_id,$charge_id,$cardAddress1,$cardAddress2,$cardCity,$cardState,$cardZipcode,$status);

$stmt->execute();

如果你这样做,你需要为mysq_设置mysqli的连接

第1块:

<?php


if ($charge->paid == true) {
    $amountReadable = $amount / 100; // to add in decimal points
    echo '<div class="alert alert-success">Your card was successfully billed for $' . $amountReadable . '</div>';
    $status = "paid";
}

第2块:

<?php
$connect = new mysqli("localhost",DB_PASS,DB_NAME);
$customer_id = $customer->id;
$charge_id = $charge->id;
$stmt = $connect->prepare("INSERT INTO orders (`email`,$customer->id,$charge->id,$status);
$stmt->execute();




$connect->close();

//insert into db for admin
$connect = new mysqli("--------","-------","--------");

$customer_id = $customer->id;
$charge_id = $charge->id;
$stmt = $connect->prepare("INSERT INTO `orders` (`email`,$status);
$stmt->execute();

第3块:

$con = new mysqli("--------","--------");
$query = "SELECT * FROM orders";
if ($result = $con->query($query))
{

echo "<table border='1' data-toggle='table'>
<tr>
<th>id</th>
<th>email</th>
<th>name</th>
<th>qty</th>
<th>product</th>
<th>amount</th>
<th>address1</th>
<th>address2</th>
<th>city</th>
<th>state</th>
<th>zip</th>
<th>status</th>
</tr>";

while($row = $result->fetch_assoc()) {
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['email'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['qty'] . "</td>";
    echo "<td>" . $row['product'] . "</td>";
    echo "<td>" . $row['amount'] . "</td>";
    echo "<td>" . $row['address1'] . "</td>";
    echo "<td>" . $row['address2'] . "</td>";
    echo "<td>" . $row['city'] . "</td>";
    echo "<td>" . $row['state'] . "</td>";
    echo "<td>" . $row['zip'] . "</td>";
    echo "<td>" . $row['status'] . "</td>";
    echo "<td><form action='markshipped.php' method='POST'><input type='hidden' name='id' value='" . $row["id"] . "'/><input type='submit' name='submit-btn' value='Mark Item Shipped' /></form></td>";
    echo "</tr>";
}}
echo "</table>";

第4块:

$con= new mysqli("----","----");
// Check connection
$id = $_POST['id'];
    $stmt = $con->prepare("UPDATE orders SET status = 'shipped' WHERE id = ?");
    $stmt->bind_param('i',$id);
    $stmt->execute();
$con->close();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读