dragon87836215
dragon87836215
2015-03-07 00:32

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 dongmijgnnq0118 6年前

    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"];
    
    点赞 评论 复制链接分享
  • dongyiluan1718 dongyiluan1718 6年前

    you should replace $name = $_POST['NAME'] with $name = $_GET['NAME'] or $name = $_REQUEST['NAME'] where $_REQUEST is default but don't use $_REQUEST

    点赞 评论 复制链接分享

为你推荐