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
https://forums.phpfreaks.com/topic/250528-check-if-record-exists/
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

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)
}
?>


?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.