2017-06-09 74 views
-2

PHP/MySQL的畫廊問題頁和畫廊的問題

我已經在PHP畫廊。它從索引頁面接收「inname」參數。圖庫每次從頁面傳遞時都不會同時發送兩個參數,並且總體上不起作用。數據庫 「idtext」 的Unparameter 請告訴我的錯誤

enter code here 

的index.php

Lista de Acontecimientos<Br /> 
<?php 
$conexion = mysqli_connect("localhost", "root", "") or trigger_error(mysql_error(),E_USER_ERROR); 
mysqli_select_db($conexion,"db674013292"); 
$consulta="Select * from textos where clase=1 "; 
$result=mysqli_query($conexion,$consulta); 
?> 
<?php 
while($fila=mysqli_fetch_row($result)){ 
    echo "<a href=\"H.php?inombre='".$fila['0']."'\">".$fila['1']."</a><br>"; } 
?> 

Gallery.php

$inombre=$_GET['inombre']; 

    $objConnect = mysql_connect("localhost","root","") or die(mysql_error()); 
    $objDB = mysql_select_db("db674013292"); 

    $strSQL = "SELECT * FROM galeriadecidiendo where idtexto =$inombre "; 

    $objQuery = mysql_query($strSQL); 
     $Num_Rows = mysql_num_rows($objQuery); 

     $Per_Page = 8; // Per Page 

     @$Page = $_GET["Page"]; 
     if([email protected]$_GET["Page"]) 
     { 
      $Page=1; 
     } 

     $Prev_Page = $Page-1; 
     $Next_Page = $Page+1; 

     $Page_Start = (($Per_Page*$Page)-$Per_Page); 
     if($Num_Rows<=$Per_Page) 
     { 
      $Num_Pages =1; 
     } 
     else if(($Num_Rows % $Per_Page)==0) 
     { 
      $Num_Pages =($Num_Rows/$Per_Page) ; 
     } 

     else 
     { 
      $Num_Pages =($Num_Rows/$Per_Page)+1; 
      $Num_Pages = (int)$Num_Pages; 
     } 

     $strSQL .=" order by idgaleriatexto ASC LIMIT $Page_Start , $Per_Page"; 
     $objQuery = mysql_query($strSQL); 


     echo"<table border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\"><tr>"; 
     $intRows = 0; 
     while($objResult = mysql_fetch_array($objQuery)) 
     { 
      echo "<td>"; 
      $intRows++; 
    ?> 
<img with="150" height="150" src="<?=$objResult["url"]; ?>"><br>     
    <?PHP 
      echo"</td>"; 
      if(($intRows)%4==0) 
      { 
       echo"</tr>"; 
      } 
     } 
     echo"</tr></table>"; 
    ?> 
     <br> 
    <span class="paguinas">Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :</span> 


       <?PHP 
     if($Prev_Page) 
     { 
      echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&$inombre=idtexto'><< Back</a> "; 
     } 

     for($i=1; $i<=$Num_Pages; $i++){ 
      if($i != $Page) 
      { 
       echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&$inombre=idtexto'>$i</a> ]"; 
      } 
      else 
      { 
       echo "<b> $i </b>"; 
      } 
     } 
     if($Page!=$Num_Pages) 
     { 
      echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page$Prev_Page&$inombre=idtexto'>Next>></a> "; 
     }`enter code here` 
     ?> 


    <?PHP 
mysql_close($objConnect); 
?> 




</body> 
</html> 
+0

您的代碼很容易受到[** SQL注入* *](https://en.wikipedia.org/wiki/SQL_injection)攻擊。你應該使用[** mysqli **](https://secure.php.net/manual/en/mysqli.prepare.php)或[** PDO **](https://secure.php.net/ manual/en/pdo.prepared-statements.php)準備帶有綁定參數的語句,如[**這篇文章**]所述(https://stackoverflow.com/questions/60174/how-can-i-prevent-sql步噴射功能於PHP)。 –

+0

請勿使用'mysql_ *'功能。自v5.5(2013年6月)開始,它們已被棄用,並從v7.0(2015年12月)開始刪除。請使用[** mysqli _ ***](https://secure.php.net/manual/en/book.mysqli.php)或[** PDO **](https://secure.php.net /manual/en/book.pdo.php)與[**準備語句**](https://secure.php.net/manual/en/pdo.prepare.php)和[**綁定參數** ](https://secure.php.net/manual/en/pdostatement.bindparam.php)。 –

回答

0

感謝您的評論。

我已經改變了代碼庫MySQLi來,但問題仍然存在,因爲我錯誤地每一次發送的參數inname該頁面的步驟請我把它

<html><head></head><body> 
<?php 

$inombre=$_GET['inombre']; 
$objConnect = mysqli_connect("localhost","root","") or die(mysql_error()); 
$objDB = mysqli_select_db($objConnect,"db674013292");  
$strSQL = "SELECT * FROM galeriadecidiendo where idtexto =$inombre "; 
$objQuery = mysqli_query($objConnect,$strSQL); 
$Num_Rows = mysqli_num_rows($objQuery); 

$Per_Page = 8; 
?> 
     @$Page = $_GET["Page"]; 
     if([email protected]$_GET["Page"]) 
     { 
      $Page=1; 
     } 

     $Prev_Page = $Page-1; 
     $Next_Page = $Page+1; 

$Page_Start = (($Per_Page*$Page)-$Per_Page); 
if($Num_Rows<=$Per_Page) 
     {$Num_Pages =1;} 
     else if(($Num_Rows % $Per_Page)==0) 
     { 
      $Num_Pages =($Num_Rows/$Per_Page) ; 
     } 
     else 
     { 
      $Num_Pages =($Num_Rows/$Per_Page)+1; 
      $Num_Pages = (int)$Num_Pages; 
     } 


     $strSQL .=" order by idgaleriatexto ASC LIMIT $Page_Start , $Per_Page"; 
     $objQuery = mysqli_query($objConnect,$strSQL); 


     echo"<table border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\"><tr>"; 
     $intRows = 0; 
     while($objResult = mysqli_fetch_array($objQuery)) 
     { 
      echo "<td>"; 
      $intRows++; 

    <img with="150" height="150" src="<?=$objResult["url"]; ?>"><br>     

       echo"</td>"; 
       if(($intRows)%4==0) 
       { 
        echo"</tr>"; 
       } 
      } 
      echo"</tr></table>"; 


     <span class="paguinas">Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :</span> 



      if($Prev_Page) 
      { 
       echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&$inombre=idtexto'><< Back</a> "; 
      } 

      for($i=1; $i<=$Num_Pages; $i++){ 
       if($i != $Page) 
       { 
        echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&$inombre=idtexto'>$i</a> ]"; 
       } 
       else 
       { 
        echo "<b> $i </b>"; 
       } 
      } 
      if($Page!=$Num_Pages) 
      { 
    echo " <a href ='$_SERVER[SCRIPT_NAME] Page=$Next_Page$Prev_Page&$inombre=idtexto'>Next>></a> "; 
      } 
    mysqli_close($objConnect);