dongzhangji4824 2013-09-10 22:28
浏览 18
已采纳

PHP在表字段中发布$ _GET变量

I'm having some problems trying to post $_GET variables into a table.

Here is my script:

include 'connect.php';

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

$_GET['list']; //these are variables passed through from another page and I want these to post in the same table this page is suppose to post in.
$_GET['list_id'];


$Cname = $_POST['client_name'];
$Cnumber = $_POST['client_number'];
$listid = $_POST['list_id'];
$listname = $_POST['list'];


if(!empty($Cname) && !empty($Cnumber)){

    $query = "INSERT INTO clients (id, client_name, client_number, list_name, date_registered, list_id) VALUES ('$userid','$Cname', '$Cnumber', '$listname', now(), '$listid')";

    mysql_query($query);

echo '<br />
 <br />
        You successfully added a new clients to your list <a href="http://somewebsite.com/clients.php">View Update</a>';


    mysql_close();
    } 

    else {

        echo '<script type="text/javascript">alert("Both fields are required");</script>';
        }

Whenever I run the script everything else but the listname and list_id is posted in the database table. I tried assigning the get variables to new variable such as

$listNAME = $_GET['id'];

but even with that I still end up with empty fields in my table

I even tried to use the $_GET variable in the mysql INSERT query and still no luck

Can anyone help me out and give me some advice as to what I can do to solve the empty fields when the script runs.

<form action="addclient.php" method="POST">

Name of Client: <input type="text" name="client_name">

Client's Number: <input type="text" name="client_number" placeholder="1-876-xxx-xxx">

 <input type="submit" >


</form>
  • 写回答

2条回答 默认 最新

  • dpp34603 2013-09-10 23:58
    关注

    I say it only to notice .

    Please use PDO or mysqli


    if you are calling your addclient.php like

    http://localhost/addclient.php?list_id=100&list=mylistname
    

    than you must catch both variables in addclient.php

    if (isset($_GET['list_id'])) {
    
     $listid = $_GET['list_id'];
     $listname = $_GET['list'];
    
    }
    

    and your form

    <form action="addclient.php" method="POST">
        <input type="hidden" name="list_id" value="$listid">
        <input type="hidden" name="list" value="$listname">
    Name of Client: <input type="text" name="client_name">
    Client's Number: <input type="text" name="client_number" placeholder="1-876-xxx-xxx">
     <input type="submit" >
    </form>
    

    and after submit

    if(isset($_POST['client_name'])) {
    
    $Cname = $_POST['client_name'];
    $Cnumber = $_POST['client_number'];
    $listid = $_POST['list_id'];
    $listname = $_POST['list'];
    ....
    }
    

    and in your insert

    VALUES ('$userid','$Cname', '$Cnumber', '$listname', now(), '$listid')
    

    $listid without quotes it's a int(11) .

    VALUES ('$userid','$Cname', '$Cnumber', '$listname', now(), $listid)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题