![]() |
Problem with code
Hey guys,
I am working on a script and this portion of code throws back and error, and I can't seem to figure out why, any help would be appreciated! Code: $recordset = mysql_query('SELECT id, date, title, description FROM news WHERE id = '.$_GET['id'].' LIMIT 1;') or die(mysql_error()); $row = mysql_fetch_array($recordset); Error: 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 |
Oh and the code worked fine on another page, so I don't know what the problem is :-\
|
Oh, I see the problem now. You appear to have placed a semi-colon at the end of your SQL statement. Remove it and try again. I don't understand why it works on another page though if it's an identical query to that. I'm fairly sure PHP would not like that semi-colon there.
|
I changed the code to:
$recordset = mysql_query('SELECT id, date, title, description FROM news WHERE id = '.$_GET['id'].'LIMIT 1') or die(mysql_error()); It still throws back the same error? |
Code:
$recordset = mysql_query('SELECT id, date, title, description FROM news WHERE id = '.$_GET['id'].' LIMIT 1') or die(mysql_error()); |
Try adding back ticks.
Quote:
PHP Code:
PHP Code:
|
That is exactly like the original code that works in the other page, but it still kicks back an error on this page. Here is the whole script :
<?php $currentPage = basename($_SERVER['SCRIPT_NAME']); require_once('dbconfig.php'); $recordset = mysql_query('SELECT id, date, title, description FROM news WHERE id = '.$_GET['id'].' LIMIT 1') or die(mysql_error()); $row = mysql_fetch_array($recordset); ?> Maybe that will help |
Check my post.
|
Well, I tryed yours and it got rid of the error, but it did not echo the information, it is just blank. This is the whole page of code, with your code in it Nor.
<?php $currentPage = basename($_SERVER['SCRIPT_NAME']); require_once('dbconfig.php'); $recordset = mysql_query("SELECT `id`, `date`, `title`, `description` FROM `news` WHERE `id` = " . intval($_GET['id']) . " LIMIT 1;") or die(mysql_error()); $row = mysql_fetch_array($recordset); ?> <span class="newscontainer"> <div class="newsinside"> <!--News section --> <div class="newsep"> <span class="newsdate"><?php echo($row['date']);?></span><br /> <span class="newstitle"><?php echo($row['title']);?></span><br /> <span class="newsdes"> <?php echo($row['description']);?></span> </div> <!--End section--> <!--News section --> <div class="newsep"> <span class="newsdate"><?php echo($row['date']);?></span><br /> <span class="newstitle"><?php echo($row['title']);?></span><br /> <span class="newsdes"> <?php echo($row['description']);?></span> </div> <!--End section--> </div> </span> |
try doing
PHP Code:
|
where should i put that code? sry im really new to php
|
after:
$row = mysql_fetch_array($recordset); PHP Code:
|
it didnt print anything
|
Then there is no value for that ID, check your database.
|
ok i fixed all of that now one last problem or so i hope :(...i am getting a syntax error on this line
while ($row = mysql_fetch_array($recordset)){ echo('.$row['date']); It looks right to me? |
What's the syntax error? I'm fairly sure it's because of "echo('.$row['date']);". Try changing that to:
PHP Code:
|
Quote:
|
ok i fixed it all up how i wanted, although you people that are good at php probably would think its pretty butured up lol, thanks for the help guys
|
What was the problem just wondering?
|
i just changed the whole script around it looks like this now :
<?php require_once "dbconfig.php"; $recordset = mysql_query('SELECT id, date, title, description FROM news ORDER BY id DESC;'); while ($row = mysql_fetch_array($recordset)){ echo('<a href="newsedit.php?id='.$row['id'].'">'.$row['date'].'-'.$row['title'].'</a><br><a href="delete_news.php?id='.$row['id'].'">Delete</a><br><br>');} ?> |
| All times are GMT. The time now is 09:33 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0