hello
following is my code to add data to database from selecting checkbox bt its not working can u plz help me????
suggest ny changes asap
thnks in advance

<?php
mysql_connect("localhost","root","")or die(mysql_error());
//echo"connection with mysql";

mysql_select_db("cater") or die(mysql_error());
//echo"database cater connected";

foreach ($_POST['check'] as $k=>$c)
$query="select * from wed_sweets";
$result=mysql_query($query) or die(mysql_error());
if($_POST['submit']=='submit')
{
{
    if($c=='on')
    {
    while($k=mysql_fetch_array($result))
{

        echo"$row[FName] "."$row[LName]";
        echo "$row[item_name]"."$row[price]";
}

    }
}

}
?>

afte foreach statment you must use curly braces to cover all below code, right now
$query="select * from wed_sweets"; statement will be called in loop.

<?php
mysql_connect("localhost","root","")or die(mysql_error());
//echo"connection with mysql";

mysql_select_db("cater") or die(mysql_error());
//echo"database cater connected";

foreach ($_POST['check'] as $k=>$c)
{ //i added this brace
$query="select * from wed_sweets";
$result=mysql_query($query) or die(mysql_error());
if($_POST['submit']=='submit')
{
{
    if($c=='on')
    {
    while($k=mysql_fetch_array($result))
{

        echo"$row[FName] "."$row[LName]";
        echo "$row[item_name]"."$row[price]";
}

    }
}

}
} //i added this brace
?>

hi there. I created HTML and PHP file to filter web form data based on multiple drop down filters. Here goes the form. when i run the form and PHP, i don't see any results in the browser. There is no error either. I am working on a example posted by another forum member. pls. see code above

<form action="showJobs_new.php" method="post">
    <select name="Locations">
    <option value="" selected="selected">All Locations</option>
    <option value="arizona">Arizona</option>
    <option value="alaska">Alaska</option>
    </select>
    <select name="Jobs">
    <option value="" selected="selected">All jobs</option>
    <option value="Carpenter">Carpenters</option>
    <option value="Plumbers">Plumbers</option>
    </select>
    <input type="submit" value="search jobs" />
    </form>

    showJobs_new.php:

    <html>
    <body>

    <?php

    $username="root";
    $password="password";
    $database="test";

    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");

    $whereClauses = array(); 
    if (! empty($_POST['Locations'])) $whereClauses[] ="Locations='".mysql_real_escape_string($_POST['Locations'])."'"; 
    if (! empty($_POST['Jobs'])) $whereClauses[] ="Jobs='".mysql_real_escape_string($_POST['Jobs'])."'"; 
    $where = ''; 
    if (count($whereClauses) > 0) { $where = ' WHERE '.implode(' AND ',$whereClauses); } 

    $sql = mysql_query("SELECT * FROM mytable ORDER BY id DESC $limit" .$where);  

    $result=mysql_query($sql);

    while ($row = mysql_fetch_assoc($result)) {
    echo $row['Locations'];
    echo $row['Jobs'];
    }

    ?>
    </body>
    </html>

@urtrivedi
Sry bt its nt running

On submission just see if the checkbox isset and if so execute a standard SQL query?

Also this: ny changes asap is really rude and arrogant. people help eachother here in their own free will - you're just registering for free help with takes the piss out of this awesome community.

Moving on...

When form is submit blah blah blah{

// some submission stuff here

if (isset($_POST['checkbox_id'])) {
            // Do query here
        }else{
            // Do something else
        } 

// some submission stuff here

    }

Hope it helps

There is a slim chance my last post could have issues with IE 6,7 and 8 but not 100% sure.

@mmcdonald m sry if u feel my rudeness bt m also in damn presure of submission of my project sry again
my project submission is on thursday nd i hv tried all d things
if u dnt wanna help u can

its nt working

commented: <?php mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("campusarena") or die(mysql_error()); ?> <?php $query="SELECT * FROM `sss` WHERE `id` = 3"; $result=mysql_query($query)or die("cannot select DB"); $num=mysql_numrows +1

<?php
mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("campusarena") or die(mysql_error());

?>
<?php
$query="SELECT * FROM sss WHERE id = 3";
$result=mysql_query($query)or die("cannot select DB");
$num=mysql_numrows($result);
while($row = mysql_fetch_array($result))

$a= $row['java'];
$b= $row['php'];
$c= $row['net'];
$d= $row['oracle'];
$e= $row['redhat'];

echo "<br/>";
if($a==1) echo "<img style='height:60px;width:100px;' src='java.gif'>";
if($b==1) echo "<img style='height:60px;width:100px;' src='1.png'> ";
if($c==1) echo "<img style='height:60px;width:100px;' src='4.png'> ";
if($d==1) echo "<img style='height:60px;width:100px;' src='orc.png'> ";
if($e==1) echo "<img style='height:60px;width:100px;' src='red.jpg'> ";
?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.