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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.