Page 1 of 1
Jump menu firing blanks
Posted: Mon Feb 09, 2009 10:44 pm
by JW09
I've created one form which submits to a sql and another form which lists text entered into first form. Can select data in second form. The problem is the second form doesn't write selected field to sql but I know it writes because it changed from a value to a blank. I think it's resorting to original option which is blank.
This has all been done with a forum. Here's the forum
http://www.eoaa.org/entvent.info/forum/index.php
usename
test
password
12345678
Go to Profile, there you see two new sections "Submit vent" and "Choose vent". Only the first field Top five musicians works for Submit vent, put text in there and then go to "Choose vent", your test is included. When you select field from Choose vent and submit it fires a blank to database.
Here's the code for the menu ..
Code: Select all
include 'ventChoose.php';
<form action="', $scripturl, '?action=profile2" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data">
<SELECT NAME=T5a_musicians>
<option value="ID"', ($context['member']['T5a_musicians']['name'] == '1' ? ' selected="selected"' : ''), '>', $mus, '</option>
</SELECT>';
And here's ventChoose.php
Code: Select all
$sql="SELECT ID, musicians FROM xxxx order by musicians";
$result=mysql_query($sql);
$mus="";
while ($row=mysql_fetch_array($result)) {
$ID=$row["id"];
$musicians=$row["musicians"];
$mus.="<OPTION VALUE=\"$id\">".$musicians;
}
?>
I know there's some mistakes, I think it needs little fine tuning and it's there. Please help, this is the last hurdle and it's been a three day marathon!
Re: Jump menu firing blanks
Posted: Tue Feb 10, 2009 12:01 am
by sparrrow
From first glance, I will tell you that PHP vars are case sensitive. So $id is not the same as $ID or $Id. Try changing either line 8 or 10 of your second code block to use the same variable and see how that goes.
Re: Jump menu firing blanks
Posted: Tue Feb 10, 2009 12:25 am
by JW09
The ID relates to a field name in MySQL. Table consists of musicians and ID. Not sure why it needs ID though. I've searched all over and cannot find someone wanting to do the same thing. The reason I don't want to let them input direct to their profile is because there could be ten people all saying the same thing but with different characters. If I make them look first if their field already exists, if it doesn't they create it and then they choose it for thier profile. It's essentially two tables, one is a self creating directory and the other is specific to each member.
Re: Jump menu firing blanks
Posted: Tue Feb 10, 2009 1:06 pm
by Skoalbasher
I dunno if it matters, but when I pull something from $row, I use single quote instead of double.
$row['likethis'];
not
$row["notlikethis"];
Again, dunno if it matters because i've never tried it the second way.
Re: Jump menu firing blanks
Posted: Wed Feb 11, 2009 4:50 am
by JW09
Yes I think you're right ..
Can anyone say why this produces syntax error, unexpected $end ?
Code: Select all
<?php
echo'
<select name="T5a_musicians">
<option value="0"', ($row_vcmusicians['musicians']) ? ' selected="selected"' : '', '>', $row_vcmusicians['musicians'], '</option>';
{ while ($row_vcmusicians = mysql_fetch_assoc($vcmusicians));
$rows = mysql_num_rows($vcmusicians);
if($rows > 0) {
mysql_data_seek($vcmusicians, 0);
$row_vcmusicians = mysql_fetch_assoc($vcmusicians);
}
echo'
</select>';
?>
Re: Jump menu firing blanks
Posted: Wed Feb 11, 2009 5:09 am
by JW09
Also forgot to mention it's in a function sorry here's the entire function ..
Code: Select all
// ventChoose
function template_ventChoose()
{
global $context, $settings, $options, $scripturl, $modSettings, $txt;
include 'ventChoose.php';
echo'
<form action="', $scripturl, '?action=profile2" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data">
<select name="T5a_musicians">
<option value="0"', ($row_vcmusicians['musicians']) ? ' selected="selected"' : '', '>', $row_vcmusicians['musicians'], '</option>';
{ while ($row_vcmusicians = mysql_fetch_assoc($vcmusicians));
$rows = mysql_num_rows($vcmusicians);
if($rows > 0) {
mysql_data_seek($vcmusicians, 0);
$row_vcmusicians = mysql_fetch_assoc($vcmusicians);
}
echo'
</select>';
template_profile_save();
echo '
</table>
</td>
</tr>
</table>
</form>';
}
Re: Jump menu firing blanks
Posted: Wed Feb 11, 2009 9:49 pm
by JW09
It was because of { before while. Can anyone say why the <option> code returns a 0 (zero).
Code: Select all
function template_ventChoose()
{
global $context, $settings, $options, $scripturl, $modSettings, $txt, $row_vcmusicians;
include 'ventChoose.php';
echo'
<form action="', $scripturl, '?action=profile2" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data">
<select name="T5a_musicians">
<option value="', $row_vcmusicians['musicians'], '"', $row_vcmusicians['musicians'] == $row_vcmusicians['musicians'] ? ' selected="selected"' : '', '>', $row_vcmusicians['musicians'], '</option>';
while ($row_vcmusicians = mysql_fetch_assoc($vcmusicians));
$rows = mysql_num_rows($vcmusicians);
if($rows > 0) {
mysql_data_seek($vcmusicians, 0);
$row_vcmusicians = mysql_fetch_assoc($vcmusicians);
}
echo'
</select>';
This is a new method of populating the menu. It works in htm except I had to edit the option a bit because it's within a function. Here's the working code in htm ..
Code: Select all
<select name="T5a_musicians" id="T5a_musicians">
<?php
do {
?>
<option value="<?php echo $row_vcmusicians['musicians']?>"><?php echo $row_vcmusicians['musicians']?></option>
<?php
} while ($row_vcmusicians = mysql_fetch_assoc($vcmusicians));
$rows = mysql_num_rows($vcmusicians);
if($rows > 0) {
mysql_data_seek($vcmusicians, 0);
$row_vcmusicians = mysql_fetch_assoc($vcmusicians);
}
?>
</select>
Re: Jump menu firing blanks
Posted: Wed Feb 11, 2009 10:16 pm
by sparrrow
What do you mean by option code? Do you mean the element value or the displayed value? Is it displaying 0 in the HTML source or after it is posted? Also, seems like alot more code going on here than what is really necessary. You are referencing the result set more than once and I don't see why. Writing it like this should accomplish what you are trying to do:
Code: Select all
<select name="T5a_musicians" id="T5a_musicians">
<?php
while ($row_vcmusicians = mysql_fetch_array($vcmusicians)) {
print (<option value=\"$row_vcmusicians['musicians']\">$row_vcmusicians['musicians']</option>");
}
?>
</select>
Re: Jump menu firing blanks
Posted: Wed Feb 11, 2009 10:18 pm
by John Cartwright
You made this alot more complicated than it needs to be. You do/while block is just ..
Code: Select all
<select name="T5a_musicians" id="T5a_musicians">
<?php
if (mysql_num_rows($vcmusicians)) {
while ($row_vcmusicians = mysql_fetch_assoc($vcmusicians)) {
echo '<option value="'. $row_vcmusicians['musicians'] .'">'. $row_vcmusicians['musicians'] .'</option>';
}
}
?>
</select>
Re: Jump menu firing blanks
Posted: Wed Feb 11, 2009 11:02 pm
by JW09
sparrrow thanks, tried it and still produced 0. Also your option code looks like htm, the code I'm after is pure php i.e. all code is always php, cannot switch it on and off inbetween.
John Cartwright, you're a freaking genious thanks it works. do/while block, it's funny but I noiticed the do { in htm version and just deleted it. So the if seems to replace the do in htm. So perhaps performing a while when nothing else is doing produces a 0. Don't know but I'm slightly delirious now after spending so much time on this, I was about to try some javascript no need now.
Here's the final working code, had to adjust for pure php ..
Code: Select all
echo'
<select name="T5a_musicians">';
if (mysql_num_rows($vcmusicians)) {
while ($row_vcmusicians = mysql_fetch_assoc($vcmusicians)) {
echo '<option value="'. $row_vcmusicians['musicians'] .'">'. $row_vcmusicians['musicians'] .'</option>';
}
}
echo'
</select>';
So now I can submit to field, call same field to menu and submit menu to another table/field, superb. One thing, how would I add a selected="selected" so that after submit selected remains selected? I go look for donate button now ..
Re: Jump menu firing blanks
Posted: Wed Feb 11, 2009 11:40 pm
by John Cartwright
JW09 wrote:So now I can submit to field, call same field to menu and submit menu to another table/field, superb. One thing, how would I add a selected="selected" so that after submit selected remains selected?
While iterating the results, check against the results of $_POST (assuming your using POST, otherwise GET), and if the values match then output the selected text, i.e.
Code: Select all
echo'
<select name="T5a_musicians">';
if (mysql_num_rows($vcmusicians)) {
while ($row_vcmusicians = mysql_fetch_assoc($vcmusicians)) {
$option = '<option value="'. $row_vcmusicians['musicians'] .'"';
if (!empty($_POST['T5a_musicians']) && $row_vcmusicians['musicians'] == $_POST['T5a_musicians']) {
$option .= ' selected="selected"';
}
$option .= '>'. $row_vcmusicians['musicians'] .'</option>';
echo $option;
}
}
echo'
</select>';
JW09 wrote:I go look for donate button now ..
Please make the donation to a charity instead

Re: Jump menu firing blanks
Posted: Thu Feb 12, 2009 12:22 am
by JW09
Hm well that does the same thing, it returns to first ordered item after submit. There's quite a few other <option= in forum files so I'll search and try some things. It's picky, can use blank first option if need be. Here's the ventChoose.php code which is included in this function.
Code: Select all
<?php
$hostname_entvent = "localhost";
$database_entvent = "xx";
$username_entvent = "xx";
$password_entvent = "xx";
$entvent = mysql_pconnect($hostname_entvent, $username_entvent, $password_entvent) or trigger_error(mysql_error(),E_USER_ERROR);
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_entvent, $entvent);
$query_vcmusicians = "SELECT musicians FROM your_table ORDER BY musicians ASC";
$vcmusicians = mysql_query($query_vcmusicians, $entvent) or die(mysql_error());
$row_vcmusicians = mysql_fetch_assoc($vcmusicians);
$totalRows_vcmusicians = mysql_num_rows($vcmusicians);
?>
Here's the function in full ..
Code: Select all
// ventChoose
function template_ventChoose()
{
global $context, $settings, $options, $scripturl, $modSettings, $txt, $row_vcmusicians;
include 'ventChoose.php';
echo'
<form action="', $scripturl, '?action=profile2" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data">
<select name="T5a_musicians">';
if (mysql_num_rows($vcmusicians)) {
while ($row_vcmusicians = mysql_fetch_assoc($vcmusicians)) {
$option = '<option value="'. $row_vcmusicians['musicians'] .'"';
if (!empty($_POST['T5a_musicians']) && $row_vcmusicians['musicians'] == $_POST['T5a_musicians']) {
$option .= ' selected="selected"';
}
$option .= '>'. $row_vcmusicians['musicians'] .'</option>';
echo $option;
}
}
echo'
</select>';
template_profile_save();
echo '
</table>
</td>
</tr>
</table>
</form>';
}
Beautiful, cheers thanks again.