2016-12-07 8 views
0

私は入力タイプ名= "name"を持っています。私はそれを提出すると、 "name"というデータベースの特定の列のデータと一致するかどうかを確認したい画像に見られる)、それが一致すれば、特定のコマンドを実行します。私の問題は、入力がその特定の列のデータと一致すると、適切なクエリまたはロジックがわからないことです。私はこのコードを試しましたが、正しい出力を得られません。前もって感謝します!私のプロジェクトで大きな助けになるでしょう! http://php.net/manual/en/intro.mysql.php入力タイプをデータベースの特定の列と比較する方法

Click this for the image sample

答えて

1

すべてのMySQLの第一は、PHPの最新バージョンでは削除されました

$name=$_GET['name']; //input type 

$result = mysql_query("SELECT name FROM map"); 
while ($search = mysql_fetch_assoc($result)) { 
$storeArray = $search['name']; 

if($name!=$storeArray){ 
echo "<script>alert('Nothing match your voice search! ')</script>"; 
echo "<script>window.location.href=\"map_index.php? name='$storeArray'\" </script>"; 


}else{ 


$find=mysql_query("SELECT * FROM map WHERE name='$name'"); 
while($found=mysql_fetch_assoc($find)){ 
、その代わりにはmysqliのやPDOを使用しています。

<?php 
$name = $_GET['name']; //input type 

//Create Prepared Statement 

if ($stmt = $mysqli->prepare("SELECT name FROM map WHERE name=?")) { 
    // bind parameters for markers the first parameter is the type, in this case it is a string, which is why we use 's'. If the parameter was an integer you would use 'i'. 
    //if this passes then the name that you are searching the database for exists 
    if ($stmt->bind_param("s", $name)) { 
     //success 
    } 
    else { ?> 
    <script> 
     alert('Nothing match your voice search!'); 
     window.location.href="map_index.php?name=<?= $storeArray; ?>"; 
    </script> 
    <?php } 
} ?> 

また、PHPからスクリプトタグとjavascriptをどのように分離したかにも注意してください。これは、あなたがそれを持っていた方法とまったく同じですが、はるかにクリーンで、ベストプラクティスと見なされます。

+0

私のPHPは更新されていないので、私はmysqliを使用してそれを行うことはできません、mysqlのそのコードの代替はありますか?それは本当に大きな助けになるでしょう – Janaaan

関連する問題