...

View Full Version : To allow user to change their selection after submission



laychoo135
11-22-2003, 06:30 AM
Hi

Can anyone help me with the following:
I want to allow user to be able to change their selection after submitting the form.

Previously, I have written the code in this way:

if (mysql_num_rows($result1) < 1)
{
$sql = "INSERT INTO student_activities (s_grade, s_tutorgroup, s_surname, s_forname, option1,option2,option3) VALUES ('$grade','$tutorgroup','$name2','$name1','$option1','$option2','$option3')";
$result = mysql_query($sql);
echo "Thank you! Your activities have been submitted.\n";
}

else if(mysql_num_rows($result1) > 0)
{
Echo "Sorry, you've submitted your activities options.";
}

mysql_close();
?>

How do modify the codes?

Thanks!

firepages
11-23-2003, 06:46 AM
does your table have a unique identifying field ? eg 'id'
you just need to UPDATE the right record , guessing here that you have an autoincrement column somewhere in your table...



<?
$idfield= '' ; //<<add the name of the autoincrement field here
if( mysql_num_rows( $result1 ) < 1 ){
$sql = "INSERT INTO student_activities (s_grade, s_tutorgroup, s_surname, s_forname, option1,option2,option3) VALUES ('$grade','$tutorgroup','$name2','$name1','$option1','$option2','$option3')";
$result = mysql_query( $sql );
/* grab the autoincrement value */
$insert_id = mysql_insert_id() ;
echo "Thank you! Your activities have been submitted.\n";
}else{ // no need for the else //
$sql = "UPDATE student_activities SET s_grade='$grade' , s_tutorgroup='$tutorgroup', s_surname='$name2', s_forname='$name1' , option1='$option1' , option2='$option2' , option3='$option3' WHERE $idfield=$id ";
$result = mysql_query( $sql ) ;
echo "Thank you! Your activities have been updated.\n" ;
}
mysql_close();
?>


if you do not have an automincrement id column then you need to UPDATE //blah// WHERE $unique_field = 'unique_data'

laychoo135
11-26-2003, 06:03 AM
Thanks for your reply.

There's no ID column.

I tried putting the coding as below:
if (mysql_num_rows($result1) < 1)
{
$sql = "INSERT INTO students_activities (s_grade,s_tutorgroup,s_surname,s_forename,option1,option2,option3) VALUES ('$grade','$tutorgroup','$name2','$name1','$option1','$option2','$option3')";
$result = mysql_query($sql);
echo "Thank you! Your activities have been submitted.\n";
}
else
{
$sql = "UPDATE student_activities SET s_grade='$grade',s_tutorgroup='$tutorgroup',s_surname='$name2',s_forename='$name1',option1='$option1 ',option2='$option2',option3='$option3' WHERE s_forename = '$name1' && s_surname = '$name2' && s_tutorgroup = '$tutorgroup'";
$result = mysql_query ($sql);
echo "Your activities have been updated.\n";
}

But it the new options submitted are not updated and reflected on the database.

Please advice.

laychoo135
11-26-2003, 06:14 AM
Sorry..I know why it didn't get updated and reflected on the database just nw.

A typo error in the table name.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum