dongzhang1864 2013-04-30 04:26
浏览 51

同时插入和更新

I have problem need to solve: I have 2 table in MySQL named Bata and Tranport.

For table Bata I have: id (PK, AI), phone, qty, price and grandtotal.

For table Tranport I have: id(PK, AI), phone, name, address and so on.

When the user clicks submit on Bata page the data will save into the database but the phone field will be left blank. When the user clicks submit on the Tranport page it will save data into database.

The question is how can I insert phone number from Tranport field into Bata phone field where the ID is the same? I have to do this because at the end user can review their order.

This is my code for transport

<?php
error_reporting(0);
ini_set('display_errors', false);


$tranport = $_POST['Tranport'];
$name = $_POST['billName'];
$phone = $_POST['billPhone'];
$company = $_POST['billCompany'];
$address = $_POST['billAdd1']; 
$negeri = $_POST['negeri']; 
$label = $_POST['mylabel']; 
$date = $_POST['inputField'];

$input = "INSERT INTO tranport (deliverTyper , name , phone , company ,
   address , state    ,   rate , date )";

$input .= " VALUES ('$tranport', '$name', '$phone', '$company', '$address',
    '$negeri',   '    $label', '$date') "; 

require_once("connection.php");
mysqli_query($conn,$input);


$query = "INSERT INTO bata (phone) VALUES ('$phone')"; 

mysqli_query($conn,$query);


if(mysqli_affected_rows($conn) <= 0)
{
print "Unable to create account.Please <a href='tranport.php'>click here</a>to try           gain.";
}
else
{
mysqli_close($conn);
header("Location:try.php?sebab=pengguna baru");
exit();
}

 mysqli_close($conn);


  ?>    
  • 写回答

2条回答 默认 最新

  • doushijia5684 2013-04-30 04:34
    关注

    You can get the ID generated for an AUTO_INCREMENT column of the last inserted entry using mysqli_insert_id($conn).


    Your code is vulnerable to injection. You should use properly parameterized queries with PDO / mysqli

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行