You are here: error checking woes « PHP « IT news, forums, messages
error checking woes

Posted by Jack Jackson on 07/30/05 15:17

Hi,
Now that the drop down is working properly (thanks!!), I am trying to
validate, and having LOTS of trouble. After being ceaselessly derided
last night on an irc channel for my dimwitedness, I am still not any closer.

The code which works is this:

function GetQuestionsDropdown($cat){
//first get all the questions

$sql = "SELECT * FROM questions WHERE questions.q_cat=$cat AND
questions.q_style=1";

$result = mysql_query($sql);
//now one-by-one go through the questions
while($row = mysql_fetch_assoc($result)) {

//if the form has been submitted, and the question unanswered
//highlight this whole question and answer block in red.
if ($message[$row['q_name']] == 1){
echo "<div class='error'>";
}

//Make a question set div wrapper
echo "<div class='q_set'>\n";
//State the question
echo "<div class='question'>";
echo $row['q_text'] . "</div>";
echo "\n\n";
echo " <div class='answer'>";
echo "\n";

//Create the dropdown for the answers
echo ' <select name="' . $row['q_name'] . '">';
echo "\n";

//get all of the answers for THIS question
$ans_sql = "select * from answers where answers.q_id=" . $row['q_id'];
$ans_result = mysql_query($ans_sql);

echo " <option value=\"\">Select from this list</option>\n";
while($ans_row = mysql_fetch_assoc($ans_result)) {

//list the answers for THIS question
echo " <option ";
echo "value=\"" . $ans_row['a_id'] . "\"";

if ($row['q_name'] == $ans_row['a_id']) {
echo " selected";
}

echo ">" . $ans_row['a_answer'] . "</option>";
echo "\n";
}
echo ' </select>' . "\n" . ' </div>' . "\n";
echo "</div><!--q_set-->\n\n";
//If there *was* an error div, close it
if (sizeof($message[$row['q_name']])){
echo "</div><!--/error-->";
}
}
}//function GetQuestionsDropdown


NOW I have to validate after it's submitted. I am trying to look and
see, if $_POST[$row['q_name']] is empty then make message of the same
name = 1, so if

if(empty($_POST['partners'])) {
$message['partners'] = '1'
}

Then when I restate the dropdown function, and it shows the questions
again, those error checking things I built in will
a) show a div class=error around questions with a message
b) pre-select the previously selected answers (because I have put in
the thing in the dropdown which says

if ($row['q_name'] == $ans_row['a_id']) { echo " selected";}


The validate code I was trying, the subject of such howling on IRC (and
I know it doesn't work, but not why) was:

function ValidatePost($cat){
//first get the q_names
$sql = "SELECT * FROM questions WHERE q_cat=$cat";
$result = mysql_query($sql);

//go through the question set
while($row = mysql_fetch_assoc($result)) {

if(empty($_POST[$row['q_name']])){

$message[$row['q_name']] == "1";
}
}
}//function ValidatePost

Can anyone tell me what I am doing wrong?

Thanks!
JJ

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация