hey so im trying to save data but i get error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE event_id = '8'' at line 1

this being the line:
$sql = mysql_query("INSERT INTO event(guest_num) VALUES('$total') WHERE event_id = '".$event_id."' ") or die(mysql_error());

php:

if(isset($_POST['save']) && isset($_POST['check']) )
{
    foreach($_POST['check'] as $insert_id)
    {
        require "connection.php";
        $total = mysql_real_escape_string($_POST['ttlg']);
        $event_id = mysql_real_escape_string($_POST['event']);
        $sql = mysql_query("INSERT INTO event(guest_num) VALUES('$total') WHERE event_id = '".$event_id."' ") or die(mysql_error());
        $name1 = mysql_real_escape_string($_POST['gname']);
        $insert_id = (int)$insert_id;
        $guest = mysql_query("INSERT INTO guest VALUES('$insert_id','$name1','".$event_id."','')") or die(mysql_error());
    }
}

html:

<form method="post" action="add_guest.php">
    <div class="dropdown">
        <label>Choose an Event : <label/>
        <select name="event" id="event">
            <option value="" disabled selected>Choose</option>
            <?php
                echo $events;
            ?>
        </select>
    </div>
    <table class="tablesorter add-guest" id="add-g">
    <thead>
        <tr>
            <th data-priority="critical">Name</th>
            <th class="columnSelector-false" data-priority="5">Spouse</th>
            <th class="columnSelector-false" data-priority="6">Children</th>
        </tr>
    </thead>
    <tbody>
        <?php
            require "connection.php"; 
            $check = mysql_query("SELECT contact_id,salutation,primary_name,s_name,ch_name FROM contact") or die(mysql_error());
            $count=mysql_num_rows($check); 
            if($count > 0)
            {
                while($rows = mysql_fetch_array($check))
                {
                    $id = $rows['contact_id'];
                    $salutation = $rows['salutation'];
                    $name = $rows['primary_name'];
                    $sname = $rows['s_name'];
                    $cname = $rows['ch_name'];

                    echo 
                    "<tr>
                        <td ><input type='checkbox' name='check[]' value='$id' id='add'><input type='hidden' name='gname' value='$salutation $name' />$salutation $name </td><td><input type='checkbox' name='check[]' id='add'><input type='hidden' name='gname' value='$sname' />$sname</td><td><input type='checkbox' name='check[]' id='add'><input type='hidden' name='gname' value='$cname' />$cname</td>
                    </tr>";
                }
            }   
            else
            {
                echo 
                "<tr>
                    <td colspan='6'>Contact Database is empty.</td>
                </tr>";
            }   
        ?>
    </tbody>
</table>
<div class="totalg">
        Total Guest : <input type="text" name="ttlg" id="ttlg-count" readonly>
        <br>
        <input type="submit" name="save" value="Save" />
    </div>
</form>

It is complaining because you have a 'where' clause at the end of an insert statement.

You will want to change it to INSERT INTO event(guest_num) VALUES('$total'). You would only need a where clause if you were trying to update or select (pretty much where you need to check existing data before performing the operation).

oh... okay. thanks kwiering.

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.