Jump to content

You have an error in your SQL syntax; check the manual that corresponds to your


mdfcows

Recommended Posts

Hi, I have been trying to make a page which shows a number of thumbnails, populated by images and text from a database, this I got working perfectly fine, but as I am now trying to make it so users can log in and edit or delete each one, it has all started to go a bit wrong and I was wondering if anyone could spot why?!?

 

It is currently bringing up this message on the screen:

 

Error fetching entries from the database, error: Statement: SELECT image,id,projecttitle,projectcode,FROM portfolio ORDER BY id DESC LIMIT 16

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM portfolio ORDER BY id DESC LIMIT 16' at line 1

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /Users/mdfcows/Sites/atelier/portfolio.php on line 129

 

I don't quite know how to get it to print out the full nature of the error, but this is the code I am using:

<?php
$max_items2 = 16; /* max number of news items to show */

require_once('config.php');
$db2 = mysql_connect (DB_HOST,DB_USER,DB_PASSWORD);
if(!$db2) {
	die('Failed to connect to server: ' . mysql_error());
}
mysql_select_db (DB_DATABASE,$db2);

function displayNews($all2 = 0) {
    global $db2, $max_items2;
    
    if ($all2 == 0) {
        /* query for news up to $max_items */
        $query9 = "SELECT image,id,projecttitle,projectcode," . 
                 
                 "FROM portfolio ORDER BY id DESC LIMIT $max_items2";
    } else {
        /* query for all news */
        $query9 = "SELECT image,id,projecttitle,projectcode," . 
                 
                 "FROM portfolio ORDER BY id DESC";
    }
    $result9 = mysql_query($query9) or print("<p>Error fetching entries from the database, error: " .	"Statement: " .	$query9 . "</p>" . mysql_error());


    while ($row9 = mysql_fetch_assoc ($result9)) {
        
        $title = htmlentities ($row9['projecttitle']);
        $news = nl2br (strip_tags ($row9['projectcode'], '<a><b><i><u>'));
	$image = $row9['image'];
	$id = $row9['id'];
        
        /* display the data */
	?>
	<div class="boxgrid captionfull">
            <a id="<?php echo $id ?>"
            
			<a class='visit' href="project.php?id=<?php echo $news ?>">
                
                <?php echo $image;

                if(strstr($image, 'jpg') or (strstr($image, 'png')) or (strstr($image, 'gif')) or (strstr($image, 'bmp')) or (strstr($image, 'jpeg')) ) {
		echo "<img class='cpimg' src='images/portfolio/$image' alt='' />";
	}else {
		echo "";}
		?>"></a>
                
                
                <div class="cover boxcaption" style="top: 122px; ">
				<p align="left"><?php echo $title ?></p>
			</div>
                </div>
        <?php	

	//Check whether the session variable SESS_MEMBER_ID is present or not

	if(isset($_SESSION['SESS_MEMBER_ID']) || (!trim($_SESSION['SESS_MEMBER_ID']) == '')) {
		echo "<form class='editbtn' action='editportfolio.php' method='POST'>";
		echo "<input type='hidden' name='idf' value='$id' />";
		echo "<input src='images/editbtn.png' type='image' value='Edit' />";
		echo "</form>";
		echo "<form class='editbtn' action='deletportfolio.php' method='POST'>";
		echo "<input type='hidden' name='ide' value='$id' />";
		echo "<input src='images/delbtn.png' type='image' value='Delete' />";
		echo "</form>";
	} else {
		echo "";
	}



    }
    
   
}

/* this is where the script decides what do do */

echo "\n";
switch($_GET['action']) {

    case 'all':
        displayNews(1);
        break;
    default:
        displayNews();
}
echo "\n";
?>

<?php
//Check whether the session variable SESS_MEMBER_ID is present or not
if(isset($_SESSION['SESS_MEMBER_ID']) || (!trim($_SESSION['SESS_MEMBER_ID']) == '')) {
echo "<span class='show_all'>";
echo "<a class='show' href='admincp.php'>  Admin</a>";
echo "</span>";
echo "<span class='show_all'>";
echo "<a class='show' href='logout.php'> Logout</a>";
echo "</span>";
} else {
echo "";
}
?>

 

with the line, " while ($row9 = mysql_fetch_assoc ($result9)) {"  being line 129

 

any help would be much appreciated!

 

Thank you, Martin

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.