<form action="<?php echo($php_self); ?>" method="post">请输入输入:
<br>姓名:<input type="text" name="name">
<br>地址:<input type="text" name="address">
<br><input type="submit" name="submit" value="submit" /></form>
<?php $name=$_POST['name'];
$address=$_POST['address'];
$submit=$_POST['submit'];
$dbcnx=@mysql_connect("localhost","root","root"); if(!$dbcnx)
{
echo "unable to connect the database server this time.";
exit();
}
if(!@mysql_select_db("school"))
{
echo "unable to locate the database at this time.";
exit();
}
if($submit=="submit")
{
$sql="insert into student(name,address,year)
value(".$name.",".$address.",".CURDATE().")";
if(mysql_query($sql))
{
echo "insert clear!";
}
else
{
echo "error adding submitted: ".mysql_error();
exit();
}
} else {
echo " unable!!!!";
}
?>
<br>姓名:<input type="text" name="name">
<br>地址:<input type="text" name="address">
<br><input type="submit" name="submit" value="submit" /></form>
<?php $name=$_POST['name'];
$address=$_POST['address'];
$submit=$_POST['submit'];
$dbcnx=@mysql_connect("localhost","root","root"); if(!$dbcnx)
{
echo "unable to connect the database server this time.";
exit();
}
if(!@mysql_select_db("school"))
{
echo "unable to locate the database at this time.";
exit();
}
if($submit=="submit")
{
$sql="insert into student(name,address,year)
value(".$name.",".$address.",".CURDATE().")";
if(mysql_query($sql))
{
echo "insert clear!";
}
else
{
echo "error adding submitted: ".mysql_error();
exit();
}
} else {
echo " unable!!!!";
}
?>
一句else {
echo " unable!!!!";
}请问哪里出错了
我把代码改为
if($submit=="submit")
{
echo "XXXXXXX!";
}else {
echo " unable!!!!";
}
都是显示else 的语句
curdate 改为date("Y-m-d");
print_r($_POST); //看能获取到值吗
value(".$name.",".$address.",".CURDATE().")";
if(mysql_query($sql))
{
echo "insert clear!";
}
else
{
echo "error adding submitted: ".mysql_error();
exit();
})测试过。。 没问题!!!
if(isset($submit))这样试试看。
<br>姓名:<input type="text" name="name">
<br>地址:<input type="text" name="address">
<br><input type="submit" name="submit" value="submit" />
</form>
<?php
if(isset($_POST['submit'])){
$name = trim($_POST['name']);
$address = trim($_POST['address']);
$dbcnx=@mysql_connect("localhost","root","root");
if(!$dbcnx){
exit("unable to connect the database server this time.");
}
if(!@mysql_select_db("school")){
exit("unable to locate the database at this time.");
}
$sql="insert into student(name,address,year) value('".$name."','".$address."','".date("Y-m-d")."')";
echo $sql;
mysql_query($sql) or die("error adding submitted: ".mysql_error());}
?>