Jump to content

Simple Error


Ducky1

Recommended Posts

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
Share on other sites

Just realised that after posting, but changed the password for it already just in case :D

 

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.