Hi,
The following script contains a form in which the user should enter data into three fields namely:
sTitles sInformation and sAuthor On the user filling in these input fields, the submit button is to be pressed. Herein lies my problem. On pressing of the submit button I need the following task to be accomplished –
§ Firstly, the details from the above fields are entered into a database (via the my_sql query $sql_createNew_Survey.
§ (On insertion of the data into the database, the variable $SurveyID is assigned a value which is gained from the function mysql_insert_ID.)
§ I need the submit button to enter the data into the database, then forward the user to the next php script (called Survey_Created.php).
THIS IS THE MOST IMPORTANT POINT-
§ the value of $Survey ID needs to be available on the following script Survey_Created.php. Can someone help!?
How do I achieve this? What is wrong with my code? Can anyone help…?
Thanks for taking the time to read this!!!!
Create_a_New_Survey.php...
<?
#echo "<FORM METHOD=GET ACTION =\"Survey_Created.php\">";
Enter Survey Title
echo "Title of Survey: <BR>\n";
echo "<INPUT TYPE=\"text\" NAME=\"sTitle\" SIZE=\"30\"><BR>";
echo "<BR><BR>\n\n";
#Enter Information and Instructions
echo "Information and Instructions of Survey:<BR>\n" ;
echo "<TEXTAREA NAME=\"sInformation\" ROWS=\"15\" COLS =\"50\" WRAP =VIRTUAL>";
echo "</TEXTAREA><BR>\n";
echo "<BR>\n";
#Enter Survey Author...
echo "Author of Survey:<BR>\n";
echo "<INPUT TYPE = \"text\" NAME =\"sAuthor\" SIZE =\"20\"><BR>\n";
echo "<BR>\n";
#check all fields have entries
if($sTitle and $sInformation and $sAuthor)
{
#connect to mySql
$conn = @mysql_connect("localhost", "root", "") or die("Err@Db");
#select database
$rs=@mysql_select_db("surveydb",$conn) or die ("Err:Db");
#create query
$sql_createNew_Survey="INSERT INTO tbl_survey(Title, Info_Instructs, Author) VALUES(\"$sTitle\", \"$sInformation\", \"$sAuthor\")";
#execute query
$rs_newSurvey = mysql_query($sql_createNew_Survey, $conn);
$SurveyID=mysql_insert_ID();
#creating queries to insert into the lastSurvey table...
$sql_lastSurvey_UPDATE = "UPDATE tbl_lastSurvey SET last_newID = \"$SurveyID\" WHERE Num = 1";
#executing query...
$rs_lastSurvey_UPDATE = mysql_query($sql_lastSurvey_UPDATE, $conn);
echo "<INPUT TYPE = \"HIDDEN\" NAME = \"SurveyID\" VALUE =$SurveyID>";
}
#SUBMIT & RESET Buttons...
echo "<INPUT TYPE = \"SUBMIT\" VALUE=\"Submit\">";
echo "<INPUT TYPE = \"RESET\" VALUE =\"Reset\">";
Herein lies my problem THIS IS THE MOST IMPORTANT POINT-