Hello Folks! New to Daniweb and programming in general! I've seen a couple other posts on this issue, but I wasn't able to sort it out with those suggestions. I'm getting the error mentioned in the subject, and I suspect it's something to do with my INSERTS/VALUES, but this is ancient code, and I'm only seeing it for the first time myself. Anyone have any suggestions for me? I've noticed I have quite a few more INSERTs than VALUES, and '$BOOTH' on line 45 looks suspect to me, but again, I'm very new and not certain. Thanks in advance!

#!/usr/local/bin/php
<?
$PageTitle = "CTS Room Input";
$SubHeader = "CTS Intranet";

$Style = "";

$Screens = $_POST['screens'];
$Boards = $_POST['boards'];

$Room = addslashes($_REQUEST['Room']);

?>

<?php require("../topper.php"); ?>

  <div id="centerwrap">
    <div id="content">

    <!-- Begin Main Text of Page -->
    <?PHP

    $Booth = $_POST['Booth'];
    if ($Booth == 'on')
    {
    $Booth = 1;
    }
    else
    {
    $Booth = 0;
    }

    $dbQuery = "INSERT INTO `MainDB` (`Campus`, `Building`, `Room`, `SeatingCap`,";
    $dbQuery .= " `RoomType`, `FloorType`, `TeachingStation`, ";
    $dbQuery .= " `Lighting`, `Windows`, `ProjectionBooth`,";
    $dbQuery .= " `AdditionalInfo`, `Contact`, `Instructions`,";
    $dbQuery .= " `AM1`, `AM2`, `AM5`, `AM6`, `AM7`, `AM12`, ";
    $dbQuery .= " `AM13`, `AM14`, `AM16`, `AM17`, `AM18`, `AM19`, `AM20`, `AM21`, `AM22`, `AM23`)"; 

    $dbQuery .= " VALUES ('" . $_POST['Campus'] . "', '" . $_POST['Building'] . "', '" . $_POST['RoomNumber'] . "', ";
    $dbQuery .= "'" . $_POST['SeatingCap'] . "', ";
    $dbQuery .= "'" . $_POST['RoomType'] . "', '" . $_POST['Floor'] . "',"; 
    $dbQuery .= "'" . $_POST['TeachingStation'] . "', ";    
    $dbQuery .= "'" . $_POST['Lighting'] . "', '" . $_POST['Windows'] . "', ";  
    $dbQuery .= "'" . $Booth . "' ,'" . $_POST['Addinfo'] . "',";   
    $dbQuery .= "'" . $_POST['Contactinfo'] . "', '" . $_POST['Instructions'] . "'";    

    if ($Room != '')
        {
        $dbQuery = "UPDATE `MainDB` ";
        $dbQuery .= "Set `Campus` = '" . $_POST['Campus'] . "', ";
        $dbQuery .= "`Building` = '" . $_POST['Building'] . "', ";
        $dbQuery .= "`Room` = '" . $_POST['RoomNumber'] . "', ";
        $dbQuery .= "`SeatingCap` = '" . $_POST['SeatingCap'] . "', ";
        $dbQuery .= "`RoomType` = '" . $_POST['RoomType'] . "', ";
        $dbQuery .= "`FloorType` = '" . $_POST['Floor'] . "', ";
        $dbQuery .= "`SeatingType` = '" . $_POST['SeatingType'] . "', ";
        $dbQuery .= "`TeachingStation` = '" . $_POST['TeachingStation'] . "', ";
        $dbQuery .= "`Lighting` = '" . $_POST['Lighting'] . "', ";
        $dbQuery .= "`Windows` = '" . $_POST['Windows'] . "', ";    
        $dbQuery .= "`Wheelchair` = '" . $Wheelchair . "', ";
        $dbQuery .= "`RegistarScheduled` = '" . $Registrar . "', ";
        $dbQuery .= "`ProjectionBooth` = '" . $Booth . "', ";
        $dbQuery .= "`AdditionalInfo` = '" . $_POST['Addinfo'] . "', ";
        $dbQuery .= "`Contact` = '" . $_POST['Contactinfo'] . "', ";
        $dbQuery .= "`Instructions` = '" . $_POST['Instructions'] . "' ";
        }

        $dbQuery2 = "Select AmenityID from AmenityDB Order by AmenityID"; 

        $table2 = "Classroom";
        require("../db2.php");
        $lastID = mysql_insert_id();


        while (mysql_Numrows($results2)>$y)                            //if there are records in the fields
        {

        $check="am" . mysql_result($results2,$y,"AmenityID"); //Find the amentities in the list.    

//      echo $check . "<br/>";

        $Data = $_POST[$check];

        if ($Data == 'on')
        {
            $Data = 1;
        }
        else
        {
            $Data = 0;
        }

    if ($Room != '')
        {
        $dbQuery .= ", `AM" . mysql_result($results2,$y,"AmenityID") . "` = '" . $Data . "' ";
        }
        else
        {
        $dbQuery .= ", '" . $Data . "'";    
        }
    $y++;
    }
    if ($Room == '')
        {   
        $dbQuery .= ")";
        }
    else
        {
        $dbQuery .= " where ID = '" . $Room . "'";
        }

