Solved

php echo error... why? easy easy question for someone who knows...

Posted on 2006-06-13
9
289 Views
Last Modified: 2010-04-17
echo "<FORM ACTION='process_addkeyword.php' METHOD=POST>\n";
echo "<div>New Keyword: <INPUT type="text" name="keyword" /></div>\n";

$sCategoryList = "SELECT DISTINCT sCategoryName FROM sCategories ORDER BY sCategoryName";
$sCategoryResult = mysql_query($sCategoryList) or die("Couldn't execute query.");

I get an error on the second line

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

I'm trying to do an html form here.. i think this is probably rediculously easy to fix and that I'm missing the finner points of echo .. could someone enlighten me here..
0
Comment
Question by:cstormer
  • 6
  • 3
9 Comments
 

Author Comment

by:cstormer
ID: 16897762
ok, i got the errors to go away it looks like " and ' have importance... a new question..

$sCategoryList = "SELECT DISTINCT sCategoryName FROM scategories ORDER BY sCategoryName";
$sCategoryResult = mysql_query($sCategoryList) or die("Couldn't execute query.");
echo '<div><SELECT name= "sCategory">\n';
while ($row = mysql_fetch_array($sCategoryResult))
{
      extract($row);
      echo "<option value='$sCategory'>$sCategory\n";
}
echo '</select>';

My dropdown list is blank... it drops the correct number of fields but there is nothing in the list.. any thoughts?
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 16897791
cstormer,

The problem is the quote marks that are used in the tag with the attributes.  You should make the line like this ...

echo "<div>New Keyword: <INPUT type=\"text\" name=\"keyword\" /></div>\n";

The back slash will comment the double quote so that it doesn't close the string.  You could also use a line like this replacing the beginning and ending double quote with a single quote.

echo '<div>New Keyword: <INPUT type="text" name="keyword" /></div>\n';

Let me know if you have a question or need more information.

b0lsc0tt
0
 

Author Comment

by:cstormer
ID: 16897835
ok so it's good to know i need to escape the quotes but that doesn't 100% explain the problem with this line..

{
     extract($row);
     echo "<option value='$sCategory'>$sCategory\n";
}

my query works, but it doesn't actually show anything in the drop down box that it creates.. there are 5 items in the database and it displays a 5 item drop down list that is empty.. that is kind o fhow i know the query works... it seems something is wrong with that option line.. that doesn't let the value display in a browser?
0
 

Author Comment

by:cstormer
ID: 16897847
if what i just doesn't make sense here is a link..

http://zeus.chrisstormer.com/addkeyword.php
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 500 total points
ID: 16897920
Try changing the line to this ...

     echo '<option value="' . $sCategory . '">' . $sCategory;

Use double quotes to make sure that your HTML tags are valid and surround the strings with single quotes.  You also need to concatenate the strings and the variables.  That is what the period does in the line above.  It will combine a string with another string or a variable.  Notice that I close the string after the double quotes (value=") and then use a period to add the variable.  I continued with that same idea for the rest of that line.  You should not need the line break (\n) until after the closing option tag.  The complete line could look like this ...

     echo '<option value="' . $sCategory . '">' . $sCategory . '</option>\n';

Let me know if you have any questions or need more information.
0
 

Author Comment

by:cstormer
ID: 16898006
So I put this linke in like you said.. and I see what you mean about opening and closing the ' and concatenating the strings and variables... but
the problem is the list is still displaying empty.. it's like it kind of see's the values in the database (it makes a drop down menu of 5) but it returns blank results.. what could possibly explain this..
0
 

Author Comment

by:cstormer
ID: 16898022
I feel like maybe i'm doing something wrong with my query?

$sCategoryList = "SELECT DISTINCT sCategoryName FROM scategories ORDER BY sCategoryName";
$sCategoryResult = mysql_query($sCategoryList) or die("Couldn't execute query.");
echo '<div><SELECT name= "sCategory">\n';
while ($row = mysql_fetch_array($sCategoryResult))
{
      extract($row);
      echo '<option value="' . $sCategory . '">' . $sCategory . '</option>\n';
}

0
 

Author Comment

by:cstormer
ID: 16898067
Thanks for all the help.. i went back and started again and rewrote and found what i did wrong :) Thanks!!
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 16898095
Your welcome!  I'm glad that I could help.  Thank you for the grade, the points and the fun question.

bol
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 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

22 Experts available now in Live!

Get 1:1 Help Now