2017-01-15 21 views
0

返されたSQLクエリに基づいて新しいテーブルを表示しようとしています。これは、ユーザーがページを読み込んだときに表示される元のテーブルコードです。結果テーブルを表示するSQL

TABLE:

<form action="walkthroughs.php" method="POST"> 
     Platform: <input type="text" name="platform"/><br/> 
     <input type="submit" value="Search"/> 
</form> 
<body> 
    <section class="container"> 
     <div class="row"> 
      <table id="table1" class="table table-bordered"> 
       <thead> 
        <th>ID</th> 
        <th width="25%">FAQ Title</th> 
        <th width="25%">Game</th> 
        <th width="*">Platform</th> 
        <th width="15%">Date Created</th> 
        <th width="15%">Date Modified</th> 
       </thead> 
       <tbody> 
        <?php 
         mysql_connect("localhost", "root", "password") or die(mysql_error()); //Connect to server 
         mysql_select_db("walkthroughs") or die("Cannot connect to database"); //connect to database 
         $query = mysql_query("Select * from faqlist"); // SQL Query 
         while($row = mysql_fetch_array($query)) 
         { 
          Print "<tr>"; 
           Print '<td align="center">'. $row['FAQ_ID'] . "</td>"; 
           Print '<td align="center">'. $row['FAQ_Title'] . "</td>"; 
           Print '<td align="center">'. $row['Game'] . "</td>"; 
           Print '<td align="center">'. $row['Platforms'] . "</td>"; 
           Print '<td align="center">'. $row['Date_Created'] . "</td>"; 
           Print '<td align="center">'. $row['Date_Modified'] . "</td>"; 
          Print "</tr>"; 
         } 
        ?> 
       </tbody> 
      </table> 
     </div> 
    </section> 
</body> 

これは私が実行しようとしているPHPコードです。 (私は私の</html>タグの下にこれを置いた。)

PHP:私は別のテーブルを追加し、を隠すことなく ID "TABLE1" を持つHTMLテーブルを更新するにはどうすればよい

<?php 
    if($_SERVER["REQUEST_METHOD"] == "POST") // Added an if to keep the page secured 
    { 
     $platform = mysql_real_escape_string($_POST['platform']); 

     mysql_connect("localhost", "root", "password") or die(mysql_error()); // Connect to server 
     mysql_select_db("walkthroughs") or die("Cannot connect to database"); // Connect to database 
     $query = mysql_query("SELECT FAQ_ID, FAQ_Title, Game, Platforms FROM faqlist WHERE 
Platforms LIKE '$platform' OR Platforms LIKE '%$platform' OR Platforms LIKE '$platform%' OR Platforms LIKE '%$platform%'"); // SQL Query 
     while($row = mysql_fetch_array($query)) 
     { 
      Print "<tr>"; 
       Print '<td align="center">'. $row['FAQ_ID'] . "</td>"; 
       Print '<td align="center">'. $row['FAQ_Title'] . "</td>"; 
       Print '<td align="center">'. $row['Game'] . "</td>"; 
       Print '<td align="center">'. $row['Platforms'] . "</td>"; 
      Print "</tr>"; 
     } 
    } 
    else 
    { 
     header("location: walkthroughs.php"); 
    } 
?> 

」 table1 "テーブル?私は現在PHPで始まっています。

+3

、使用するたびに[ 'mysql_'](http://stackoverflow.com/questions/12859942/why-shouldnt- i-use-mysql-functions-in-php) データベース拡張子を新しいコード ** [キツンは世界のどこかで絞殺されている](http://bb.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg /AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)****それは廃止されており、何年も前からPHP7で永久に失われています。 PHPを学んでいるだけなら、 'PDO'や' mysqli'データベースの拡張機能や準備した文を学ぶことができます。 [ここから開始](http://php.net/manual/en/book.pdo.php) – RiggsFolly

+3

あなたのスクリプトは[SQL Injection Attack]の危険にさらされています(http://stackoverflow.com/questions/60174/how -in-prevent-sql-injection-in-php) [Little Bobby Tables](http://bobby-tables.com/)に何が起こったかを見てください。 [入力をエスケープしている場合は、安全でない!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) [準備されたパラメータ化されたステートメント](http://php.net /manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly

+0

最初のクエリが処理された後で、「」 – RiggsFolly

答えて

0

この拡張機能は、PHP 5.5.0では廃止され、PHP 7.0.0では削除されました。代わりに、MySQLiまたはPDO_MySQL拡張を使用する必要があります。

私は同じロジックで異なる例を共有しています。

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

$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname"; 
$result=mysqli_query($con,$sql); 

// Numeric array 
$row=mysqli_fetch_array($result,MYSQLI_NUM); 
printf ("%s (%s)\n",$row[0],$row[1]); 

// Associative array 
$row=mysqli_fetch_array($result,MYSQLI_ASSOC); 
printf ("%s (%s)\n",$row["Lastname"],$row["Age"]); 

// Free result set 
mysqli_free_result($result); 

mysqli_close($con); 
?> 

RESULT

必須。 mysqli_query()、mysqli_store_result()またはmysqli_use_result()

resultTypeと

オプションによって返される結果セットIDを指定します。作成する配列の種類を指定します。以下のいずれかの値になります

MYSQLI_ASSOC、 MYSQLI_NUM、 MYSQLI_BOTH、

+0

テーブルを印刷しますか? –

+0

非常に簡単な操作で印刷できます –

関連する問題