//  echo $_POST['screens'];

//  print $dbQuery . "<br />";

    $table = "Classroom";
    require("../db.php");

    $lastID = mysql_insert_id();
    if ($lastID == 0)
    {
    $lastID = $Room;
    }
//----------------------------------------------------------------------------------------------------
    if ($Room != '')
    {
    $dbQuery = "Delete FROM `AmenityMainLink` WHERE MainDBID = '" . $Room . "'";

    $table = "Classroom";
    require("../db.php");
    }

    $dbQuery = "Select AmenityID from AmenityDB Order by AmenityID"; 
    $table = "Classroom";
    require("../db.php");       

    while (mysql_Numrows($results)>$x) 
    { 
        $check="am" . mysql_result($results,$x,"AmenityID"); //Find the amentities in the list.

        if ($_POST[$check]=="on")
        {

        $dbQuery2 = "INSERT INTO `AmenityMainLink` (`MainDBID`, `AmenityID`) Values (" . $lastID .", " . mysql_result($results,$x,"AmenityID") . ")"; 

        $table2 = "Classroom";
        require("../db2.php");

        }
    $x++;
    }
//------------------------------------Boards-------------------------------------------------------------------
    $x=0;

    for ($i = 1; $i <= $_POST['boards']; $i++) {

        $BLoc = "BoardLocal" . $i;
        $BL = "BoardLength" . $i;
        $BW = "BoardWidth" . $i;
        $BC = "BoardColor" . $i;

    if ($Room != '')
    {
    $dbQuery = "Delete FROM `ChalkboardDB` WHERE MainDBID = '" . $Room . "'";

    $table = "Classroom";
    require("../db.php");
    }


        if($BL!="")
        {
        $dbQuery3 = "INSERT INTO `ChalkboardDB` (`Height`, `Width`, `Position`, `MainDBID`, `ChalkType`) Values ('" . $_POST[$BL] . "', '" . $_POST[$BW] . "' , '" . $_POST[$BLoc] . "' ," . $lastID . ", '" . $_POST[$BC] . "')"; 

        $table3 = "Classroom";
        require("../db3.php");

        }   
    }
        for ($i = 1; $i <= $_POST['screens']; $i++) {

        $PLoc = "ProjectLocal" . $i;
        $PL = "ProjectLength" . $i;
        $PW = "ProjectWidth" . $i;
        $PT = "ProjectThrow" . $i;
        $PD = "ProjectDDP" . $i;
        $Ps = "Projectors" . $i;

        $PLoc = $_POST[$PLoc];
        $PL = $_POST[$PL];
        $PW = $_POST[$PW];
        $PT = $_POST[$PT];
        $PD = $_POST[$PD];
        $Ps = $_POST[$Ps];

        if ($Ps = '')
        {
        $Ps = 0;
        }
        if ($PD == 'on')
        {
        $PD = 1;
        }
        else
        {
        $PD = 0;
        }

        $PE = "ProjectElec" . $i;

        if ($PE == 'on')
        {
        $PE = 1;
        }
        else
        {
        $PE = 0;
        }

        $PC = "ProjectCSR" . $i;

        if ($PC == 'on')
        {
        $PC = 1;
        }
        else
        {
        $PC = 0;
        }

    if ($Room != '')
    {
    $dbQuery = "Delete FROM `ProjectionScreenDB` WHERE MainDBID = '" . $Room . "'";

    $table = "Classroom";
    require("../db.php");
    }

        if ($PLoc != "")
        {
        $dbQuery = "INSERT INTO `ProjectionScreenDB` (`Height`, `Width`, `Location`, `MainDBID`, `Elec`, `CSR`, `DDP`, `Projectors`) Values ('" . $PL ."', '" . $PW ."', '" . $PLoc ."', '" . $lastID ."', '" . $PE ."', '" . $PC ."', '" . $PD ."', '" . $Ps ."')"; 

        echo $dbQuery . "<br/><br/>";

        $table = "Classroom";
        require("../db.php");


        }
    }
    ?>
    <!-- End Main Text of Page -->
    The room has been added to the database.  <a href='addition.php'>Enter another</a>

    </div>
    <!-- end content -->
    <!--stopindex-->

<?php require("../footer.php"); ?>

</body>
</html>

Column count does not match value count at row 1

That means that in your query, you specified a different amount of colums before VALUES, then values after VALUES. Check your columns.

Thank you pritaeas. I suspected this was the case. So basically, all of the "AMx" columns need to also need to be represented in VALUES. Do I also need to include them in the > if ($Room != '') statement?

And does $BOOTH on line 45 correct? Thanks again!

Added to the VALUES so it matched the INSERT and still get the error?

If it does, check all INSERT queries. There has to be a discrepancy.

Thanks again. I've been out in the field for a couple weeks and will get back to this issue later this week. I've noticed it looks like someone has added to the database, but the additions are not in the code for this form. I am going to try adding in all the missing AM# VALUES, and add in the added database fields to both, and see what happens.

Alright, I've finally been able to spend some more time with this, and have narrowed it down a bit. It appears a few columns have been added to the DB and the code was not updated to reflect this. However I'm not exactly sure, how I need to update it. Now, what's interesting is, I can add the room manually in to the DB, then go back to the same form, and update it, it just seems that the form is unable to actually insert the room into the DB initially. Here is the code of the page I think is causing the problem:

#!/usr/local/bin/php
<?
$PageTitle = "CTS Secured Intranet";
$SubHeader = "CTS Intranet";

$Style = "<script type=\"text/javascript\">\n";
$Style .= "function imclicked(chkbx,spnname)\n{\n";
$Style .= "id = document.getElementById(spnname);\n";
$Style .= "if (chkbx.checked == true)\n";
$Style .= "{\n";
$Style .= "id.style.background = '#FFFF00';\n";
$Style .= "}\n";
$Style .= "else\n";
$Style .= "{\n";
$Style .= "id.style.background = 'white';\n";
$Style .= "}\n";
$Style .= "}\n";
$Style .= "</script>\n";

$Room = $_REQUEST['Room'];

if ($Room != '')
{
    $dbQuery = "Select ID, RoomType, FloorType, SeatingCap, TeachingStation, ";
    $dbQuery .= "Building, Room, RegistarScheduled, Windows, Wheelchair, Lighting, Contact, AdditionalInfo, ";
    $dbQuery .= "Campus, TeachingStation, ProjectionBooth, Instructions, FP, AM1, AM2, AM5, AM6, AM7, ";
    $dbQuery .= "AM12, AM13, AM14, AM16, AM17, AM18, AM19, AM20, AM21, AM22, AM23 ";
    $dbQuery .= "from MainDB where ID = '" . $Room . "'"; 

    $table = "Classroom";
    require("../db.php");

    $Campus = mysql_result($results,0,"Campus");
    $RoomType  = mysql_result($results,0,"RoomType");
    $SeatingCap  = mysql_result($results,0,"SeatingCap");   
    $FloorType  = mysql_result($results,0,"FloorType");
    $Building  = mysql_result($results,0,"Building");
    $RoomNo  = mysql_result($results,0,"Room");
    $Windows  = mysql_result($results,0,"Windows"); 
    $Wheelchair  = mysql_result($results,0,"Wheelchair");
    $Lighting  = mysql_result($results,0,"Lighting");
    $Contact  = mysql_result($results,0,"Contact");
    $AdditionalInfo  = mysql_result($results,0,"AdditionalInfo");
    $TeachingStation = mysql_result($results,0,"TeachingStation");
    $ProjectionBooth  = mysql_result($results,0,"ProjectionBooth");
    $FloorPlan  = mysql_result($results,0,"FP");
    $AM[1] = mysql_result($results,0,"AM1");
    $AM[2] = mysql_result($results,0,"AM2");
    $AM[5] = mysql_result($results,0,"AM5");
    $AM[6] = mysql_result($results,0,"AM6");
    $AM[7] = mysql_result($results,0,"AM7");    
    $AM[12] = mysql_result($results,0,"AM12");
    $AM[13] = mysql_result($results,0,"AM13");
    $AM[14] = mysql_result($results,0,"AM14");
    $AM[16] = mysql_result($results,0,"AM16");
    $AM[17] = mysql_result($results,0,"AM17");
    $AM[18] = mysql_result($results,0,"AM18");
    $AM[19] = mysql_result($results,0,"AM19");
    $AM[20] = mysql_result($results,0,"AM20");
    $AM[21] = mysql_result($results,0,"AM21");
    $AM[22] = mysql_result($results,0,"AM22");
    $AM[23] = mysql_result($results,0,"AM23");
}
?>

<?php require("../topper.php"); ?>

  <div id="centerwrap">
    <div id="content">
    <form enctype="multipart/form-data" name='form' action="roomadd.php<?
    if ($Room != '')
        {
        echo "?Room=" . $Room;
        }
    ?>" method="post">
    <!-- Begin Main Text of Page -->

    <table cellspacing=2 width=700>
    <tr valign=top>
    <td>

        <?php
        echo "<table class='tbl'>\n"; //Room Specs Table
        echo "<tr class='colhead'>\n";
        echo "<td colspan=4>Room Specifications</td></tr>\n";
        echo "<tr><td>Building</td>\n";
        echo "<td colspan=3><select size=\"1\" name=\"Building\">\n";

        $dbQuery = "Select BuildingID, BuildingAbv, BuildingName from BuildingDB Order by BuildingName"; 

        $table = "Classroom";
        require("../db.php");

        while (mysql_Numrows($results)>$x)                            //if there are records in the fields
        { 
        echo "<option ";

        if($Building == mysql_result($results,$x,"BuildingID"))
        {
        echo "selected ";
        }

        echo "value=\"" . mysql_result($results,$x,"BuildingID") . "\">" . mysql_result($results,$x,"BuildingName") . " -- " . mysql_result($results,$x,"BuildingAbv") . "</option>\n";
        $x++;
        }
        echo "</select>";
        $x = 0;     
        ?>
        </tr>
        <tr>
        <td>Room</td>
        <td colspan=3><input type='text' name='RoomNumber' size=6 value='<? echo $RoomNo ?>'></td>
        </tr>
        <?PHP
        echo "<tr><td>Room Type</td>";
        echo "<td colspan=3><select size=\"1\" name=\"RoomType\">";

        $dbQuery = "Select RoomTypeID, RoomType from RoomTypeDB Order by RoomType"; 

        $table = "Classroom";
        require("../db.php");               

        while (mysql_Numrows($results)>$x)                            //if there are records in the fields
        { 
        echo "<option ";

        if($RoomType == mysql_result($results,$x,"RoomTypeID"))
        {
        echo "selected ";
        }

        echo "value=\"" . mysql_result($results,$x,"RoomTypeID") . "\">" . mysql_result($results,$x,"RoomType") . "</option>\n";
        $x++;
        }
        echo "</select>";
        $x = 0;     
        ?>
        </tr>
        <tr>
        <td>Seat Cap</td><td colspan=3><input type="text" Name="SeatingCap" size=6 value='<? echo $SeatingCap ?>'></td>
        </tr>
        <tr>
        <td>Floor</td>
        <?php
        echo "<td colspan=3><select size=\"1\" name=\"Floor\">\n";

        $dbQuery = "Select FloorID, FloorType from FloorDB Order by FloorType"; 

        $table = "Classroom";
        require("../db.php");               

        while (mysql_Numrows($results)>$x)                            //if there are records in the fields
        { 
        echo "<option ";

        if($FloorType == mysql_result($results,$x,"FloorID"))
        {
        echo "selected ";
        }

        echo "value=\"" . mysql_result($results,$x,"FloorID") . "\">" . mysql_result($results,$x,"FloorType") . "</option>\n";
        $x++;
        }
        $x = 0;     
        echo "</select>\n";
        ?>
        </td>
        </tr>

        <tr>
        <td>Station</td>
        <?php

        echo "<td colspan=3><select size=\"1\" name=\"TeachingStation\">\n";

        $dbQuery = "Select TSID, Station from TeachingStation Order by Station"; 

        $table = "Classroom";
        require("../db.php");               

        while (mysql_Numrows($results)>$x)                            //if there are records in the fields
        { 
        echo "<option ";

        if($TeachingStation == mysql_result($results,$x,"TSID"))
        {
        echo "selected ";
        }

        echo "value=\"" . mysql_result($results,$x,"TSID") . "\">" . mysql_result($results,$x,"Station") . "</option>\n";
        $x++;
        }
        $x = 0;     
        echo "</select>\n";
        ?>
        </td>
        </tr>
        <tr>
        <td>Lighting</td>
        <?php

        echo "<td colspan=3><select size=\"1\" name=\"Lighting\">\n";

        $dbQuery = "Select LightingControlsID, LightingType from LightingControlsDB Order by LightingType"; 

        $table = "Classroom";
        require("../db.php");

        while (mysql_Numrows($results)>$x)                            //if there are records in the fields
        { 
        echo "<option ";

        if($Lighting == mysql_result($results,$x,"LightingControlsID"))
        {
        echo "selected ";
        }

        echo "value=\"" . mysql_result($results,$x,"LightingControlsID") . "\">" . mysql_result($results,$x,"LightingType") . "</option>\n";
        $x++;
        }
        $x = 0;     
        echo "</select>";
        ?>
        </td>
        </tr>        
        <tr>
        <td>Windows</td>
        <?php

        echo "<td colspan=3><select size=\"1\" name=\"Windows\">\n";

        $dbQuery = "Select WindowID, WindowTreatment from  WindowDB Order by WindowTreatment"; 

        $table = "Classroom";
        require("../db.php");               

        while (mysql_Numrows($results)>$x)                            //if there are records in the fields
        { 
        echo "<option ";

        if($Windows == mysql_result($results,$x,"WindowID"))
        {
        echo "selected ";
        }

        echo "value=\"" . mysql_result($results,$x,"WindowID") . "\">" . mysql_result($results,$x,"WindowTreatment") . "</option>\n";
        $x++;
        }
        $x = 0;     
        echo "</select>\n";
        ?>
        </td>
        </tr>                
        <tr>
        <td>Wheelchair</td><td><input type="checkbox" <?
        if($Wheelchair == "1")
        {
        echo "checked ";
        }
        ?>Name="WheelChair"></td>
        <td>Floor Plan</td><td><input type="checkbox" <?
        if($FloorPlan == "1")
        {
        echo "checked ";
        }
        ?>Name="FloorPlan"></td>
        </tr>
        <tr>
        <td colspan=2>Projection Booth</td><td colspan=2><input type="checkbox" <?
        if($ProjectionBooth == "1")
        {
        echo "checked ";
        }
        ?>Name="Booth"></td>
        </tr>
        </table>

    <td>

        <table class='tbl'>
        <tr>
        <td class='colhead'>Additional Information</td>
        </tr>
        <tr>
        <td>
        <textarea cols="30" rows=6 style="overflow: visible" name='Addinfo'><? echo $AdditionalInfo ?></textarea>
        </td>
        </tr>
        </table>
        <br />

        <table class='tbl'>
        <tr>
        <td class='colhead'>Contact Info</td>
        </tr>
        <tr>
        <td>
        <textarea cols="30" rows=6 style="overflow: visible" name='Contactinfo'><? echo $Contact ?></textarea>
        </td>
        </tr>
        </table>

    </td>
    </tr>

        <tr>
        <td colspan=7><input type='button' name='what' onclick="ScreenAdd('project')" value='Add Screen'></td>
        </tr>
        </tbody>
        </table>
    </td>
    <tr>
    <td colspan=2>
    <table class='tbl'>
    <tr>
    <td colspan=5 class='colhead'>Amentities</td>
    </tr>
    <tr>
        <?PHP

        $dbQuery = "Select Amenity, AmenityID from AmenityDB Order by Amenity"; 

        $table = "Classroom";
        require("../db.php");               

        while (mysql_Numrows($results)>$x)                            //if there are records in the fields
        { 
        $AMID = mysql_result($results,$x,"AmenityID");
        echo "<td>";
        echo "<input type='checkbox' name='am" . $AMID; 
        echo "' onclick ='imclicked(this,\"tx" . $AMID ."\")'";

    if ($AM[$AMID] == 1)
        {
        echo " Checked ";
        echo ">";
        echo "<span id='tx" . $AMID . "' style='background: #FFFF00;'>" . mysql_result($results,$x,"Amenity");
        echo "</span></td>\n";
        }
        else
        {
        echo ">";
        echo "<span id='tx" . $AMID . "'>" . mysql_result($results,$x,"Amenity");
        echo "</span></td>\n";
        }
        $x++;
        if ($x % 4 == 0 && $x > 2)
            { echo "</tr>\n<tr>\n"; }
        }
        $x = 0;     

        ?>
        </tr>
        </table>
    </td>
    </tr>
    <tr>
    <td colspan=2><center><input type='submit' value='Enter Room'></center></td>
    </tr>
    </table>
    <br />
    <iframe width=635 height=200 src='<?php
    if ($Room != '')
    { echo 'chalkboards.php?Room=' . $Room;}
    ?>'></iframe>
    <br /><br />
    <iframe width=635 height=200 src='<?php
    if ($Room != '')
    { echo 'screens.php?Room=' . $Room;}
    ?>'></iframe>

    <!-- End Main Text of Page -->
    </form>
    </div>
    <!-- end content -->
    <!--stopindex-->

<?php require("../footer.php"); ?>

</body>
</html>

Now that I've thought about it some, I believe it is the original piece of code and not my more recent post. The more recent snippet is the actual page that is accessed through the site, but the original code is was actually inserts into the DB, which is where I seem to be having the issue. Thanks again!

Finally got this fixed. There was an entry in one of my databases that was not represented in my code. Once I found all the instances of code that referenced this database, and added it to the code, it worked fine.

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.