2012-11-23 8 views
0

i have 2 fichiers fourm.php et viewfourm.phpMySql/PHP Forum Problèmes avec sélection Forum Pour Voir

fourm.php premier

<?php 

$host="mysql13.000webhost.com"; // Host name 
$username="a2670376_Users"; // Mysql username 
$password="PASS"; // Mysql password 
$db_name="a2670376_Pass"; // Database name 
$tbl_name="fourm"; // Table name 

    // Connect to server and select database. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

    // select record from mysql 
    $sql="SELECT * FROM $tbl_name"; 
    $result=mysql_query($sql); 
?> 
<table> 
<tr> 
<td align="center"><strong>Post Number</strong></td> 
<td align="center"><strong>UserName</strong></td> 
<td align="center"><strong>Topic</strong></td> 
<td align="center"><strong>Date</strong></td> 
<td align="center"><strong>View</strong></td> 
</tr> 
<?php 
while($rows=mysql_fetch_array($result)){ 
?> 
<tr> 
<td><? echo $rows['fourmid']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
<td><? echo $rows['username']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
<td><? echo $rows['fourmname']; ? >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
<td><? echo $rows['date']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
<td><a href="viewfourm.php?id=<? echo $rows['fourmid']; ?>">View Topic</a></td> 
<?php 
// close while loop 
} 
?> 

</tr> 
</table> 
<?php 
// close connection; 
mysql_close(); 
?> 
<hr width='67%' color='#29001F' size='3'/> 
</center> 

maintenant viewfourm.php

<?php 

$host="mysql13.000webhost.com"; // Host name 
$username="a2670376_Users"; // Mysql username 
$password="PASS"; // Mysql password 
$db_name="a2670376_Pass"; // Database name 
$tbl_name="fourm"; // Table name 

    // Connect to server and select database. 
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB"); 

    // select record from mysql 
    $sql="SELECT * FROM $tbl_name"; 
    $result=mysql_query($sql); 
    ?> 
    <table> 
    <tr> 
    <td align="center"><strong>Post Number</strong></td> 
<td align="center"><strong>UserName</strong></td> 
<td align="center"><strong>Topic</strong></td> 
<td align="center"><strong>Date</strong></td> 
<td align="center"><strong>View</strong></td> 
</tr> 
<?php 
while($rows=mysql_fetch_array($result)){ 
?> 
<tr> 
<td><? echo $rows['fourmid']; ? >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
<td><? echo $rows['username']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
<td><? echo $rows['fourmname']; ? >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
<td><? echo $rows['date']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
<td><a href="fourm.php">back/a></td> 
<?php 
// close while loop 
} 
?> 

</tr> 
</table> 
<?php 
// close connection; 
mysql_close(); 
?> 
<hr width='67%' color='#29001F' size='3'/> 
</center> 

maintenant sur forum.php quand je sélectionne ce "forum" de base de données MySql je veux voir il charge tous les forums que je veux réparer je sais pourquoi il le fait sa cause le même script que le premier juste modifié un peu mais je l'ai fait Je pourrais le faire. je suis choisissais tag thrue de fourmid de forum dans la base de données MySql c'est ce que le « > Voir sujet est sur son supposé charger le forum avec l'ID sélectionné

+0

sql vurnurable Je sais fix mal plus tard une fois que je résoudre ce –

+1

[** S'il vous plaît, ne pas utiliser les fonctions '' * de mysql_ dans le nouveau code **] (http: // bit .ly/phpmsql). Ils ne sont plus maintenus et le [processus de dépréciation] (http://j.mp/Rj2iVR) a commencé dessus. Voir la [** boîte rouge **] (http://j.mp/Te9zIL)? En savoir plus sur [* instructions préparées *] (http://j.mp/T9hLWi) à la place, et utiliser [PDO] (http://php.net/pdo) ou [MySQLi] (http://php.net/ mysqli) - [cet article] (http://j.mp/QEx8IB) vous aidera à décider lequel. Si vous choisissez PDO, [voici un bon tutoriel] (http://j.mp/PoWehJ). – PeeHaa

+0

MySQLi encore en train d'apprendre MySQL et PHP lol malade apprendre que la prochaine, mais pour moi MySQL est plus facile –

Répondre

0

Dans viewfourm.php modifier votre requête sql $sql="SELECT * FROM $tbl_name"; comme celui-ci

$fourmid= $_POST['fourmid']; //if passing using get method use $_GET['fourmid']; $sql = "SELECT * FROM $tbl_name WHERE fourmid = '$fourmid'";

vous avez aussi passer fourmid de fourm.php à viewfourm.php

EDIT

Faire un lien comme celui-ci

<td> <a href="viewfourm.php?fourmid=<? echo $rows['fourmid']; ?>"> <? echo $rows['fourmname']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </a> </td>

+0

Attention: mysql_fetch_array(): l'argument fourni n'est pas une ressource de résultat MySQL valide dans /home/a2670376/public_html/fourms/viewfourm.php sur la ligne 35 J'ai obtenu ceci et je l'ai fait au script // sélectionnez l'enregistrement de mysql $ fourmid = $ _POST ['fourmid']; // si passer avec la méthode get utilise $ _GET ['fourmid']; $ sql = "SELECT * FROM $ nom_bloc WHEREfourmid = '$ fourmid'"; –

+0

comment le passerais-je? –

+0

faire un lien dans fourm.php pour chaque sujet – Ravi

0

en form.php obtenir la valeur de

a href="viewfourm.php?id=<? echo $rows['fourmid']; ?>">View Topic</a> 

//viewform.php

$ fourmid = $ _REQUEST [ » id '] ;.

$ sql = "SELECT * FROM $ nom_bloc WHERE fourmid = '$ fourmid'";

Essayez ..

+0

Attention: mysql_fetch_array(): l'argument fourni n'est pas une ressource de résultat MySQL valide dans/home/a2670376/public_html/fourms/viewfourm.php sur la ligne 34 –

+0

je jamais utilisé pour obtenir cette erreur avant:, ( –

+0

je ne peux toujours pas le comprendre –