[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Transitioning to PDO/MySQL.  Need assistance with if/else statement

Posted on 2014-12-21
5
Medium Priority
?
308 Views
Last Modified: 2014-12-21
Are changes necessary for if/else statements in PHP/PDO?

I am getting the following error:
Parse error: syntax error, unexpected 'catidexp1' (T_STRING)

(Script works fine without if/else statement)



$query3 = $conn->query('SELECT DISTINCT cat1, catidexp1 FROM download ORDER BY catidexp1);

while ($row3 = $query3->fetch(PDO::FETCH_ASSOC))
{

 if $row3['catidexp1']==0 {      //error here
continue; 
} else {



$statement = $conn->prepare('INSERT INTO category (category_id) VALUES(:catid)');
$params = array(':catid'=>$row3['catidexp1']);
$statement->execute($params); 

}

Open in new window

0
Comment
Question by:lawrence_dev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 1800 total points
ID: 40512197
Is that your real code?
You are missing the closing apostrophe
$query3 = $conn->query('SELECT DISTINCT cat1, catidexp1 FROM download ORDER BY catidexp1');

Open in new window


Also don't put prepared statements inside a loop, put them before you loop - their purpose is to tell MySQL what to expect, not keep telling it what is coming...

$statement = $conn->prepare('INSERT INTO category (category_id) VALUES(:catid)');
0
 
LVL 17

Assisted Solution

by:Chris Millard
Chris Millard earned 200 total points
ID: 40512199
Change line 6 to:-

 if ($row3['catidexp1']==0) {
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40512208
Parse error: syntax error, unexpected ...
always means something is wrong "upstream" from the line with the error.  It may be the line above or a line many lines above.  Typically this is due to missing or unmatched parentheses, quotes, etc.

This has nothing to do with PDO, per se -- it's a PHP syntax error that may have been introduced by a conversion from MySQL to a current SQL extension, but looking to PDO for an answer is a red herring.  Instead, go back to the basic PHP syntax and you'll find the error through that process.
0
 

Author Closing Comment

by:lawrence_dev
ID: 40512231
Agreed Gary!  Thanks for your help!  Thanks Chris!
0
 

Author Comment

by:lawrence_dev
ID: 40512264
Take 30 seconds to look at the code to see the mistake and point it out. ---  100% Agree!  Thanks again for your help!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question