Author Topic: Error in my syntax  (Read 324 times)

0 Members and 1 Guest are viewing this topic.

Offline bullbreedTopic starter

  • Enthusiast
  • Posts: 109
  • Gender: Male
    • View Profile
Error in my syntax
« on: February 08, 2010, 05:35:53 PM »
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();
	
	
}
	
}

When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.

Offline corrupshun

  • Enthusiast
  • Posts: 80
    • View Profile
Re: Error in my syntax
« Reply #1 on: February 08, 2010, 05:39:23 PM »
did you get an error?
<?php
if(isset($_POST['troll'])) {
echo 'GTFO';
}
?>

Offline bullbreedTopic starter

  • Enthusiast
  • Posts: 109
  • Gender: Male
    • View Profile
Re: Error in my syntax
« Reply #2 on: February 08, 2010, 05:46:41 PM »
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

When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.

Offline jl5501

  • Devotee
  • Posts: 728
  • Gender: Male
  • PHP Freelancer
    • View Profile
Re: Error in my syntax
« Reply #3 on: February 08, 2010, 05:48:28 PM »
missing some brackets

"INSERT INTO articles (`article_section`)  VALUES ('$existcat')"
Secure forms without Captcha

Offline bullbreedTopic starter

  • Enthusiast
  • Posts: 109
  • Gender: Male
    • View Profile
Re: Error in my syntax
« Reply #4 on: February 08, 2010, 06:01:24 PM »
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
« Last Edit: February 08, 2010, 06:02:35 PM by bullbreed »
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.

Offline bullbreedTopic starter

  • Enthusiast
  • Posts: 109
  • Gender: Male
    • View Profile
Re: Error in my syntax
« Reply #5 on: February 08, 2010, 06:37:34 PM »
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
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.

Offline bullbreedTopic starter

  • Enthusiast
  • Posts: 109
  • Gender: Male
    • View Profile
Re: Error in my syntax
« Reply #6 on: February 09, 2010, 04:57:05 AM »
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  :wtf:
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.