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
419 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

707 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

14 Experts available now in Live!

Get 1:1 Help Now