alen Posted December 4, 2006 Share Posted December 4, 2006 I'm making a news management script!So far I have managed to make the script add news, so that I can view it on the index page. Now I've started with the edit part.First off I got an error ... then I added a mysql_error to check it.This is the result of the new error:[b]Parse error:[/b] parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in [b]/path/path/rediger.php[/b] on line [b]8[/b].I can't seem to find any extra spaces in the script, so I don't think that's causing the error.Here's my code, http://anigma.sitees.com/rediger.txt and http://anigma.sitees.com/lagre.txtIt consist's of two parts, firstly I have to extract the news from my database, and secondly I have to display this data.I have chosen to display the latest 10 newest posts. Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/ Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 if line 8 is[code]$query = "SELECT title, news FROM nyheter WHERE id = $_GET['id']"; [/code]then try[code]$query = "SELECT title, news FROM nyheter WHERE id = {$_GET['id']}"; [/code] Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-134606 Share on other sites More sharing options...
alen Posted December 4, 2006 Author Share Posted December 4, 2006 Now I get:Notice: Undefined index: id in path/path/rediger.php on line 8You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-134818 Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 that'll be because you havent got an 'id' in the URL. tack on a rediger.php?id=1 or something to your URL and try it out. you'll need to decide what you want to do in the event that 'id' hasnt been passed in the URL, and put in a check to handle it before you query the DB Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-134821 Share on other sites More sharing options...
alen Posted December 4, 2006 Author Share Posted December 4, 2006 I tried rediger.php?id=1 and then I got this:Table 'nyheter.nyheter' doesn't existWhere do I ask for the nyheter.nyheter table? Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-134904 Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 on this line:[code]<?php$query = "SELECT title, news FROM nyheter WHERE id = $_GET['id']"; ?>[/code]have you actually made a database table called nyheter yet? Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-134909 Share on other sites More sharing options...
Hypnos Posted December 4, 2006 Share Posted December 4, 2006 [code]mysql_select_db ($db_name) or die ("Databasen er imidlertid nede."); [/code]Replace with:[code]mysql_select_db($db_name) or die("Databasen er imidlertid nede."); [/code] Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-134911 Share on other sites More sharing options...
alen Posted December 4, 2006 Author Share Posted December 4, 2006 Of course I have a database named nyheter.. and the table is named news.. However, the query should be getting something! Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-134927 Share on other sites More sharing options...
keeB Posted December 4, 2006 Share Posted December 4, 2006 Then your code would be[code=php:0]$query = "SELECT * FROM news WHERE id = {$_GET['id']}"; [/code] Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-134936 Share on other sites More sharing options...
alen Posted December 4, 2006 Author Share Posted December 4, 2006 Hey it works! Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-135164 Share on other sites More sharing options...
alen Posted December 4, 2006 Author Share Posted December 4, 2006 How would I make the newest posts be listed on the rediger.php site? From 1 to 10.. Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-135171 Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 assuming you've got a column/field for the date, then something like:[code]<?php$query = "SELECT * FROM news WHERE id = {$_GET['id']} ORDER BY date DESC LIMIT 10";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-135178 Share on other sites More sharing options...
alen Posted December 4, 2006 Author Share Posted December 4, 2006 This is how my edit script looks like right now,http://anigma.sitees.com/rediger.txtandhttp://anigma.sitees.com/lagre.txtI keep getting a notice error..[b]Notice:[/b] Undefined index: id in [b]rediger.php[/b] on line [b]8[/b]Should I just get this away with, error_reporting(E_ALL ^ E_NOTICE); ? Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-135181 Share on other sites More sharing options...
alen Posted December 4, 2006 Author Share Posted December 4, 2006 Yes I have a field/column for the date, but I got this,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 'ORDER BY date DESC LIMIT 10' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-135183 Share on other sites More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 you could, but it's best to deal with your errors rather than hide them. especially as considering your query, an undefined index (and hence no value) would make your query fail. ([b]edit[/b] which is what your reply you just posted has shown)replace the query line with the following:[code]<?phpif (isset($_GET['id'])){ $query = "SELECT * FROM news WHERE id = {$_GET['id']}";}else{ $query = "SELECT * FROM news ORDER BY date DESC LIMIT 10";}?>[/code]which means if an ID is passed in the URL (notice the 'isset' check), then that record will be picked and displayed. otherwise, the latest 10 records order by most recent first will be displayed.cheersMark Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-135186 Share on other sites More sharing options...
alen Posted December 5, 2006 Author Share Posted December 5, 2006 That was better, but... I want to have links on the rediger.php site to each post.Let's say this is the page:rediger.php :Random test (the first post i posted)Whatever (the second)etc...And then I want to make each title to a link like rediger.php?id=1 (which is Random test since it was the first post i posted), and then I click on the title and then I would be able to edit/save the content. Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-135210 Share on other sites More sharing options...
alen Posted December 5, 2006 Author Share Posted December 5, 2006 Are we on the same page on this? Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-135213 Share on other sites More sharing options...
Mr.x Posted December 5, 2006 Share Posted December 5, 2006 [code]$content = mysql_query("SELECT * FROM news WHERE id = {$_GET['id']}")while ($row = mysql_fetch_assoc($content)) {echo "<a href='rediger.php?id=".$row['id']."'>".$row['title']."</a> <br>";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-135317 Share on other sites More sharing options...
alen Posted December 5, 2006 Author Share Posted December 5, 2006 How would I put that together with the rest of the code? Quote Link to comment https://forums.phpfreaks.com/topic/29353-parse-error/#findComment-135426 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.