Forum Moderators: coopster
echo '<p>Countries I\'d Like to Work in * <select name="preferinte_tari" multiple size="7">
';
$cerereSQL = 'SELECT nume_tara FROM tari';
$rezultat = mysql_query($cerereSQL);
while($rand = mysql_fetch_row($rezultat))
{
print("<option value=\"$rand[0]\">$rand[0]</option>");
}
echo '</select>';
the script works fine,it populate the selection box, when i press the submit button sends the data to the mysql table, doesn't return any error if i select something.
but when i don't select anything and i press submit it returns this error:
Notice: Undefined index: preferinte_tari in C:\wamp\www\au pair\autentificare\inregistrare.php on line 590
i don't understand why. this is my 590 line: $_SESSION['preferinte_tari'] = $_POST['preferinte_tari'];
also the session is started in a config.php file which is called at the begining of the script.
this is my script:
<?php
require_once('config.php');
if(!isset($_GET['actiune'])) $_GET['actiune'] = '';
if(!isset($_SESSION['preferinte_tari'])) $_SESSION['preferinte_tari'] = '';
switch($_GET['actiune'])
{
case '':
echo '<p><form name="formular" action="inregistrare.php?actiune=validare" method="post">Countries I\'d Like to Work in * <select name="preferinte_tari" multiple size="7">
';
$cerereSQL = 'SELECT nume_tara FROM tari';
$rezultat = mysql_query($cerereSQL);
while($rand = mysql_fetch_row($rezultat))
{
print("<option value=\"$rand[0]\">$rand[0]</option>");
}
echo '</select>';
echo '<p align="justify"><input name="Submit" type="submit" id="Submit" value="Submit"></p>
</form>';
break;
case 'validare':
$_SESSION['preferinte_tari'] = $_POST['preferinte_tari'];
if(($_SESSION['preferinte_tari'] == ''))
{
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`(`preferinte_tari`) VALUES( '".addentities($_SESSION['preferinte_tari'])."')";
mysql_query($cerereSQL) or die (mysql_error());
$_SESSION['preferinte_tari'] = '';
}
break;
}
?>
can you tell me please where i go wrong?
while (list($key, $val) = each ($Type)) {
$insertSQL = sprintf("INSERT INTO yourtable (yourfield) VALUES (%s)",
GetSQLValueString($val, "text"));
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error()); and other examples like that but i didn't manage to send the info to database.