Ducky1 Posted June 14, 2009 Share Posted June 14, 2009 Hi Guys, Trying to do a really simple script. Not sure, but i think the error is getting the user / $table variable into the query. Thanks in advance. <?php $table = $_GET['user']; $conn = mysql_connect("**", "***", "***"); if (!$conn ) { echo "Could not connect to the database."; } $did_we_find_a_db_to_use = mysql_select_db("rovstr_peter"); if (!$did_we_find_a_db_to_use) { echo "Invalid database name."; } $data = mysql_query("SELECT * FROM rank WHERE name = '$table'"); Print "<table border cellpadding=3>"; $info = mysql_fetch_array($data); while($info = mysql_fetch_array($data)) { echo "test"; Print "<tr>"; Print "<th>Name:</th> <td>".$info['name'] . "</td> "; Print "<th>Rank:</th> <td>".$info['rank'] . " </td>"; Print "<th>Title:</th> <td>".$info['title'] . "</td> "; } Print "</table>"; echo("End"); ?> Link to comment https://forums.phpfreaks.com/topic/162112-simple-error/ Share on other sites More sharing options...
joel24 Posted June 14, 2009 Share Posted June 14, 2009 whats the error you are getting? was going to tell you to edit out the user/pass for your database but you've already done so, Link to comment https://forums.phpfreaks.com/topic/162112-simple-error/#findComment-855466 Share on other sites More sharing options...
Ducky1 Posted June 14, 2009 Author Share Posted June 14, 2009 Just realised that after posting, but changed the password for it already just in case Its just that the $data = mysql_query("SELECT * FROM rank WHERE name = '$table'"); - getting the $table into the query, and where it says echo "test", it never appears, so it must be failing somewhere Link to comment https://forums.phpfreaks.com/topic/162112-simple-error/#findComment-855467 Share on other sites More sharing options...
joel24 Posted June 14, 2009 Share Posted June 14, 2009 also check that your $table variable is being set... up the top put in $table = $_GET['user']; echo $table; exit(); and see what it echos. Link to comment https://forums.phpfreaks.com/topic/162112-simple-error/#findComment-855468 Share on other sites More sharing options...
joel24 Posted June 14, 2009 Share Posted June 14, 2009 woops sorry, didnt have a good enough look at your code you have mysql_fetch_array twice. change get rid of the $info = mysql_fetch_array($data); line so its only Print "<table border cellpadding=3>"; while($info = mysql_fetch_array($data)) Link to comment https://forums.phpfreaks.com/topic/162112-simple-error/#findComment-855469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.