2016-05-06 1 views
0

私は、phpページにフィールドを持って、登録番号を入力し、詳細を確認します。 Here is the ScreenShot. 登録番号は、表のIDです。 それで、どのように私はデータベースのレジスタ番号でページに入力されたレジスタ番号を確認できますか?ここでphpのID(主キー)を検証する方法は?

は、コードは次のとおりです。

<?php 
session_start(); 
include 'connect1.php'; 
if (isset($_POST['login'])) 
{ 
    $_SESSION['regno']= $_POST['regno']; 
    $regid = $_SESSION['regno']; 
    if (empty($regid)){ 
     echo "<p class='echo'> *The Field Should not be empty </P>"; 
    } 
    else if ($regid =)//WHAT SHOULD BE CHECKED HERE ?????? 
    { 
     header('location: details.php');// If not empty, Details page is loaded. 
    } 
} 
?> 
<html> 
<head> 
    <title> 
     Login 
    </title> 
    <link rel="stylesheet" type="text/css" href="style.css"> 
</head> 
<body> 
<div class="reg"> 
    <h1 class="h1">Registered User?</h1> 
    <form action="" method="POST" > 
    <input type="number" class="textbox" name="regno" placeholder="Registration Number"/><br/> 
    <input type="submit" class="login" name="login" value="Check"> 
</form> 
</div> 
</body> 
</html> 

私はフィールドに入力した番号がデータベース内にあるかどうかを確認する必要があります?事前に

感謝:)

+0

はいデータベースでそれを確認する必要があります。 mysqliを使用してdbに接続し、id = registration_numberの製品を選択します。 –

+0

where句とnum行を使用してselectクエリを実行します。 num行== 0の場合、無効なentry.Elseが有効です。 –

+0

"SELECT id FROM table_name id = '$ regid'" –

答えて

0

回答は、あなたのパターンを使用していますロジックを実装して実装します。

<?php 
$con=mysqli_connect("localhost","my_user","my_password","my_db"); 
// Check connection 
if (mysqli_connect_errno()) { 
echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 
// escape variables for security 
$_SESSION['regno'] = mysqli_real_escape_string($con, $_POST['regno']); 
$regid =$_SESSION['regno']; 
if (empty($regid)){ 
    echo "<p class='echo'> *The Field Should not be empty </P>"; 
} 
else 
{ 
    $sql="select regno from your_table where regno='".$regid."'"; 
    $result=mysqli_query($con,$sql); 
    $number=mysqli_num_rows($result); 
    if($number > 0){ 
    header('location: details.php');// If not empty, Details page is loaded. 
    }else{ 
    echo "<p class='echo'> *Not Found </P>"; 
    } 

} 
0

ただ、このような要求を行います。

Select * From table_name Where ID = the_checked_ID 

それは何も返さない場合は、IDがデータベースにない

+1

セキュリティチェックはありません! ** PHP **で実装する必要もあります。 –

0

これを試してみてください。..

<?php 
$current_path = $_SERVER['SCRIPT_NAME']; 
//include database connection code here :) 
if(isset($_POST['regno'])) 
{ 
    $regnumber = $_POST['regno']; 
    $query = "Select * From your_table_name Where ID = '$regnumber'"; 
    if($query_run = mysql_query($query)) 
    { 
     $num_rows = mysql_num_rows($query_run); 
     if($num_rows == 1) 
     { 
      echo "This is registered User"; 
     } 
     else 
     { 
      echo "Please Register"; 
     } 
    } 
} 
?> 
<html> 
<head> 
    <title> 
     Login 
    </title> 
    <link rel="stylesheet" type="text/css" href="style.css"> 
</head> 
<body> 
<div class="reg"> 
    <h1 class="h1">Registered User?</h1> 
    <form action="<?php echo $current_path ?>" method="POST" > 
    <input type="number" class="textbox" name="regno" id="regno" placeholder="Registration Number"/><br/> 
    <input type="submit" class="login" name="login" value="Check"> 
</form> 
</div> 
</body> 
</html> 
関連する問題