我想将项目代码从url传输到数据库

时间:2017-08-29 19:28:31

标签: php mysql

我想从url获取itemcode并插入数据库。但是没有插入商品代码。

<?php

$item_code = $_GET['item_code'];

if (isset($_POST['submit'])) {
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $address = $_POST['address'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $pincode = $_POST['pincode'];
    $item_number = $_POST['item_number'];
    $date = $_POST['date'];
    $call_time = $_POST['call_time'];
    $comment = $_POST['comment'];
    $datetime = date_default_timezone_set('Asia/Kolkata');
    $datetime = date("l jS \of F Y h:i:s A");



    $insert_query = "insert into rlu_order(item_code,first_name,last_name,email,phone,address,city,state,pincode,item_number,date,call_time,comment,datetime) values('$item_code','$first_name','$last_name','$email','$phone','$address','$city','$state','$pincode','$item_number','$date','$call_time','$comment','$datetime')";


    if (mysqli_query($con, $insert_query)) {

        echo "<script>alert('Thank You for your Project order we will contact you shortly')</script>";
        echo "<script>window.open('index.php','_self')</script>";
    }
}
?>

我传递了像'order.php?item_code=$item_code'

这样的网址

2 个答案:

答案 0 :(得分:1)

在继续下一步之前始终进行错误检查

*在*** SUBMIT 被解雇后检查$ item_code

if (isset($_POST['submit'])) {

$item_code = ( !empty $_REQUEST['item_code'] ) ? $_REQUEST['item_code'] : '';

if( empty($item_code) ) 
{
   //No need to continue if there's no item_code
   die("We need item_code");
}

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$pincode = $_POST['pincode'];
$item_number = $_POST['item_number'];
$date = $_POST['date'];
$call_time = $_POST['call_time'];
$comment = $_POST['comment'];
$datetime = date_default_timezone_set('Asia/Kolkata');
$datetime = date("l jS \of F Y h:i:s A");



$insert_query = "insert into rlu_order(item_code,first_name,last_name,email,phone,address,city,state,pincode,item_number,date,call_time,comment,datetime) values('$item_code','$first_name','$last_name','$email','$phone','$address','$city','$state','$pincode','$item_number','$date','$call_time','$comment','$datetime')";


if (mysqli_query($con, $insert_query)) {

    echo "<script>alert('Thank You for your Project order we will contact 

you shortly')</script>";
        echo "<script>window.open('index.php','_self')</script>";
    }
}

答案 1 :(得分:0)

好像你正在使用GET和POST

$_GET[''] $_POST['']

我使用REQUEST获取所有值

$_REQUEST['']