所以我有下面的代码。我的问题是,要显示“vous êtes amis”消息,用户必须在提交按钮上单击两次。但我想让用户在提交按钮上只点击一次。谢谢!
<?php
$checkcontact = mysql_query("SELECT * FROM contacts WHERE IDcontact = '".$dnn['id']."'");
if(mysql_num_rows($checkcontact) == 1)
{
echo "<h1>Vous êtes amis</h1>";
}
else
{
?>
<form method="post" action="profile.php?id=<?php echo $dnn['id']; ?>">
<input type="hidden" value="<?=$dnn['Username'];?>" name="userid" />
<input type="submit" value="Add as Friend" />
</form>
<?php
if ($_POST)
{
$fid = htmlspecialchars(stripslashes($_POST['userid']));
$fid = mysql_real_escape_string($fid);
include("base.php");
mysql_query("INSERT into contacts (ID, Nom, IDcontact, Nomcontact) VALUES ('".$_SESSION ['id']."', '".$_SESSION['Username']."', '".$dnn['id']."', '$fid')");
}
}
?>