Jump to content

Recommended Posts

I have a script found out 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 I could find someone to tell me why that is.

 

<?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 *, DATE_FORMAT(`datecreated`, '%M %e, %Y') as datecreated FROM titlehistory";

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> <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> 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> <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> 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> 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>'; 
}  
?>

Link to comment
https://forums.phpfreaks.com/topic/119851-solved-wont-post-data-from-table/
Share on other sites

Dont you want to find the record from the ID?

if (isset($_GET['id']))
{
//Define the query
$query = "SELECT *, DATE_FORMAT(`datecreated`, '%M %e, %Y') as datecreated FROM titlehistory";

 

Should be

 

if (isset($_GET['id']))
{
//Define the query
$query = "SELECT *, DATE_FORMAT(`datecreated`, '%M %e, %Y') as datecreated FROM titlehistory WHERE id='".$_GET['id']."'";

neil.johnson you are correct, but without the id=id part it should grab everything and output something.  Try formatting the date in the php rather than in the SQL query, it may be screwing something up.  Example:

 

$query = "SELECT * FROM titlehistory WHERE id='".$_GET['id']."'";

 

Wherever you use "$row['datecreated']" replace with:

 

date("Y/m/d", $row['datecreated'])

Wow.

How did you create your database tables?

Are you using phpmyadmin or a similar web based program?

If so, put your SQL into the query window to test.

 

Using MYSQL on the command line: If using linux then login to the mysql server via SSH (if you are allowed to do this, maybe you are on a shared server, dunno). If Windows then dont know because Windows is a crap platform (my god that statements gonna get some feedback)

Replace:

 

$query = "SELECT *, DATE_FORMAT(`datecreated`, '%M %e, %Y') as datecreated FROM titlehistory";

if ($r = mysql_query ($query)){ // Run the query. 
    while ($row = mysql_fetch_array ($r)){
}	

 

With:

 

$query = "SELECT *, DATE_FORMAT(`datecreated`, '%M %e, %Y') as datecreated FROM titlehistory";

       $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
        $row = mysql_fetch_assoc($result);

 

If that doesn't work you need to start debugging...

 

Use neil.johnson's suggestion.  Put the query into PhpMyAdmin, or whatever web app you use, and see if the correct results return.  If they don't there's something wrong with your sql statement (wrong table name, field name etc...).  If you get the correct results then go back and try and just

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.