Solved

I've searched everywhere on the net and can't find anything close to an answer for my problem

Posted on 2013-07-01
15
420 Views
Last Modified: 2013-07-01
I am having two major problems that need to be fixed by tomorrow:  
1. "You have an error in your SQL syntax near "Karen' (and a couple of others) at line 7".  (Code to follow)
2. The dropdown options don't show up on the webpage (form) although when clicking down arrow and blindly selecting an option and submitting the form, it shows the correct option in the error message.

<select size="1" name="SalesPerson">
			<option selected>Select One</option>
<option value="Karen"<?php if ($row["ColumnName"] == "Karen") echo " SELECTED "; ?>Karen</option>
<option value="Nanette"<?php if ($row["ColumnName"] == "Nanette") echo " SELECTED "; ?>Nanette</option>
<option value="Jenny"<?php if ($row["ColumnName"] == "Jenny") echo " SELECTED "; ?>Jenny</option>
<option value="Mary Ann"<?php if ($row["ColumnName"] == "Mary Ann") echo " SELECTED "; ?>Mary Ann</option>
<option value="Don"<?php if ($row["ColumnName"] == "Don") echo " SELECTED "; ?>Don</option>
<option value="Ira"<?php if ($row["ColumnName"] == "Ira") echo " SELECTED "; ?>Ira</option>
<option value="Stephen"<?php if ($row["ColumnName"] == "Stephen") echo " SELECTED "; ?>Stephen</option>
<option value="Ronnie"<?php if ($row["ColumnName"] == "Ronnie") echo " SELECTED "; ?>Ronnie</option></select>

Open in new window

0
Comment
Question by:phase3studios
  • 8
  • 7
15 Comments
 
LVL 23

Expert Comment

by:nemws1
ID: 39291224
Well, I see no SQL here, so you'll have to post whatever query you are trying to run as well.  Maybe have your script dump it out as HTML to your page before it runs the query (even as an HTML comment) so we can see the data.  I'm guessing you're missing a quote or double-quote.

As for your options, you are missing the greater than sign after you print out whether or not that option should be selected.  )This is pretty clear if you look at the generated HTML):

<form>
<select size="1" name="SalesPerson">
                        <option selected>Select One</option>
<option value="Karen"<?php if ($row["ColumnName"] == "Karen") echo " SELECTED "; ?>>Karen</option>
<option value="Nanette"<?php if ($row["ColumnName"] == "Nanette") echo " SELECTED "; ?>>Nanette</option>
<option value="Jenny"<?php if ($row["ColumnName"] == "Jenny") echo " SELECTED "; ?>>Jenny</option>
<option value="Mary Ann"<?php if ($row["ColumnName"] == "Mary Ann") echo " SELECTED "; ?>>Mary Ann</option>
<option value="Don"<?php if ($row["ColumnName"] == "Don") echo " SELECTED "; ?>>Don</option>
<option value="Ira"<?php if ($row["ColumnName"] == "Ira") echo " SELECTED "; ?>>Ira</option>
<option value="Stephen"<?php if ($row["ColumnName"] == "Stephen") echo " SELECTED "; ?>>Stephen</option>
<option value="Ronnie"<?php if ($row["ColumnName"] == "Ronnie") echo " SELECTED "; ?>>Ronnie</option>
</select>

Open in new window

0
 
LVL 23

Accepted Solution

by:
nemws1 earned 500 total points
ID: 39291229
Sorry... I now see your "code to follow" for the SQL error.  Please post and we'll take a look at it. :)

(Just to clarify as well.. you were not closing your opening <Option> tag.  If you look at your original code again and count less than signs versus greater than signs per line, this will become very clear.)
0
 

Author Closing Comment

by:phase3studios
ID: 39291408
Thanks, you're right about the option tag close.  Below is the query info.  I am a real newbie and am trying to get this to work.  I've had others to help but still get this message:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘Mary Ann', ContactName = ‘sdgsgsg', JobName = ‘gsgsg', Job_Address = ‘' at line 7"

Query:

 // Connects to your Database

 mysql_connect("deleted", "deleted", "deleted") or die(mysql_error());

 mysql_select_db("aaaeeeiii") or die(mysql_error());

 



//Find if the SO Number already exists.

$sql = "SELECT COUNT(*) as Cnt ";

$sql .= " FROM workorder";

$sql .= " WHERE SONumber = '$SONumber'";



$result = mysql_query($sql) or die(mysql_error());

while ($row = mysql_fetch_array($result))   {

    $Cnt       = $row["Cnt"];

}



