Jump to content

[SOLVED] $_Post Problem


savagenoob

Recommended Posts

I am submitting the test name via post and the test names have spaces in them, during the submit, the post does not recognize anything after a space and its driving me crazy. Such as Quiz 5, only comes through as Quiz. Here is some code....

 

$qname = $_POST['qname']; // This is the problem...

if (isset($_POST['newquiz']) && ($myname != $qname))
{

$select = mysql_query("INSERT INTO pq_quizname SET Name = '$qname'");
echo mysql_error();
echo "Added successfully";
echo "<meta http-equiv=Refresh content=3;url=quizadd.php>";
}
else
{

?>
<table>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="newquiz">
<tr><th>New Quiz</th></tr>
<tr><th>Quiz Name</th><td><input name="qname" type="text" size="20" maxlength="40" /></td></tr>
<tr><td><input type="submit" name="newquiz" value="Next"></td></tr>
</form>
</table>
<?php
}
?>
<?php 
require_once('config.php');
//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false;

//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");
}
$query = mysql_query("SELECT * FROM pq_quizname");
	while($row = mysql_fetch_assoc($query))
	{
		$showtest[] = $row['Name'];
	}

?>
<table>
<form action="takequiz.php" method="post" name="taketest">
<tr><th>Take a test</th></tr>
<tr><td>Test </td><td><?php echo '<SELECT name=testname>';
foreach ($showtest as $key => $value) {
    echo '<OPTION value=' . $value . '> ' . $value . '';
}
echo '</select>'; ?></td><td>Number of questions</td><td><input name="numques" type="text" size="3" maxlength="4" /></td></tr>
<tr><td><input type="submit" name="takequiz" value="Take Test"></td></tr>
</form>
</table>

Link to comment
https://forums.phpfreaks.com/topic/151193-solved-_post-problem/
Share on other sites

I am not 100% sure this will take care of it.... but I would start with valid HTML

 

 

 

....... echo '<SELECT name="testname">';
foreach ($showtest as $key => $value) {
    echo '<OPTION value="' . $value . '"> ' . $value . '';
}
echo '</select>'; ?>< ...........

 

I believe that attribute values in HTML are supposed to have quotes around them. I don't think it matters whether it is single or double quotes.... just put quotes around and I believe that it will fix it.

 

Nate

Link to comment
https://forums.phpfreaks.com/topic/151193-solved-_post-problem/#findComment-794240
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.