0

Hi, I want to update one of my tables in a database, when the user checks the checkbox.
I am running update query for the same.When I echo that query, I came to know that it is not taking the checkbox name .. Can someone please help me out with this..
here's the code

echo "<table border=1 align=center>";
        echo "<tr>";

        while($row = mysql_fetch_array($sellexe);)
        {
    echo "<td colspan='3' align='right'><input type='checkbox' name='scow'>Sell"
         }
        echo "<td><input type='submit' name='submit' value='submit'></td>";
        echo "</tr>";
        echo "</table>";

$se = $_POST[scow];
//cho "$se";
        if(isset($_POST['submit']))
    {
        $inssell = "UPDATE `farmlogin` SET `sellcow` = '$se' WHERE `cowid`='$id'";
        //echo "$inssell";
        $s = mysql_query($inssell);
    }

Edited by Reverend Jim: Fixed formatting

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by vibhaJ
0

You will only have value in $se = $_POST[scow]; if that checkbox is checked and form is submitted.
and value must be there for checkbox field.and whatever is value will be comes in $se. here $se will be 1.

echo "<td colspan='3' align='right'><input type='checkbox' value='1' name='scow'>Sell"

Edited by vibhaJ: n/a

0

You will only have value in $se = $_POST[scow]; if that checkbox is checked and form is submitted.
and value must be there for checkbox field.and whatever is value will be comes in $se. here $se will be 1.

echo "<td colspan='3' align='right'><input type='checkbox' value='1' name='scow'>Sell"

I made the changes.. but still nothing $se is not taking any value..

0

You may wanna double check you're not missing the '' in POST? As in your example.

0

Debug code using printing post array.And post your output.
BTW where is your form tag as this code is partial?

<?
	echo "<table border=1 align=center>";
	echo "<tr>";
	
	while($row = mysql_fetch_array($sellexe)
	{
	echo "<td colspan='3' align='right'><input type='checkbox' name='scow'>Sell"
	}
	echo "<td><input type='submit' name='submit' value='submit'></td>";
	echo "</tr>";
	echo "</table>";
	
	$se = $_POST[scow];
	//cho "$se";
	if(isset($_POST['submit']))
	{
		echo '<pre>';
		print_r($_POST);
		exit;
		
	$inssell = "UPDATE `farmlogin` SET `sellcow` = '$se' WHERE `cowid`='$id'";
	//echo "$inssell";
	$s = mysql_query($inssell);
	} 
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.