求PHP大神解答问题 怎么会出错??? 30
//index.php<formid="form1"name="form1"method="post"action="Add.php"><labelclass="STYL...
//index.php
<form id="form1" name="form1" method="post" action="Add.php">
<label class="STYLE21">游戏名
<input name="name" type="text" class="STYLE21" id="name" />
</label>
<p>
<label class="STYLE21">昵称
<input name="ch_name" type="text" class="STYLE21" id="ch_name" />
</label>
</p>
<p>
<label>
<input name="Submit" type="submit" class="STYLE10" value="加入势力" />
</label>
</p>
</form>
//Add.php
<?php
$action = $_SERVER['PHP_SELF'];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$con = mysql_connect("localhost","elitetrp","yangge304291");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("elitetrp", $con);
mysql_query("INSERT INTO elitetrp.gaizaozhe (`id` ,`name` ,`perm` ,`ch_name` )
VALUES ('3', $_POST['name'], 'builder', '$_POST['ch_name']'");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
}
?> 展开
<form id="form1" name="form1" method="post" action="Add.php">
<label class="STYLE21">游戏名
<input name="name" type="text" class="STYLE21" id="name" />
</label>
<p>
<label class="STYLE21">昵称
<input name="ch_name" type="text" class="STYLE21" id="ch_name" />
</label>
</p>
<p>
<label>
<input name="Submit" type="submit" class="STYLE10" value="加入势力" />
</label>
</p>
</form>
//Add.php
<?php
$action = $_SERVER['PHP_SELF'];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$con = mysql_connect("localhost","elitetrp","yangge304291");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("elitetrp", $con);
mysql_query("INSERT INTO elitetrp.gaizaozhe (`id` ,`name` ,`perm` ,`ch_name` )
VALUES ('3', $_POST['name'], 'builder', '$_POST['ch_name']'");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
}
?> 展开
展开全部
sql语句出错了:有两处问题,1是id是自增字段吧?那么不要给具体值;2是标点符号有问题
mysql_query("INSERT INTO elitetrp.gaizaozhe (`id` ,`name` ,`perm` ,`ch_name` )
VALUES ('3', $_POST['name'], 'builder', '$_POST['ch_name']'");
应该为:
$name=$_POST["name"];
$ch_name=$_POST["ch_name"];
mysql_query("INSERT INTO elitetrp.gaizaozhe (`id` ,`name` ,`perm` ,`ch_name` )
VALUES (NULL, '$name', 'builder', '$ch_name'");
ps,代码还是写规范些好,这样看着不舒服,另外就是建议用php5面向对象的方式写
mysql_query("INSERT INTO elitetrp.gaizaozhe (`id` ,`name` ,`perm` ,`ch_name` )
VALUES ('3', $_POST['name'], 'builder', '$_POST['ch_name']'");
应该为:
$name=$_POST["name"];
$ch_name=$_POST["ch_name"];
mysql_query("INSERT INTO elitetrp.gaizaozhe (`id` ,`name` ,`perm` ,`ch_name` )
VALUES (NULL, '$name', 'builder', '$ch_name'");
ps,代码还是写规范些好,这样看着不舒服,另外就是建议用php5面向对象的方式写
追问
还是有问题啊
怎么回事
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询