Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

php - When I submit my form I get an answer of Column count doesn't match value count at row 1

I just resolved an issue with my field list(which was careless I admit),but I cannot find a way to solve this issue. I looked at error-column-count-doesn't-match-value already but could not find a solution that worked with my code. Any Suggestions?

attendence-form.php

<?php include( "dbconfig.php"); session_start(); if(!isset($_SESSION[ 'login_user'])) { header( "Location: default.php"); } ?>
<!DOCTYPE html>
<html>

<head>
  <link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
  <meta charset="UTF-8">
  <title>User Area|SparkAcad</title>
  <style>
    body {
      background-size: cover;
      font-family: Montserrat;
    }
    .logo {
      width: 213px;
      height: 36px;
      margin: 30px auto;
    }
    .login-block {
      width: 320px;
      padding: 20px;
      background: #fff;
      border-radius: 5px;
      border-top: 5px solid #ff656c;
      margin: 0 auto;
    }
    .login-block h1 {
      text-align: center;
      color: #000;
      font-size: 18px;
      text-transform: uppercase;
      margin-top: 0;
      margin-bottom: 20px;
    }
    .login-block input {
      width: 100%;
      height: 42px;
      box-sizing: border-box;
      border-radius: 5px;
      border: 1px solid #ccc;
      margin-bottom: 20px;
      font-size: 14px;
      font-family: Montserrat;
      padding: 0 20px 0 50px;
      outline: none;
    }
    .login-block input#username {
      background: #fff url('http://i.imgur.com/u0XmBmv.png') 20px top no-repeat;
      background-size: 16px 80px;
    }
    .login-block input#username:focus {
      background: #fff url('http://i.imgur.com/u0XmBmv.png') 20px bottom no-repeat;
      background-size: 16px 80px;
    }
    .login-block input#password {
      background: #fff url('http://i.imgur.com/Qf83FTt.png') 20px top no-repeat;
      background-size: 16px 80px;
    }
    .login-block input#password:focus {
      background: #fff url('http://i.imgur.com/Qf83FTt.png') 20px bottom no-repeat;
      background-size: 16px 80px;
    }
    .login-block input:active,
    .login-block input:focus {
      border: 1px solid #ff656c;
    }
    .login-block button {
      width: 100%;
      height: 40px;
      background: #ff656c;
      box-sizing: border-box;
      border-radius: 5px;
      border: 1px solid #e15960;
      color: #fff;
      font-weight: bold;
      text-transform: uppercase;
      font-size: 14px;
      font-family: Montserrat;
      outline: none;
      cursor: pointer;
    }
    .login-block button:hover {
      background: #ff7b81;
    }
    table#header {
      width: 100%;
      background-color: #ff3366;
    }
    tr:hover {
      background-color: #f5f5f5
    }
  </style>
</head>

<body>

  <div class="logo">
    <table id="header" align="center">
      <tr>
        <td>
          <a href="welcome-home.php">Home</a>
        </td>
        <td>
          <a href="students.php">Student Managment</a>
        </td>
        <td>
          <a href="transcript.php">Transcript/SSL</a>
        </td>
        <td>
          <a href=""></a>
        </td>
      </tr>

    </table>
  </div>
  <div class="login-block">

    <!---uper boundAll content should go between these --->
    <?php if(isset($_POST[ 'search'])) { $valueToSearch=$ _POST[ 'valueToSearch']; // search in all table columns // using concat mysql function $query="SELECT * FROM `records` WHERE CONCAT(`FName`, `LName`) LIKE '%" .$valueToSearch. "%'"; $search_result=f
    ilterTable($query); } else { $query="SELECT * FROM `records`" ; $search_result=f ilterTable($query); } // function to connect and execute the query function filterTable($query) { $connect=m ysqli_connect( "mysql.hostinger.co.uk", "u733142706_root",
    "Summer$2000", "u733142706_user"); $filter_Result=m ysqli_query($connect, $query); return $filter_Result; } ?>
    <form action="insertmulti.php" method="post" align="center">


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

          <th>First Name</th>
          <th>Last Name</th>
          <th>Mark</th>

        </tr>

        <!-- populate table from mysql database -->
        <?php while($row=m ysqli_fetch_array($search_result)):?>
        <tr>
          <td>
            <?php echo $row[ 'FName'];?>
          </td>
          <td>
            <?php echo $row[ 'LName'];?>
          </td>
          <td>
            <input type="text" placeholder="Present/Absent/Tardy" id="Mark" value="Present">
          </td>

        </tr>

        <?php endwhile;?>
      </table>
      <input type="Submit" value="Take Attedence">
    </form>

    <!---lower bound All content should go between these --->
    <br>
    <br>
    <a href="logout.php">Logout</a>
  </div>
</body>

</html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are inserting a table - each select is a row, each comma delimited item in the selects is a field. Each select has 2 fields, while the parenthetical field list has 3 fields. Try something like:

INSERT INTO attendence  (FName, LName, Mark)
$FName, $LName, $Mark

To use your select test setup:

INSERT INTO attendence  (FName, LName, Mark)
SELECT  'FName1', 'LName1', 1
UNION ALL
SELECT  'FName2', 'LName2', 2
UNION ALL
SELECT  'FName3', 'LName3', 3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...