Page 1 of 1

Checkbox value same when being sent to DB

Posted: Fri Jun 27, 2008 11:55 am
by josephman1988
Form:

Code: Select all

<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
Client Name: <br /><input type="text" name="name" /><br /><br />
Client Site: <br /><input type="text" name="exchange" /><br /><br />
Client Bio: <br />
<textarea name="ClientBio" cols="100" rows="20"></textarea>
<br />
<br />
Client Pic: (Type Their Name (No Spaces))<br /><input type="text" name="pic" /><br /><br />
Client Demo: (Type Their Name (No Spaces))<br /><input type="text" name="demo" /><br /><br />
What Events is this Artist available for (Seperate With Commas):<br /><input type="text" name="events" /><br /><br />
 
<?php
 
$cat = @mysql_query("SELECT id, name FROM categories");
 
while ($catResult = mysql_fetch_array($cat))
 
    {
    $cid = $catResult['id'];
    $catname = $catResult['name'];
    echo "<label><input type='checkbox' name='cat[]' value='$cid' /> $catname </label><br />";
    }
 
?>
<br /><br />
Type Of Act Ticked Above: <br /><input type="text" name="type" /><br /><br />
<input type="submit" name="Submit" value="Add Client" /> <input type="reset" name="Reset" Value="Reset" />
</form>
 
<?php
 
$ClientName = $_POST['name'];
$ClientBio = $_POST['bio'];
$ClientPic = $_POST['pic'];
$ClientExchange = $_POST['exchange'];
$ClientDemo = $_POST['demo'];
$ClientEvents = $_POST['events'];
$ClientType = $_POST['type'];
$clientSQL = @mysql_query("INSERT INTO clients SET
        name = '$ClientName',
        bio = '$ClientBio',
        pic = '$ClientPic',
        exchange = '$ClientExchange',
        events = '$ClientEvents',
        demo = '$ClientDemo',
        type = '$ClientType',
        categoriesid = '$cid'
        ");
        
    
 
?>
After this is submitted, the value ALWAYS comes out with 5 (Adult Entertainment) whether I tick this box or not.

What have i missed?
Thanks.

Re: Checkbox value same when being sent to DB

Posted: Thu Jul 03, 2008 7:35 am
by sureshmaharana
Hi,

categoriesid = '$cid', this is ur mistake.

In while condition you are initializing the value of $cid and at the time of insert you are inserting the $cid, so $cid will always give last value..