dragon87836215 2015-03-07 00:32
浏览 25
已采纳

PHP / MySQL - 不发布到数据库

This PHP script is meant to post a users name into a database but it doesnt seem to work properly. The project in unity wont post it correctly and going straight to IP

ADDRESS/addUser.php?NAME=Ryan 

also doesnt work. It auto increments the ID as it should but the name field is always blank.

<?php
         //Connect
        $sql_connect = mysql_connect("IP", "USER", "PASS") or die ("no DB Connection");

        //Select Database
        mysql_select_db("practiceCrim") or die ("DB not found");

        //Post Info To Var
        $name = $_POST['NAME'];

        //Query
         $query = "INSERT INTO Users (Name)
         VALUES ('$name')";

         //Run The Query, Get Result
        $result = mysql_query( $query, $sql_connect );

         //Not Really Needed For You
         if(!$result)
         {
            die('Error: ' . mysql_error());
         }

        //Close The Connection
        mysql_close($sql_connect);
    ?>
  • 写回答

2条回答 默认 最新

  • dongmijgnnq0118 2015-03-07 00:44
    关注

    It look like you're getting the name field from the PHP $_POST variable. But your example passes the name field as a GET parameter.

    To fix this, you have two options. If you only want to allow name to be passed as a GET parameter, then you need to do this:

    $name = $_GET["NAME"];
    

    If you want to allow name to be passed as either a GET or a POST parameter, you can do this:

    $name = $_REQUEST["NAME"];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料