Jump to content

Check if record exists


Gotharious

Recommended Posts

Hello,

 

I want to check when adding a new user, that if there are 2 records that has the same recruiter id, it's should give an error, if less, than it makes him complete the registration

 

Also check if the National ID number is not assigned to another user, so if there is a record that has it, it should give and error, if it's unavailable, it should let him complete the registration

 

here is my code

 

register.html

 

<html>
  <form action="post.php" method="post">
<table>
<tr><td>First Name: <input type="text" name="fname" /></td></tr>
<tr><td>Middle Name: <input type="text" name="mname" /></td></tr>
<tr><td>Last Name: <input type="text" name="lname" /></td></tr>
<tr><td>Mobile: <input type="text" name="mobile" /></td></tr>
<tr><td>Telephone: <input type="text" name="tel" /></td></tr>
<tr><td>Address: <input type="text" name="address" /></td></tr>
<tr><td>Job Title: <input type="text" name="job" /></td></tr>
<tr><td>Company: <input type="text" name="company" /></td></tr>
<tr><td>National ID Number: <input type="text" name="nid" /></td></tr>
<tr><td>Recruiter ID: <input type="text" name="recruiteris" /></td></tr>
<tr><td>Email: <input type="text" name="email" /></td></tr>
<tr><td>Password: <input type="password" name="password" /></td></tr>
<tr><td>Type: <input type="text" name="type" /></td></tr>

<tr><td><input type="submit" /></td></tr>

</table>
</form></html>

 

 

post.php

 

<?php

$sql="INSERT INTO users (id,fname, mname, lname, mobile, tel, address, job, company, nid, recruiteris, email, password, type)
VALUES
('','$_POST[fname]','$_POST[mname]','$_POST[lname]','$_POST[mobile]','$_POST[tel]','$_POST[address]','$_POST[job]','$_POST[company]','$_POST[nid]','$_POST[recruiteris]','$_POST[email]','$_POST[password]','$_POST[type]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
echo "<br />";
echo "<a href='http://waw-eg.com/admin/register.html'>Add More Client? Click Here</a><br/>";  
echo "<a href='http://waw-eg.com/admin/Users.php'>View Users Click Here</a>";

mysql_close($con)
?>

Link to comment
Share on other sites

I've tried that

it was

 

<?php

$fetch_check=mysql_query("SELECT email, nid FROM users WHERE email = '$email' OR nid = 'nid'");
$count=mysql_num_rows($fetch_check);

If($count>0);
{
echo 'Email or National ID already exist';
}
else
{
//Insert query here
}

?>

 

but after that, it neither gave me an error or registered the user no matter if any existed or not

Link to comment
Share on other sites

That's the whole code of post.php

 

<?php
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database", $con);


$fetch_check=mysql_query("SELECT email, nid FROM users WHERE email = '$email' OR nid = 'nid'");
$count=mysql_num_rows($fetch_check);

If($count>0);
{
echo 'Email or National ID already exist';
}
else
{

$sql="INSERT INTO users (id,fname, mname, lname, mobile, tel, address, job, company, nid, recruiteris, email, password, type)
VALUES
('','$_POST[fname]','$_POST[mname]','$_POST[lname]','$_POST[mobile]','$_POST[tel]','$_POST[address]','$_POST[job]','$_POST[company]','$_POST[nid]','$_POST[recruiteris]','$_POST[email]','$_POST[password]','$_POST[type]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
echo "<br />";
echo "<a href='http://waw-eg.com/admin/register.html'>Add More Client? Click Here</a><br/>";  
echo "<a href='http://waw-eg.com/admin/Users.php'>View Users Click Here</a>";

mysql_close($con)
}
?>


?>

 

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.