 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
11-06-2007, 01:52 AM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Nov 2007
Posts: 22
Thanks: 0
|
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
|
|
|
|
11-06-2007, 01:52 AM
|
#2 (permalink)
|
|
The Wanderer
Join Date: Nov 2007
Posts: 22
Thanks: 0
|
Oh and the code worked fine on another page, so I don't know what the problem is :-\
|
|
|
|
11-06-2007, 02:00 AM
|
#3 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
11-06-2007, 02:04 AM
|
#4 (permalink)
|
|
The Wanderer
Join Date: Nov 2007
Posts: 22
Thanks: 0
|
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?
|
|
|
|
11-06-2007, 02:26 AM
|
#5 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Code:
$recordset = mysql_query('SELECT id, date, title, description FROM news WHERE id = '.$_GET['id'].' LIMIT 1') or die(mysql_error());
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
11-06-2007, 02:29 AM
|
#6 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 282
Thanks: 61
|
Try adding back ticks.
Quote:
|
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.
|
Doesn't really matter since most sql delimiters use a semi colon at the end.
PHP Code:
$recordset = mysql_query("SELECT `id`, `date`, `title`, `description` FROM `news` WHERE `id` = " . intval($_GET['id']) . " LIMIT 1;") or die(mysql_error());
If that don't work try adding single quotes around the id:
PHP Code:
$recordset = mysql_query("SELECT `id`, `date`, `title`, `description` FROM `news` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1;") or die(mysql_error());
|
|
|
|
11-06-2007, 02:30 AM
|
#7 (permalink)
|
|
The Wanderer
Join Date: Nov 2007
Posts: 22
Thanks: 0
|
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
|
|
|
|
11-06-2007, 02:31 AM
|
#8 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 282
Thanks: 61
|
Check my post.
|
|
|
|
11-06-2007, 02:35 AM
|
#9 (permalink)
|
|
The Wanderer
Join Date: Nov 2007
Posts: 22
Thanks: 0
|
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>
|
|
|
|
11-06-2007, 02:37 AM
|
#10 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 282
Thanks: 61
|
try doing
PHP Code:
<?php print_r($row); ?>
and post the array that you get for us.
|
|
|
|
11-06-2007, 02:41 AM
|
#11 (permalink)
|
|
The Wanderer
Join Date: Nov 2007
Posts: 22
Thanks: 0
|
where should i put that code? sry im really new to php
|
|
|
|
11-06-2007, 02:43 AM
|
#12 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 282
Thanks: 61
|
after:
$row = mysql_fetch_array($recordset);
PHP Code:
$row = mysql_fetch_array($recordset); print_r($row);
|
|
|
|
11-06-2007, 02:45 AM
|
#13 (permalink)
|
|
The Wanderer
Join Date: Nov 2007
Posts: 22
Thanks: 0
|
it didnt print anything
|
|
|
|
11-06-2007, 02:48 AM
|
#14 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 282
Thanks: 61
|
Then there is no value for that ID, check your database.
|
|
|
|
11-06-2007, 03:03 AM
|
#15 (permalink)
|
|
The Wanderer
Join Date: Nov 2007
Posts: 22
Thanks: 0
|
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?
|
|
|
|
11-06-2007, 03:16 AM
|
#16 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
|
What's the syntax error? I'm fairly sure it's because of "echo('.$row['date']);". Try changing that to:
PHP Code:
echo $row['date'];
|
|
|
11-06-2007, 03:20 AM
|
#17 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 282
Thanks: 61
|
What are you talking about? Thats not even in his post that he posted. where you get that extra quotes..
|
|
|
|
11-06-2007, 03:38 AM
|
#18 (permalink)
|
|
The Wanderer
Join Date: Nov 2007
Posts: 22
Thanks: 0
|
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
|
|
|
|
11-06-2007, 04:12 AM
|
#19 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 282
Thanks: 61
|
What was the problem just wondering?
|
|
|
|
11-06-2007, 04:16 AM
|
#20 (permalink)
|
|
The Wanderer
Join Date: Nov 2007
Posts: 22
Thanks: 0
|
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>');}
?>
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|