/    Sign up×
Community /Pin to ProfileBookmark

Multiple if else statements

Hi i have a multiple if else statement which enters the first line of information but that is it. The script doesn’t error or anything it just deosn’t enter the information. I have tested all the variables and the information is passed to this page correctly and if i echo the individual variables the correct information is displayed.

Below is the statements.

[code=php]

if (isset($model)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model’, ‘$name’, ‘$price’, ‘$qty’, ‘$total’, ‘$non’) “)
or die(mysql_error());

}

elseif (isset($model1)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model’, ‘$name’, ‘$price’, ‘$qty’, ‘$total’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model2)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model2’, ‘$name2’, ‘$price2’, ‘$qty2’, ‘$total2’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model3)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model3’, ‘$name3’, ‘$price3’, ‘$qty3’, ‘$total3’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model4)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model4’, ‘$name4’, ‘$price4’, ‘$qty4’, ‘$total4’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model5)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model5’, ‘$name5’, ‘$price5’, ‘$qty5’, ‘$total5’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model6)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model6’, ‘$name6’, ‘$price6’, ‘$qty6’, ‘$total6’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model7)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model7’, ‘$name7’, ‘$price7’, ‘$qty7’, ‘$total7’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model8)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model7’, ‘$name7’, ‘$price7’, ‘$qty7’, ‘$total6’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model8)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model8’, ‘$name8’, ‘$price8’, ‘$qty8’, ‘$total8’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model9)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model9’, ‘$name9’, ‘$price9’, ‘$qty9’, ‘$total9’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model10)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model10’, ‘$name10’, ‘$price10’, ‘$qty’10, ‘$total10’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model11)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model11’, ‘$name11’, ‘$price101’, ‘$qty11’, ‘$total11’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model12)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model12’, ‘$name112’, ‘$price112’, ‘$qty112’, ‘$total12’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model13)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model13’, ‘$name13’, ‘$price13’, ‘$qty13’, ‘$total13’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model14)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model14’, ‘$name14’, ‘$price14’, ‘$qty14’, ‘$total14’, ‘$non’) “)
or die(mysql_error());
}

elseif (isset($model15)) {

mysql_query(“INSERT INTO products (Product_Code, Product_Name, Price, Qty, Total, Order_Number) VALUES(‘$model15’, ‘$name15’, ‘$price15’, ‘$qty15’, ‘$total15’, ‘$non’) “)
or die(mysql_error());
}

[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Aug 26.2010 — Did you turn error reporting on? Are you sure you connected to the db first (mysql_connect)?
Copy linkTweet thisAlerts:
@NogDogAug 26.2010 — i have a multiple if else statement which enters the first line of information but that is it.[/quote]
By using if/elseif/elseif..., only the first condition that matches will execute. All others will be skipped after that first match. If you want all conditions that match to execute, use [b]if[/b] for each one, not [b]elseif[/b].

PS: Assuming that is the case, it would be more efficient to build a comma-separated set of VALUES() clauses, then just execute a single mysql_query().
×

Success!

Help @stn003 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...