Created
May 15, 2015 07:27
-
-
Save mokiding/ee836fdac188f99e9b01 to your computer and use it in GitHub Desktop.
Check if ID exist in database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mysql_server = "localhost"; | |
$mysql_user = "username"; | |
$mysql_password = "password"; | |
$mysql_dbname = "db"; | |
$mysqlcon = new mysqli($mysql_server, $mysql_user, $mysql_password, $mysql_dbname); | |
if ($mysqlcon->connect_error) { | |
die("Connection failed: " . $mysqlcon->connect_error); | |
} | |
$id = mysqli_real_escape_string($mysqlcon,$_GET['id']); | |
$query = "SELECT id FROM members WHERE id='$id'"; | |
if ($mysqlcon->query($query) != TRUE) { | |
echo "Error: " . $query . "<br>" . $mysqlcon->error; | |
} | |
if ($result = mysqli_query($mysqlcon, $query)) | |
{ | |
$row_cnt = mysqli_num_rows($result); | |
if($row_cn > 0) | |
{ | |
echo "The ID ".$id." is found in database (exist)"; | |
} | |
else | |
{ | |
echo "The ID ".$id." is not found in database (not exist)"; | |
} | |
mysqli_free_result($result); | |
} | |
mysqli_close($mysqlcon); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment