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
422 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
exchange ,script 10 52
MySQL Memory Keeps Increasing 4 47
MYSQL responding very slow 3 26
Powershell Exchange mailboxsizes 3 11
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

821 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