Just want to check my code to see if I wrote them right. If wrong please correct me

Create a cfif block that checks for the condition:
IsDefined("url.productid") AND NOT IsDefined("form.productid") --- so I wrote

<cfif IsDefined("url.productid") AND NEQ IsDefined("form.productid")>

Create a ciff block that checks for the condition:
if url.action is defined and form.action is not defined
Inside the block, assign url.action to form.action ----so I wrote

<cfif IsDefined(url.action) AND IsDefined(form.action) NEQ "1">

Create a cfif block that checks for getCartItems.quantity is greater than 0.
If the quantity is greater than 0, assign getCartItems.quantity + 1 to variables.quantity .
Otherwise, assign 1 to variables.quantity ---- so I wrote

<cfif getCartItems.quantity GT 0 AND getCartItems.quantity + 1 to variables.quantity>

Typically if you can you should try to create Boolean test conditions. I will show you what I would do for each situation you have listed:

Create a cfif block that checks for the condition:
IsDefined("url.productid") AND NOT IsDefined("form.productid") --- so I wrote

<cfif IsDefined("url.productid") AND NEQ IsDefined("form.productid")>

Below I put your test condition in a cfscript tag because it runs faster if your script is going to be longer than a few lines. Also using "NEQ" before IsDefined will probably throw an error though I have not tested it.

<cfscript>
	if ( IsDefined("url.productid") AND NOT IsDefined("form.productid") ) {
		do_something = true;
	}
</cfscript>

Create a ciff block that checks for the condition:
if url.action is defined and form.action is not defined
Inside the block, assign url.action to form.action ----so I wrote

<cfif IsDefined(url.action) AND IsDefined(form.action) NEQ "1">

There are a few problems with the above:
1.) You forgot to put quotes around "url.action" and "form.action"
2.) You don't need to put quotes around numeric values.
3.) AND IsDefined(form.action) NEQ "1" is not syntactically correct. It should be something like:

<cfscript>
	if ( IsDefined("url.action") AND NOT IsDefined("form.action") ) {
		do_something = true;
	}
</cfscript>

Create a cfif block that checks for getCartItems.quantity is greater than 0.
If the quantity is greater than 0, assign getCartItems.quantity + 1 to variables.quantity .
Otherwise, assign 1 to variables.quantity ---- so I wrote

<cfif getCartItems.quantity GT 0 AND getCartItems.quantity + 1 to variables.quantity>

You don't want to test getCartItems.quantity and increment variables.quantity within the condition part of a cfif block. Incrementing variables.quantity is the result of "getCartItems.quantity GT 0" being true.

You will notice I put the val() function around any variables that are supposed to be numeric. I've found by doing so guarantees that when I'm doing a numeric test that I'm always testing against numeric values. Also, any string variables inside of the val function will be 0 if they cannot be converted to numeric.

<cfscript>
	if ( val(getCartItems.quantity) GT 0) {
		variables.quantity = val(getCartItems.quantity) + 1;
	}
</cfscript>

I hope this helps!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.