gadgetster Posted January 3, 2014 Share Posted January 3, 2014 I followed this tutorial: http://blog.calendarscripts.info/phpmysql-tutorial-classifieds-software-in-1-hour/ and i keep getting an error. i am simply trying to get a classified ads service going i attached the php files and folders any help is appreciated! test.zip Quote Link to comment https://forums.phpfreaks.com/topic/285051-help-with-classified-ads-code/ Share on other sites More sharing options...
mac_gyver Posted January 3, 2014 Share Posted January 3, 2014 i keep getting an error. posting the error message, with the line number mentioned in it, would allow someone to help you. as it is, all you are have done is dump your code on a forum and that won't get you much help since we don't have the slightest idea what you saw in front of you that would narrow down the problem. Quote Link to comment https://forums.phpfreaks.com/topic/285051-help-with-classified-ads-code/#findComment-1463667 Share on other sites More sharing options...
gadgetster Posted January 3, 2014 Author Share Posted January 3, 2014 it tells me there is an error in line 2 of category.php, there is supposedly an extra ' ( ', but when i check that line it is just a class function and nothing seems to be wrong with it ps. maybe there is a better php classified ads tutorial around? Quote Link to comment https://forums.phpfreaks.com/topic/285051-help-with-classified-ads-code/#findComment-1463672 Share on other sites More sharing options...
cyberRobot Posted January 3, 2014 Share Posted January 3, 2014 It might help to post the code instead of attaching a ZIP file. When posting code, please surround it with tags. Also, when PHP says there's an error on a specific line, it doesn't always mean that the error is on that line. Perhaps something before line 2 is causing the issue. Quote Link to comment https://forums.phpfreaks.com/topic/285051-help-with-classified-ads-code/#findComment-1463687 Share on other sites More sharing options...
gadgetster Posted January 3, 2014 Author Share Posted January 3, 2014 i posted it in my first post, i copied every code from: http://blog.calendarscripts.info/phpmysql-tutorial-classifieds-software-in-1-hour/ it is the exact same and i do not know why the error appears Quote Link to comment https://forums.phpfreaks.com/topic/285051-help-with-classified-ads-code/#findComment-1463722 Share on other sites More sharing options...
mac_gyver Posted January 3, 2014 Share Posted January 3, 2014 the category class definition is incorrect. it should start with - <?php class Category { Quote Link to comment https://forums.phpfreaks.com/topic/285051-help-with-classified-ads-code/#findComment-1463729 Share on other sites More sharing options...
gadgetster Posted January 3, 2014 Author Share Posted January 3, 2014 the category class definition is incorrect. it should start with - <?php class Category { ok, i fixed that and i get the following error: syntax error, unexpected 'list' (T_LIST), expecting identifier (T_STRING) in C:\wamp\www\test\models\category.php on line 43 here is my models/category.php code: <?php class Category { function __construct() { // for this tutorial there will be nothing inside this method // in the real app you could possibly add some initialization } function add($name) { $this->filter($name); $q="INSERT INTO categories (name) VALUES (\"$name\")"; mysql_query($q) or die(mysql_error()); } function edit($name, $id) { $this->filter($name); // add some basic security if(!is_numeric($id)) exit; $q="UPDATE categories SET name=\"$name\" WHERE id='$id'"; mysql_query($q); } // category name allows only alphanumeric private function filter($name) { $name=preg_replace("/\W/","",$name); return $name; } function delete($id) { if(!is_numeric($id)) exit; $q="DELETE FROM categories WHERE id='$id'"; mysql_query($q); } // method to list the categories for admin edit/delete function list() { $q="SELECT * FROM categories ORDER BY name"; $result=mysql_query($q); $cats=array(); while($cat=mysql_fetch_array($result)) $cats[]=$cat; return $cats; } // method to return categories along with number of ads in them function list_count() { $q="SELECT COUNT(tA.id) as classifieds, tC.name as name, tC.id as id FROM categories tC LEFT JOIN classifieds tA ON tA.category_id=tC.id ORDER BY tC.name"; $result=mysql_query($q); $cats=array(); while($cat=mysql_fetch_array($result)) $cats[]=$cat; return $cats; } // method to return full category data for a single category function select($id) { if(!is_numeric($id)) exit; $q="SELECT * FROM categories WHERE id='$id'"; $category=mysql_fetch_array(mysql_query($q)); return $category; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/285051-help-with-classified-ads-code/#findComment-1463743 Share on other sites More sharing options...
mac_gyver Posted January 3, 2014 Share Posted January 3, 2014 obviously the author of that site didn't write/test this code and you should not waste any more time trying to use it unless you are trying to gain experience debugging php syntax errors. its not this forum's function to debug a bunch of syntax errors in code that was found on the Internet. Quote Link to comment https://forums.phpfreaks.com/topic/285051-help-with-classified-ads-code/#findComment-1463762 Share on other sites More sharing options...
gadgetster Posted January 4, 2014 Author Share Posted January 4, 2014 well, i need a classified ads code and I have minor knowledge in PHP and no time to learn all the database stuff so I figured I'll ask here. But wow this is a one stuck up forum. Hopefully someone can be more helpful than these two robots above Quote Link to comment https://forums.phpfreaks.com/topic/285051-help-with-classified-ads-code/#findComment-1463795 Share on other sites More sharing options...
mac_gyver Posted January 4, 2014 Share Posted January 4, 2014 your lack of time to learn the basics isn't our problem. for the basics, you need to spend your time and maybe some money to buy and read a book, take a class, hire a tutor, or study enough online tutorials to learn the prerequisite information for the task you are trying to accomplish. programming help forums are for people to get help with code they have written. if you are not at the point where you can even get past simple punctuation and language errors in any code and are just posting error after error you are getting in some code you have found, you are not at the point to even be asking for help in a programming forum, because you haven't programmed anything. you need to either a) learn enough of the programming language you are using so that you don't need to be spoon fed in post after post, or b) hire someone to write the code that does what you want. and finally, since this is some third party code and not your own, moving this thread to the Third Party Script Forum Section... Quote Link to comment https://forums.phpfreaks.com/topic/285051-help-with-classified-ads-code/#findComment-1463834 Share on other sites More sharing options...
hansford Posted January 5, 2014 Share Posted January 5, 2014 I agree with the Guru member - you need to learn the basics of programming in general and then PHP. I ran your code and there are multiple issues. You are not accessing the database columns properly for one: $cats[] = $cat should be: $cats[] = $cat['some_column_in_table'] Also, you don't use opening and closing braces properly or return values on several functions. function list() { $q="SELECT * FROM categories ORDER BY name"; $result=mysql_query($q); $cats=array(); while($cat=mysql_fetch_array($result)) $cats[]=$cat; return $cats; } should be more along the lines of this: function list() { $q="SELECT * FROM categories ORDER BY name"; $result=mysql_query($q); $cats=array(); while($cat=mysql_fetch_array($result)) { $cats[]=$cat['some_column_in_table']; } return $cats; } You should also be using PDO to access the database as your code has been deprecated and will not work in PHP future releases. Quote Link to comment https://forums.phpfreaks.com/topic/285051-help-with-classified-ads-code/#findComment-1463927 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.