if ($Cnt == 0) {

  //we don't have SO Number -- create it!

  $sql = "INSERT INTO workorder (SONumber) VALUES ('$SONumber')";

  mysql_query($sql)  or die(mysql_error());

}



  //service order found or created

  $sql = "UPDATE workorder SET

    PO = '$PO',

      ServiceDate = '$ServiceDate',
      
      SalesPerson = ‘$SalesPerson',
      
      ContactName = ‘$ContactName',
      
      JobName = ‘$JobName',
      
      Job_Address = ‘$Job_Address',
      
      ContactPhone = ‘$ContactPhone',
      
      TechName = ‘$TechName',
      
      Customer = ‘$Customer',
      
      Customer_Address = ‘$Customer_Address',
      
      Bill_City = ‘$Bill_City',
      
      Customer_State = ‘$Customer_State',
      
      Zip = ‘$Zip',
      
      CustomerEmail = ‘$CustomerEmail',
      
      AP_Phone = ‘$AP_Phone',
      
      AP_Fax = ‘$AP_Fax',
      
      APEmail = ‘$APEmail',
      
      Exempt = ‘$Exempt',
      
      Resale = ‘$Resale',
      
      Expire_Date = ‘$Expire_Date',
      
      WO_Cancelled = ‘$WO_Cancelled',
      
      aei_1 = ‘$aei_1',
      
      Part_1 = ‘$Part_1',
      
      aei_2 = ‘$aei_2',
      
      aei_20 = ‘$aei_20',
      
      aei_3 = ‘$aei_3',
      
      Part_2 = ‘$Part_2',
      
      aei_4 = ‘$aei_4',
      
      aei_21 = ‘$aei_21',
      
      aei_5 = ‘$aei_5',
      
      Part_3 = ‘$Part_3',
      
      aei_6 = ‘$aei_6',
      
      aei_22 = ‘$aei_22',
      
      aei_7 = ‘$aei_7',
      
      Part_4 = ‘$Part_4',
      
      aei_8 = ‘$aei_8',
      
      aei_23 = ‘$aei_23',
      
      aei_9 = ‘$aei_9',
      
      Part_5 = ‘$Part_5',
      
      aei_10 = ‘$aei_10',
      
      aei_24 = ‘$aei_24',
      
      Notes = ‘$Notes',
      
      New_Quote = ‘$New_Quote',
      
      aei_11 = ‘$aei_11',
      
      SLabor1 = ‘$SLabor1',
      
      aei_12 = ‘$aei_12',
      
      aei_25 = ‘$aei_25',
      
      aei_13 = ‘$aei_13',
      
      SLabor2 = ‘$SLabor2',
      
      aei_14 = ‘$aei_14',
      
      aei_26 = ‘$aei_26',
      
      aei_15 = ‘$aei_15',
      
      SLabor3 = ‘$SLabor3',
      
      aei_16 = ‘$aei_16',
      
      aei_27 = ‘$aei_27',
      
      Other1 = ‘$Other1',
      
      aei_28 = ‘$aei_28',
      
      Other2 = ‘$Other2',
      
      aei_29 = ‘$aei_29',
      
      Other3 = ‘$Other3',
      
      aei_30 = ‘$aei_30',
      
      aei_45 = ‘$aei_45',
      
      aei_32 = ‘$aei_32',
      
      aei_41 = ‘$aei_41',
      
      aei_40 = ‘$aei_40',
      
      aei_43 = ‘$aei_43',
      
      aei_42 = ‘$aei_42',
      
      aei_50 = ‘$aei_50'


      WHERE SONumber = '$SONumber'";

   mysql_query($sql)  or die(mysql_error());





?>
  Thank you so much for your help.
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39291460
Right before this line:
mysql_query($sql)  or die(mysql_error());

Open in new window


put this:

print "<PRE>";
print $sql;
print "</PRE>";

Open in new window


Try your form again and then post the first part (should be the first 5-6 lines) of the SQL command that gets printed that is failing.

I can't quite tell from the code what the problem is.
0
 

Author Comment

by:phase3studios
ID: 39291520
Thank you!  I did that and here is what came back:
SELECT COUNT(*) as Cnt  FROM workorder WHERE SONumber = '0720131 -  16 '
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘Jenny', ContactName = ‘wwgggwrg', JobName = ‘wergwergwerg', Job_Addres' at line 7
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39291530
Well, the 'print $sql' is in the wrong spot.

I need it to print out whatever statement (I'm guessing its the UPDATE statement) is causing the above error.

Whatever gets printed out should contain "Jenny" and "wwgggwrg" etc.... (the same things as what the error is printing out)
0
 

Author Comment

by:phase3studios
ID: 39291532
would it help if I posted the form address?  Thank you so much for being nice!
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:phase3studios
ID: 39291555
let me move it and get back to you.  Thanks
0
 

Author Comment

by:phase3studios
ID: 39291578
I am sorry, but moving the 'print $sql' higher only gives this:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘Select One', ContactName = ‘', JobName = ‘', Job_Address = ‘', Cont' at line 7

is there something I am doing wrong?
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39291594
Well, yes, because its not printing what I want to see. ;-)  I wouldn't call that "wrong" though.

Maybe you need to move it down.  Between these two lines, which is after your UPDATE command.

      WHERE SONumber = '$SONumber'";

   mysql_query($sql)  or die(mysql_error());

Open in new window

0
 

Author Comment

by:phase3studios
ID: 39291628
I did that exactly and here is what came back:

SELECT COUNT(*) as Cnt  FROM workorder WHERE SONumber = '1234567'
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘Select One', ContactName = ‘', JobName = ‘', Job_Address = ‘', Cont' at line 9
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39291639
Something wonky is going on.  It's obvious that that SELECT statement doesn't have 'ContactName' in it, so its printing the wrong query.

Can you e-mail me your PHP script (remove username/password/etc.)?  nemws1<the symbol for an e-mail address>gmail.com
0
 

Author Comment

by:phase3studios
ID: 39291648
Absolutely!
0
 

Author Comment

by:phase3studios
ID: 39291790
I would like to thank nemws1!  You have helped tremendously!   I couldn't have done it, otherwise! Blessings to you!
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39291797
You're welcome. :)
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Install MySQL 5.6 and PHP on Centos Linux 6 101
Active DirectoryScript to change the Pager Field 1 49
Powershell Script need assistance to make some changes 4 63
xampp tool 12 28
This article will show, step by step, how to integrate R code into a R Sweave document
Creating and Managing Databases with phpMyAdmin in cPanel.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now