I have a contact form that utilizes a table of questions and answers, instead of a visual confirmation. They are stored in a mySQL db, in ISAM id, order. For each one there is a question and answer in the table:
1 question1 answer1
2 question2 answer2
3 question3 answer3
etc.....
I open the database, then read the table with this code:
//$rs = mysql_query("select question, answer from question_table order by rand() limit 1");
//$row = mysql_fetch_array($rs);
$rs = mysql_query("select * from question_table order by rand() limit 1");
$row = mysql_fetch_array($rs);
$randomq=$row[question];
$randoma=$row[answer];
echo "rs=";
echo $rs;
echo "<br>";
echo "row=";
echo $row;
echo "<br>";
echo "randomq=";
echo $randomq;
echo "<br>";
echo "randoma=";
echo $randoma;
Throughout the process, I use these same echoes to try to see where the problem is.
My result for $rs is always rs=Resource id #4
My result for $row is always row=Array
My result for randomq & randoma are questions and answers in the table. I know they are random because when I refresh, they change. So, they are showing up okay. My problem is when I click on the Submit button for the contact input form, they change. So, they kick out an error message in which I have embedded echoes to displa them. I cannot figure out how they change, since the only other code that even utilizes them is the original code that displays the question (which displays fine) and asks the users to input the answer; and the echoes to put them out in an error message, if there is an error. The change is random in order (not the next one in the array or the last one in the array). But, it is always the correct answer for the correct question, so I know it is the entire row that is changing.
I am really new at php, so I am hoping I am just being stupid and forgetting something obvious.
Thanks for any help you can give me. Take Care, Sharon