Jump to content

Error in my syntax


bullbreed

Recommended Posts

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();
	}
}

 

Link to comment
https://forums.phpfreaks.com/topic/191419-error-in-my-syntax/
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/191419-error-in-my-syntax/#findComment-1009160
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/191419-error-in-my-syntax/#findComment-1009177
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.