duai3681 2013-03-14 05:35
浏览 55
已采纳

为什么我的$ _GET表单不会将数据(使用PHP)插入到MySql数据库或表中?

Here is the html form:

<form action="register.php" METHOD=GET align="center">
<table border="2" align="center">
<tr>
<td>Desired Username:</td><td><input name="username" type="text" size"20"></input></td>
</tr>
<tr>
<td>Your Email:</td><td><input name="email" type="text" size"30"></input></td>
</tr>
<tr>
<td>Desired Password:</td><td><input name="password" type="password" size"20"></input>                                       </td>
</tr>
<tr>
<td>Confirm Password:</td><td><input name="password2" type="password" size"20"></input>          </td>
</tr>
</table>
<input type="submit" value="Register!" align="center"></input>
</FORM>

And here is the PHP code on register.php:

<?php
$myServer = "localhost";
$myUser = "Censored";
$myPass = "Censored";
$myDB = "Censored";

//connection to the database
$conn = "mssql_connect($myServer, $myUser, $myPass)
or die('Couldn't connect to SQL Server on $myServer')"; 

//select a database to work with
$selected = "mssql_select_db($myDB, $conn)
or die('Couldn't open database $myDB')"; 

//add new user to DB
if($_GET["username"] && $_GET["email"] && $_GET["password"] && $_GET["password2"] )
{
if($_GET["password"]==$_GET["password2"])
{
$sql="INSERT INTO Users(Username, Password, Email)              VALUES('$_GET[username]','$_GET[password]','$_GET[email]')";
$result="mysql_query($sql,$conn) or die (mysql_error())";
}

if ($result)
{
echo "<h1 align='center'>Registration Successful!</h1>";

echo "<p align='center'>Click<a href='index.php'> here</a> to log in.</p>";

}
else echo "Oops! Something went wrong. Please <a       href='http://www.canilosa.zxq.net/index.php'>go back</a> and fix it.";
}
?>

I am a beginner in PHP and MySql. I have checked and rechecked all the usernames, passwords, databases, etc. The echo works and it says the registration is successful, but when I check my database there is no data.


Thanks SO much to everyone who answered!!! It works fine now :). As I said, I am new to all of this so most of the code was from snippets of tutorials and I just kind of skimmed it to see if it made sense. Thanks again! (I'm creating a game website with lots of PHP-MySql...so I'll probably be back here soon enough xD)

  • 写回答

4条回答 默认 最新

  • dousao6313 2013-03-14 05:43
    关注

    Mysql functions that you are using are not correct ...

    change

    mssql_connect($myServer, $myUser, $myPass)
    

    to

    mysql_connect($myServer, $myUser, $myPass)
    

    AND

    mssql_select_db($myDB, $conn)
    

    to

    mysql_select_db($myDB, $conn)
    

    DOCUMENTATION LINK http://www.w3schools.com/php/php_ref_mysql.asp

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

报告相同问题?

悬赏问题

  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件