Jump to content

Help in coding...


Guest

Recommended Posts

Hi everybody,

 

I'm having a headache with a coding of a page that always brings me the same error message:

"Database query failed: 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 'LIMIT 1' at line 1"

 

Here is the code of my page:

 

<?php require_once("includes/session.php"); ?>

<?php require_once("includes/connection.php"); ?>

<?php require_once("includes/functions.php"); ?>

<?php confirm_logged_in(); ?>

<?php

if (isset($_GET['news'])) {

$sel_news = $_GET['news'];

} else {

$sel_news = "";

}

$sel_info = get_news_by_id($sel_news);

?>

<?php include("includes/header.php"); ?>

<div id="mainMenu">

<ul>

<li><a href="content_news.php">News</a></li>

<li><a href="content_actors.php">Actors</a></li>

<li><a href="content_actresses.php">Actresses</a></li>

<li><a href="content_creative.php">Creative</a></li>

<li><a href="content_voice.php">Voice</a></li>

<li class="last"><a href="content.php">Back to Staff Menu</a></li>

</ul>

</div>

<div id="mainContent">

<div id="mainContentelement" class="staffContent">

<h2>NEWS section of </h2>

Please select one of these options:

<table width="100%" border="0">

<tr>

<td>

<p><a href="new_news.php">+ Add a new subject</a></p>

<p>Select the news to edit:<br/>

<?php

$news_set = get_all_news();

echo "<ul>";

while ($news = mysql_fetch_array($news_set)) {

echo "<li";

if ($news["id"] == $sel_news) {echo " class=\"selected\"";}

echo "><a href=\"content_news.php?news=" . urlencode($news["id"]) .

"\"> {$news["menu_name"]}</a></li>" . "<br />";

}

echo "</ul>";

?>

</p>

</td>

<td>

<?php echo $sel_info["menu_name"]; ?>

</td>

</tr>

</table>

</div>

<?php require("includes/footer.php"); ?>

 

I think it may come from the "get_news_by_id ()" function because when it starts bugging when I put it into the code. Here is this function:

 

function get_news_by_id($news_id) {

global $connection;

$query = "SELECT * ";

$query .= "FROM news ";

$query .= "WHERE id=" . $news_id ." ";

$query .= "LIMIT 1";

$result_set = mysql_query($query, $connection);

confirm_query($result_set);

// REMEMBER:

// if no rows are returned, fetch_array will return false

if ($news = mysql_fetch_array($result_set)) {

return $news;

} else {

return NULL;

}

}

 

Can anyone give me some help on that?  :-[

Link to comment
https://forums.phpfreaks.com/topic/177656-help-in-coding/
Share on other sites

Krystof,

 

This is a MySQL error, not a PHP error. That probably means the code is correct and the query is wrong. My best guess would be to change the lines:

 

$query .= "WHERE id=" . $news_id ." ";

$query .= "LIMIT 1";

 

to:

 

$query .= "WHERE id='".$news_id ."' ";

$query .= "LIMIT 1;";

Link to comment
https://forums.phpfreaks.com/topic/177656-help-in-coding/#findComment-936744
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.