Page 1 of 1

Won't Post Data

Posted: Fri Aug 15, 2008 2:27 pm
by CoolAsCarlito
I have a script I made which is located at http://www.kansasoutlawwrestling.com/titlehistory.php and when you click on each title it's supposed to go to my titlehistory table in my database and look for the get the correct corresponding title's info and post the values from that row. I know I only have values for my first title to test it but it won't even post that titles info. I was hoping someone might tell me why that is.

Code: Select all

<?php
// Connects to your Database
$link = mysql_connect("?", "?", "?") or die(mysql_error());
mysql_select_db("?",$link) or die(mysql_error());
 
if (!mysql_select_db("?", $link)) {
echo 'Could not select database';
exit;
}
 
if (isset($_GET['id']))
{
//Define the query
$query = "SELECT * FROM titlehistory WHERE id='".$_GET['id']."'";
 
if ($r = mysql_query ($query)){ // Run the query. 
    while ($row = mysql_fetch_array ($r)){
}   
 
print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
print '<tr><td background="images/bg_bar4.gif" height=35>&nbsp;<font color="white">Title Histories</font></td></tr>';
print '<tr><td></td></tr>';
print '</table>';
print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
print '<tr><td background="images/bg_bar3.gif" height=35 colspan=2><font color=red>&nbsp;KOW '.$row['titlename'].'</font></td></tr>';
print '<tr><td width=200><img src="/images/' . $row['titleimage'] . '" width=208px height=156px border=0 alt="View KOW '.$row['titlename'].' History"></td><td valign=top>';
print '<table cellpadding="2" cellspacing="0" border="0" width=100%>';
print '<tr><td align=center bgcolor=#E0E0E0><b>Date Created</b></td></tr><tr><td align=center><font color=white>'.$row['datecreated'].'</font></td></tr>';
print '<tr><td bgcolor=#E0E0E0 align=center><b>Status</b></td></tr>';
print '<tr><td align=center><font color=white>'.$row['status'].'</font></td></tr>';
print '<tr><td bgcolor=#E0E0E0 align=center><b>Longest Reign</b></td></tr>';
print '<tr><td align=center><a href=bio.php?'.$row['longestreign'].'><b>'.$row['longestreign'].'</b></a> <font color=white>('.$row['numdays'].')</font></td></tr>';
print '<tr><td bgcolor=#E0E0E0 align=center><b>Most Successful Defenses</b></td></tr>';
print '<tr><td align=center><a href=bio.php?'.$row['sucessdefenses'].'><b>'.$row['sucessdefenses'].'</b></a> <font color=white>('.$row['numdef'].')</font></td></tr>';
print '</table>';
}
}
else
{
print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
print '<tr><td background="images/bg_bar4.gif" height=35>&nbsp;<font color="white">Title Histories</font></td></tr>';
print '</table>';
print '<table border=0 cellspacing="0" cellpadding=3 width=575>';
print '<tr><td background="images/bg_bar3.gif" height=35 colspan=4>&nbsp;Active Titles</td></tr>';
print '<tr>';
 
//Define the query
$query = "SELECT * FROM titles WHERE status = 'Active'"; // Active rows
 
if ($r = mysql_query ($query)){ // Run the query. 
 
    while ($row = mysql_fetch_array ($r)){
    
        print '<td><a href="titlehistory.php?id=' . $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
        print '<img src="/images/' . $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
    
    }
 
} else {
    die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was $query.</p>');
} //End of query IF 
 
print '</tr>';
print '</table>';
print '<img src=images/spacer.gif><br>';
print '<table border=0 cellspacing=0 cellpadding=3 width=575><tr><td background="images/bg_bar3.gif" height=35 colspan=2>&nbsp;Inactive Titles</td></tr>';
print '<tr>';
 
//Define the query
$query = "SELECT * FROM titles WHERE status = 'Inactive'"; // Inactive Rows
 
if ($r = mysql_query ($query)){ // Run the query. 
 
    while ($row = mysql_fetch_array ($r)){
    
        print '<td><a href="titlehistory.php?id=' . $row['id'] . '" title="View KOW '.$row['titlename'].' History">';
        print '<img src="/images/' . $row['titleimage'] . '" border=0 alt="View KOW '.$row['titlename'].' History" height="115px" width="115px"></a></td>';
    
    }
 
} else {
    die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was $query.</p>');
} //End of query IF 
 
print '</tr>';
print '</table>'; 
}  
?>
 

Re: Won't Post Data

Posted: Fri Aug 15, 2008 3:04 pm
by nowaydown1
Follow a normal debugging procedure. Take the following snippet:

Code: Select all

 
if ($r = mysql_query ($query)){ // Run the query.
     while ($row = mysql_fetch_array ($r)){
}   
 
There's no error handling. Make sure your query is actually running. On a side note, if you're only returning one row there's no sense in running a while loop. You can just do:

Code: Select all

 
$row = mysql_fetch_array($r);
 
If the query isn't throwing an error, then check how many rows are being returned. If its zero then something about your criteria isn't correct. If it is returning a row, the do a print_r or var_dump on $row and see what's in there.