Forum Moderators: coopster

Message Too Old, No Replies

POSTing the value of a listbox from a db

         

Rezznor

12:27 pm on Apr 19, 2008 (gmt 0)

10+ Year Member



This is similar to what darkenroyce and a few others have asked about, but what I have been able to get from those threads haven't really helped myself much. Here is what I have:

$dbc = @mysql_connect("localhost","username","password");
@mysql_select_db("rezznor_qtesting") or die ("Could not select the database: " . mysql_error() );
$query = "SELECT * FROM tests";
$result = mysql_query ($query);
echo "<form action = " . $_SERVER['PHP_SELF'] . " method = 'post'>";
echo 'Select test:';
echo '<select name = "testName">';
if ($result)
{
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
echo "<option value = '" . $row[1] . "'>" . $row[1] . "</option>";
}
}
echo "</select>";

Now I want to get the value of that text box and update another db table. And just to make sure something is actually being posted, I echo the variable.


$tname = $_POST['testName'];
$query1 = "UPDATE tests SET numberofQuestions = (tests.numberofQuestions + 1) WHERE testName = '" . $tName . "'";
echo $query1;
echo "<p>tName = " . $tName;

Looks like everything should work ok, but it keeps coming back with an empty result. I get
$tName =

Any ideas on what could be causing the problem?

wheelie34

1:41 pm on Apr 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



does the echo $query1 show anything? try changing this bit

WHERE testName = '" . $tName . "'
to
WHERE testName = '$tname'

edit: noticed the caps N

Rezznor

2:01 pm on Apr 19, 2008 (gmt 0)

10+ Year Member



the echo $query1 shows
UPDATE tests SET numberofQuestions = (tests.numberofQuestions+1) WHERE testName =
I'll try it the other way.