Forum Moderators: coopster

Message Too Old, No Replies

submit a dropdown list selection generated from mysql to a mysql datab

         

bogdanb

10:24 am on May 8, 2008 (gmt 0)

10+ Year Member



hi
i have this case.
one register page with several fields that users have to complete.
one or more fields are dropdown list generated from amysql database.
i have difficulties submiting those selection.
here is the code i use.
<?php
require_once('config.php');

if(!isset($_GET['actiune'])) $_GET['actiune'] = '';
if(!isset($_SESSION['user'])) $_SESSION['user'] = '';
if(!isset($_SESSION['localitate'])) $_SESSION['localitate'] = '';
switch($_GET['actiune'])
{
case '':

echo '<table width="309" border="0" cellpadding="0" cellspacing="0">
<form name="formular" action="inregistrare.php?actiune=validare" method="post">
<tr>
<td height="36" colspan="4" valign="top"><h1>Formular inregistrare </h1></td>
</tr>
<tr>
<td width="80" height="19" valign="top">&nbsp;</td>
<td width="15" rowspan="5" valign="top"></td>
<td width="144" valign="top">&nbsp;</td>
<td width="70" valign="top">&nbsp;</td>
</tr>
<tr>
<td height="22" align="right" valign="top">Utilizator:</td>
<td colspan="2" valign="top">
<input type="text" name="user" value="'.$_SESSION['user'].'"> </td>
</tr>
<tr>
<td colspan="2" valign="top">';
echo '<p>Localitate <select name="localitate">';

$cerereSQL = 'SELECT valoare FROM localitate_register';
$rezultat = mysql_query($cerereSQL);

while($rand = mysql_fetch_row($rezultat))
{
print("<option value=\"$rand[0]\">$rand[0]</option>");
}
echo '</select>';
echo' </td>
</tr>
<tr>
<td height="19">&nbsp;</td>
<td valign="top"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="24">&nbsp;</td>
<td valign="top"></td>
<td colspan="2" valign="top"><input name="Trimite" type="submit" id="Trimite" value="Trimite">
<input name="Reseteaza" type="reset" id="Reseteaza" value="Reseteaza"> </td>
</tr>
<tr>
<td height="24">&nbsp;</td>
<td valign="top"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</form>
</table>';
break;

case 'validare':

$_SESSION['user'] = $_POST['user'];
$_SESSION['localitate']= $_POST['localitate'];
if(($_SESSION['user'] == '') ¦¦ ($_SESSION['localitate'] == ''))
{
echo 'Nu ai introdus date in formular sau cele introduse nu sunt corecte. <br>
Apasa <a href="inregistrare.php">aici</a> pentru a te intoarce la pagina anterioara.';
}
else
{
echo 'Va multumim. <br>
Datele au fost introduse cu succes in baza de date. <br>
Pentru a va autentifica apasati <a href="autentificare.php">aici</a>.';

$cerereSQL = "INSERT INTO `utilizatori` (`utilizator`, `localitate`)
VALUES ('".addentities($_SESSION['user'])."', '".addentities($_SESSION['localitate'])."’)";
mysql_query($cerereSQL);
$_SESSION['user'] = '';
$_SESSION['localitate'] = '';
}

break;

}

?>
if i remove "localitate" field from form everything works great.
the script doesn't return any error.
when i press the submit button i receive the "OK message".
If i want to log in with the new created user i can't because there is no data recorded in the database.
can you help me pls?

jatar_k

12:22 pm on May 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld bogcanb,

my first thought would be to add an 'or die' statement to your insert

mysql_query($cerereSQL) or die (mysql_error());

that will give you the error back from mysql if there is one, let's try that first

bogdanb

2:17 pm on May 8, 2008 (gmt 0)

10+ Year Member



thank you verry much
you are my hero
thanks thanks thanks
it was an ` instead of a '.
great forum. i will ask again if i will need help.
the problem was here '".addentities($_SESSION['localitate'])."’)";
it should be '".addentities($_SESSION['localitate'])."')";
great place!

jatar_k

2:19 pm on May 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



nice catch, glad to help