Hi everyone, I have information posted on a database that I am trying to get my script to read based on one of the elements in the table matching with the supplied name (ie. the title) This is the data that I have in my first table. This is a segment of my code which is requesting the information from this table <?php $con = mysql_connect("localhost"," ***** "," ***** "); mysql_select_db("jmazza17_photos", $con); $album_title =('Test album'); $album_description = mysql_query("SELECT album_description FROM album_info WHERE album_title='{$album_title}'",$con); $total_photos = mysql_query("SELECT photos FROM album_info WHERE album_title='{$album_title}'",$con); if (!$con){ die('Could not connect: ' . mysql_error()); } if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); } ?> PHP: When I load the page I get this error: But as you can see from the image above the table is not empty. Any ideas how I can fix this. Thanks in advance.
Try with backtick: $album_description = mysql_query("SELECT `album_description` FROM `album_info` WHERE `album_title`='{$album_title}'",$con); $total_photos = mysql_query("SELECT `photos` FROM `album_info` WHERE `album_title`='{$album_title}'",$con); cheers
Hi AlC4Tr4z thanks for the quick reply. Unfortunately that did not work. Do you have any other ideas?
Hi, at this moment any sorry, I'm going to work now, if u can provide the db dump later in the evening I'll try some more solution. Cheers
Where is the $sql variable? I can not see it. You must to do so: <?php $con = mysql_connect("localhost"," ***** "," ***** "); mysql_select_db("jmazza17_photos", $con); if (!$con){ die('Could not connect: ' . mysql_error()); } $album_title = 'Test album'; $album_inf = mysql_query("SELECT album_description,photos FROM album_info WHERE album_title='{$album_title}'",$con); if (!$album_inf){ die('Error: ' . mysql_error()); } $row = mysql_fetch_row($album_inf); echo $row[0]; echo $row[1]; ?> PHP:
Please debug the script as follows. $album_title = 'Test album'; $sql="SELECT album_description,photos FROM album_info WHERE album_title='{$album_title}'"; echo $sql; exit; $album_inf = mysql_query($sql,$con); and see if the correct sql command is printing
Thanks for the help, that part of the script is now working properly and it is finding the album information. I am now trying to make it retrieve file names and file descriptions for each picture and I am running into some problems doing the same thing. This is the code that tries to retrieve that information.(its in the same file as the previous problem so the connection is still active). <table border="0" cellspacing="0" cellpadding="0" align="center"> <?php $count = 1; $pic_num = 1; $remainder = $total_photos % 6; $full_row = ($total_photos - $remainder)/6; while($count <= $full_row){ ?> <tr> <?php $j = 1; while ($j <= 6){ $file_info = mysql_query("SELECT pic_name,pic_description FROM pics WHERE album_title='{$album_title}' AND count = '{$pic_num}'",$con); if (!$file_info){ die('Error: ' . mysql_error()); } $row = mysql_fetch_row($file_info); $file_name = $row[0]; $file_description = $row[1]; ?> <td><a href="<?php echo($album_title); ?>/photos/<?php echo($file_name); ?>" rel="lytebox[vacation]" title="<b><?php echo($file_description); ?></b>"> <img src="<?php echo($album_title); ?>/thumbs/<?php echo($file_name); ?>" width="160" height="120" border="0" alt="Name:<?php echo($file_name);?>"></a></td> <?php $j = $j + 1; $pic_num = $pic_num + 1; } ?> </tr> <?php $count = $count + 1; } ?> </table> Code (markup): Any help is once again appreciated, thanks for the help.