tomm098 Posted May 5, 2010 Share Posted May 5, 2010 Hey everyone. I'm having a slight problem with a Question Answer forum which is stored in a mySQL database. I have two seperate tables, one for Questions, one for Answers. Each Question has a unique ID. When someone answers a question it is assigned that Questions ID. All that is fine.. But I cannot get the answers to appear below the corresponding Questions. The insert record works fine and they have the same ID's but will the answers will not display because they are from different tables I think. The answers have a recordset filter with a form variable. I think if i can set a form variable to the Question ID's they will show up. But im not sure how to do that? Here is the form <form id="form6" name="form6" method="POST" action="<?php echo $editFormAction; ?>"> <p><span class="question"><?php echo $row_QA['Question']; ?></span><br /> <span class="answer"><?php echo $row_Answer['Answer']; ?></span> </p> <p> <input name="Answer" type="text" id="Answer" value="add your own answer" /> <input name="QuestionID" type="text" id="QuestionID" value="<?php echo $row_QA['ID']; ?>"/> <input name="User" type="hidden" id="User" value="tomm098" /> <input type="hidden" name="MM_insert" value="form6" /> <input type="submit" name="Submit" id="Submit" value="Submit" /> </p> </form> Here is the insert record PHP <?php if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form6")) { $insertSQL = sprintf("INSERT INTO Answers (QuestionID, Answer, `User`) VALUES (%s, %s, %s)", GetSQLValueString($_POST['QuestionID'], "int"), GetSQLValueString($_POST['Answer'], "text"), GetSQLValueString($_POST['User'], "text")); mysql_select_db($database_test, $test); $Result1 = mysql_query($insertSQL, $test) or die(mysql_error()); } ?> and here is the recordset for the Answers filter $colname_Answers = "-1"; if (isset($_POST['QuestionID'])) { $colname_Answers = $_POST['QuestionID']; } mysql_select_db($database_test, $test); $query_Answers = sprintf("SELECT Answer, `User` FROM Answers WHERE QuestionID = %s", GetSQLValueString($colname_Answers, "int")); $Answers = mysql_query($query_Answers, $test) or die(mysql_error()); $row_Answers = mysql_fetch_assoc($Answers); $totalRows_Answers = mysql_num_rows($Answers); ?> Hopefully I have been clear enough. Thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/200757-setting-a-form-variable/ Share on other sites More sharing options...
harristweed Posted May 5, 2010 Share Posted May 5, 2010 where is the function GetSQLValueString defined? Quote Link to comment https://forums.phpfreaks.com/topic/200757-setting-a-form-variable/#findComment-1053418 Share on other sites More sharing options...
tomm098 Posted May 5, 2010 Author Share Posted May 5, 2010 Is this what you mean if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } Quote Link to comment https://forums.phpfreaks.com/topic/200757-setting-a-form-variable/#findComment-1053419 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.