<?php
mysql_connect("localhost","root","");
mysql_select_db("school");
if($ok){
$sql="INSERT INTO user value('','$name','$gender','$age','$class')";
$result=mysql_query($sql);
echo "记录已经成功插入<br><a href='modify.php'>继续插入记录</a>";
}
else
{
?>
<form method=post action=insert.php>
姓名<input type=text name="name"><br>
性别<input type=text gender="gender"><br>
年龄<input type=text age="age"><br>
班级<input type=text class="class"><br> <input type=submit name='ok' value="ok">
</form><?
}
?>
这段代码逻辑有问题吗? 点击提交后没有报错,数据库也没有添加记录啊!
mysql_connect("localhost","root","");
mysql_select_db("school");
if($ok){
$sql="INSERT INTO user value('','$name','$gender','$age','$class')";
$result=mysql_query($sql);
echo "记录已经成功插入<br><a href='modify.php'>继续插入记录</a>";
}
else
{
?>
<form method=post action=insert.php>
姓名<input type=text name="name"><br>
性别<input type=text gender="gender"><br>
年龄<input type=text age="age"><br>
班级<input type=text class="class"><br> <input type=submit name='ok' value="ok">
</form><?
}
?>
这段代码逻辑有问题吗? 点击提交后没有报错,数据库也没有添加记录啊!
<?php
$conn = mysql_connect("localhost","root","");
mysql_select_db("school",$conn);
$ok = $_POST['ok'];
$name = $_POST['name'];
$gender = $_POST['gender'];
$age = $_POST['age'];
$class = $_POST['class']; if($ok){
$sql="INSERT INTO user value('','$name','$gender','$age','$class')";
$result=mysql_query($sql);
echo "记录已经成功插入<br><a href='modify.php'>继续插入记录</a>";
}
else
{
?>
<form method=post action=insert.php>
姓名<input type=text name="name"><br>
性别<input type=text gender="gender"><br>
年龄<input type=text age="age"><br>
班级<input type=text class="class"><br> <input type=submit name='ok' value="ok">
</form><?php
}
?>
$result=mysql_query($sql);
echo "记录已经成功插入<br><a href='modify.php'>继续插入记录</a>";