bullbreed Posted February 8, 2010 Share Posted February 8, 2010 Hi. php newbie here. Could someone please tell me the error in this syntax if ($existcat != ""){ $queryreg = mysql_query("INSERT INTO articles (`article_section` VALUES '$existcat')");echo mysql_error(); }else{ if ($existcat = 'None'){ $queryreg = mysql_query("INSERT INTO articles (`article_section` VALUES '$newcat')");echo mysql_error(); } } Quote Link to comment Share on other sites More sharing options...
corrupshun Posted February 8, 2010 Share Posted February 8, 2010 did you get an error? Quote Link to comment Share on other sites More sharing options...
bullbreed Posted February 8, 2010 Author Share Posted February 8, 2010 Yes, t said 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 'VALUES 'shorts')' at line 1 Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 8, 2010 Share Posted February 8, 2010 missing some brackets "INSERT INTO articles (`article_section`) VALUES ('$existcat')" Quote Link to comment Share on other sites More sharing options...
bullbreed Posted February 8, 2010 Author Share Posted February 8, 2010 Thanks for that. I can now submit the form but it adds 2 rows to the database What im trying to do is this I have a news article system on my site and when the admin wants to add an article he can either select a category from a drop down menu or create a new category Hence if ($existcat != ""){ $queryreg = mysql_query("INSERT INTO articles (`article_section`) VALUES ('$existcat')");echo mysql_error(); }else{ if ($existcat == ""){ $queryreg = mysql_query("INSERT INTO articles (`article_section`) VALUES ('$newcat')");echo mysql_error(); } } The $existcat variable is a menu form field and has an empty value as default but also echos the column of the database that holds the categories So what im trying to achieve is someting like; If the $existcat has no value then they must have selected someting below the empty value so put it in the article_section column If the $existcat does have no value then check the other form field called $newcat and store that value in the article_section column Quote Link to comment Share on other sites More sharing options...
bullbreed Posted February 8, 2010 Author Share Posted February 8, 2010 Has anyone added a category to a news article section before? The reason I want a category associated with the articles is so the visitor can easily find the articles they want. e.g. if it was a golfing website the article section could have hundreds of articles but if they were sorted by category they would be easier to find. Category = Clubs Article about clubs no 1 Article about clubs no 2 Article about clubs no 3 Category = Drivers Article about drivers no 1 Article about drivers no 2 Article about drivers no 3 Quote Link to comment Share on other sites More sharing options...
bullbreed Posted February 9, 2010 Author Share Posted February 9, 2010 It doesnt put the category variable in to the article_section column of the database and creates 2 rows of info in the db? Not sure why. Well I have an idea. My code is rubbish Quote Link to comment 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.