Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Need help with escape characters!? SQL query in $form

Codes here !

Moderators: macek, egami, gesf

Need help with escape characters!? SQL query in $form

Postby lsg3385 » Fri Mar 14, 2003 5:45 pm

I have always used html then <? enclosed phpcode?>. I just read about using $form= then putting the whole form in the string, great for checking for entered data.. BUT I am stuck on something probably very easy. I have a list box in this form. If I have hard coded entries it is fine, but if I include the sql query to populate the list box I get an error "Parse error: parse error, unexpected T_STRING" on the Query statement. I think it is probably a simple thing, but I am stuck!!
Here is the code:
$form = "<form action=\"test.php\" method=\"post\">
<form name=\"Create\" method=\"post\" action=\"addStudent.php\">
<input type=\"hidden\" name=\"seenform\" value=\"y\">
<p>Enter Student's Last Name:<input type=\"text\" name=\"slname\" maxlength=\"30\" size=\"30\" value=\"$studentLastName\"></p>
<p>Assign Student to a Group:
select name=\"groupID\">
:oops: (this next line causes the error)
$listGroups_query = mysql_query("SELECT mathgroup.groupID, mathgroup.groupName from mathgroup");
while($listGroups_record = mysql_fetch_array($listGroups_query)) {

<option value=\"$groupID"\"> $groupName </option>
}
</select><br>
<input type=\"submit\" value=\"subscribe!\">
</form>";
// has the form already been filled in?
if ($seenform != "y"):
print "$form";
lsg3385
New php-forum User
New php-forum User
 
Posts: 5
Joined: Fri Mar 14, 2003 5:35 pm

Postby Romantik » Sat Mar 15, 2003 1:17 am

Code: Select all
$listGroups_query = mysql_query('SELECT mathgroup.groupID, mathgroup.groupName from mathgroup');

or
Code: Select all
$listGroups_query = mysql_query(\"SELECT mathgroup.groupID, mathgroup.groupName from mathgroup\");
Romantik
New php-forum User
New php-forum User
 
Posts: 67
Joined: Mon Feb 24, 2003 2:55 am
Location: ../Ukraine/Kherson

Need more help on syntax: EASY I'm sure!! (but Im confused)

Postby lsg3385 » Sat Mar 15, 2003 9:56 am

Assign Student to a Group:
<select name=\"groupID\">
$listGroups_query = mysql_query(\"SELECT mathgroup.groupID, mathgroup.groupName from mathgroup\");
while($listGroups_record = mysql_fetch_array($listGroups_query)) {

I generally would use the following, but that causes errors::(
<option value=\"<?=$listGroups_record[\"groupID\"]?>\"> <?=$listGroups_record[\"groupName\"]?> </option>

I tried using this: and that doesnt cause an error but I dont get anything in the list box: :oops:
<option value=\"$groupID\"> $groupName </option>
}
</select><br>
</form>";
lsg3385
New php-forum User
New php-forum User
 
Posts: 5
Joined: Fri Mar 14, 2003 5:35 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron