这是我的代码:
<html>
<body>
<BR><p><U>Add contact...</U></p><BR>
Name: <INPUT TYPE="text" NAME="firstbox">
Id.number: <INPUT TYPE="text" NAME="idbox">
<?php
session_start();
$username=$_SESSION['UserID'];
$s_name=$_GET['firstbox'];
$s_id=$_GET['idbox'];
$db = mysql_connect("???????", "???????", "");
mysql_select_db("???????",$db);
$result = mysql_query("SELECT * FROM contacts WHERE u_id='$username' and c_id='$s_id'",$db);
$myrow = mysql_fetch_row($result);
if(!$myrow) {
mysql_query("INSERT INTO contacts(u_id, c_name, c_id) VALUES ('$username','$s_name','$s_id')",$db);
header("Location: http://?????/protectedpage.php");
} else {
header("Location: http://?????contact1.htm");
}
?>
</body>
</html>
是否可以检查是否在firstbox
and中输入了我的值lastbox
,如果是,则连接到数据库,但如果否,则不要插入数据库?
是否可以限制一个框中的总整数,例如,idbox
如果整数大于 5(12345、11234、99900),不要插入数据库?
好的,我已经尝试过了,但它不起作用
if (($s_id="") and ($_name=""))
{
header("Location: http://at-web2.comp.glam.ac.uk/students/10003088/contact1.htm");
}
else
{
$db = mysql_connect("at-web2.comp.glam.ac.uk", "user_10003088", "Glamorgan1");
mysql_select_db("db_10003088",$db);
$result = mysql_query("SELECT * FROM contacts WHERE u_id='$username' and c_id='$s_id'",$db);
$myrow = mysql_fetch_row($result);
if(!$myrow)
{
mysql_query("INSERT INTO contacts(u_id, c_name, c_id) VALUES ('$username','$s_name','$s_id')",$db);
header("Location: http://at-web2.comp.glam.ac.uk/students/10003088/protectedpage.php");
}
else{
header("Location: http://at-web2.comp.glam.ac.uk/students/10003088/contact1.htm");
}
}
我添加了一个 if 语句来检查,