如何根据php中的表中的数据检查用户输入?

时间:2012-03-07 19:20:36

标签: php mysql

如果用户在表单字段“AddGuestName”中输入数据,我想查询“a_table”以查看是否允许其他访客。 “addguest”列包含“Y”,如果他们可以有一个额外的访客,如果他们不能,则包含“N”。如果他们不能显示和错误消息,并且在“AddGuestName”字段为空之前不保存数据。不知道我哪里出错了。

我的代码

$Name = check_name($_POST['name'],
 " Enter Your First and Last Name....Click Your Browsers Back Button To Re-Enter ");    

$RsvpNum = check_input($_POST['RsvpNum'], " Enter The 3 Digit RSVP Number Located On Your RSVP Card....Click Your Browsers Back Button To Re-Enter ");

$AddGuestName = check_rsvp($_POST['AddGuestName'], "You Are Not Allowed An Additional Guest.....Click your Browsers Back Button To Re-Enter");


function check_rsvp($data, $query, $result, $RsvpNum, $AddGuestName, $problem='')<br />
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
   if ($problem && strlen($data) > 0)
    {
mysql_query($query="SELECT addguest FROM a_table WHERE rsvp_num=$RsvpNum");
    $result=mysql_query($query);
    }
    return $data;



    if (($result) == 'N')
        {
            die($problem);
        }
        return $data;
    }

2 个答案:

答案 0 :(得分:0)

您对第一return $data之后的if意味着什么?我在想不...

答案 1 :(得分:0)

$query="SELECT addguest FROM guests WHERE rsvp_num=$RsvpNum LIMIT 1";
$result=mysql_query($query);
$row = mysql_fetch_row($result);

if ($row[0] =='y'){
 ...