dougou6213 2012-03-14 05:19
浏览 12
已采纳

将值插入DB不起作用?

Hey guys i had a similar problem before but i scraped that idea. Now basically my system allows my users to input there data into the fields and if they submit it the information will go to the database. Now for some reason the data does not go and i am presented with the echo that i stored in my else statement which was " echo" try again later" ;"

Now i have gone back into the database and looked at all the fileds and there correct names and placed them into the query but nothing gets stored into the db. Now you may be thinking whats the file on top called connect.inc.php in my code this is its basically a script in php which connects to the server.

here is my code pleas have a look thank you :)

<?php

  //require 'core.inc.php';
  include 'connect.inc.php';


if(isset($_POST['Username'])&& isset($_POST['Password']) && isset($_POST['PasswordAgain'])&& isset($_POST['Firstname'])&& isset($_POST['Lastname'])){

    $username = $_POST['Username'];
    $password = $_POST['Password'];

    $password_again = $_POST['PasswordAgain'];
    $Firstname = $_POST['Firstname'];

    $password_hash = md5($password);

    $Lastname = $_POST['Lastname'];

    if(!empty($username)&& !empty($password) && !empty($password_again) && !empty($Firstname) && !empty($Lastname)){



if ($password !== $password_again) {

            echo "passwords do not match";
        }
        else{

            $query = "SELECT username FROM members WHERE username = '$username'";
            $query_run = mysql_query($query);
            if(mysql_num_rows($query_run )==1){

                echo "The username ". $username ." is taken";

            }else{

                $query = "INSERT INTO members VALUES ('','Firstname','Lastname','Username','Password')";
                if ($query_run = mysql_query($query)){

                    echo "Well done";


                }else{

                    echo "Sorry we couldn't register at this time. Please try again later thank you";
                }

            }

        }
    }   
    else{

        echo "Please fill in all the details thank you ";

    }
}

?>


<form action="join.inc.php" method="post">


     Username: <input type="text" name="Username" value="<?php echo $username; ?>" /><br />
     Password: <input type="password" name="Password" /><br />
     Password Again: <input type="password" name="PasswordAgain" /><br />
     FirstName: <input type="text" name ="Firstname" value="<?php echo $Lastname; ?>"  /><br />
     LastName: <input type="text" name ="Lastname" value="<?php echo $Firstname ?>" /><br />

    <input type="submit" value="SUBMIT" />
</form>

Connect Script

  • 写回答

7条回答 默认 最新

  • douzi3756 2012-03-14 05:24
    关注

    I would recommend explicitly stating the columns used in your INSERT statement.

    INSERT INTO members (`field1`, `field2`, ...) 
    VALUES ('','Firstname','Lastname','Username','Password')
    

    Also, what is the blank value you are trying to insert? If that field is an AUTO_INCREMENT field, you should not include it in the VALUES declaration.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥20 C# TCP服务端,客户端退出后,不断有数据进来
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?