これは私のコードです:
<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>
I 値がfirstbox
andlastbox
に入力されているかどうかを確認し、はいの場合はデータベースに接続し、いいえの場合はデータベースに挿入しないことは可能ですか?
また、ボックス内の合計整数を制限することは可能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文を追加しましたが、