Jump to content

unique variables


Nandini

Recommended Posts

hi

 

i have a form with in while loop. In that form i have a field like mailbox number. If user enter submit button with unique mail box number values , I want to display an error message as "Dont enter unique values for mail box number"

 

here is my script

<form method="post">
<?
if(isset($_POST['submit']))
{
$i=0;
$row_size=count($_POST['secret']);
while ($i < $row_size) {
$check_mailbox=mysql_query("select * from astaccount where accountcode='".$_POST['mail_box'][$i]."'");
$mailbox_num=mysql_num_rows($check_mailbox);
if(empty($_POST['secret'][$i]))
{
$errmsg="Enter secret value.";
}
if(!ctype_digit($_POST['secret'][$i]))
{
$errmsg="Enter numerical values for secret.";
}
if(strlen($_POST['secret'][$i])<4)
{
$errmsg="Minimum four digits for secret";
}
if(strlen($_POST['secret'][$i])>6)
{
$errmsg="Maximum six digits for secret";
}
if(empty($_POST['mail_box'][$i]))
{
$errmsg="Enter mailbox number";
}
if(!ctype_digit($_POST['mail_box'][$i]))
{
$errmsg="Enter numerical values for mailbox number";
}
if($mailbox_num==0)
{
$errmsg="<b>".$_POST['mail_box'][$i]."</b> is not an existing mailbox number";
}
[b]i want to display error here when mailbox number filed contain unique value[/b]
++$i;
}
if($errmsg == '')
{
///////update operation
}
}
if(!isset($_POST['submit']) || $errmsg != '') {
?>
<div align="center"><font color="red"><? echo $errmsg; ?></font></div><br>
<table class="cptable" border="0" cellpadding="0" cellspacing="0" width="70%">
<tr height="25px" class="table_header">
<th><font color="white">Account</font></th>
<th><font color="white">Secret</font></th>
<th><font color="white">Notification Email</font></th>
<th colspan="6"><font color="white">Mailbox Number</font></th></tr>
<div id="content">
<?php
$row_uid="22"; 
$sql1 = mysql_query("SELECT * FROM astaccount where uid ='".$row_uid."'");
$i=0;
while ($res = mysql_fetch_array($sql1))
{
?>
<tr bgcolor="#e9f0f9">
<td><input type="text" name="secret[<? echo $i; ?>]" value="<? echo $res['secret']; ?>"></td>
<td><input type="text" name="mail_box[<? echo $i; ?>]" value="<? echo $res['mailbox']; ?>"></td>
</tr>
<input type="hidden" name="id[<? echo $i; ?>]" value="<? echo $res['uid']; ?>">
<input type="hidden" name="ac[<? echo $i; ?>]" value="<? echo $res['accountcode']; ?>">
<?php
++$i;
}
?>
<tr bgcolor="#e9f0f9"><td colspan="6" align="center">
<input type="submit" name="submit" value="submit">
</td></tr>
</table>
<?
}
?>
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.