sql - $_POST leads to empty fields in MySQL Database -


thank taking time read this. question may or may not have been answered before, might have been looking in wrong place, i've hit dead end wall here , hope ask finding solution.

i'm using basic form validation specific fields , checkboxes before i'm sending them in query database.

                            <?php                             if ($_server["request_method"] == "post") {                                  // validate text inputs                                 $err = array();                                 if (empty($_post['a'])) {                                     array_push($err, "a required.");                                 }                                                 if (empty($_post['b'])) {                                     array_push($err, "b required.");                                 }                                 if (empty($_post['c'])) {                                     array_push($err, "c required.");                                 } else {                                     $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";                                      if (!eregi($pattern, $_post['email'])) {                                         array_push($err, "incorrect email.");                                     }                                 }                                         if (empty($_post['d'])) {                                     array_push($err, "d required.");                                  if (sizeof($err) != 0) {                                     echo "<p style='color: red'>the following files haven't been filled yet.</p>";                                     echo "<ul style='list-style:circle !important;color: red !important;'>";                                      foreach ($err &$value) {                                         echo "<li style='background: 0;list-style: disc inside none;color: red;'>" . $value . "</li>";                                     }                                      echo "</ul>";                                     echo "<br/>";                                 }                                  // validate agree checkbox                                 if (sizeof($err) == 0 && !isset($_post['agree'])) {                                     array_push($err, "please agree tos.");                                     foreach ($err &$value) {                                         echo "<p style='color: red'>" . $value . "</p>";                                     }                                 }                             }                             ?> 

then inside form got this:

<?php echo isset($_post['a']) ? $_post['a'] : ''; ?>" 

the other lines same, i'll save having read huge block. there on sent code towards:

<?php        // redirect if form valid if (sizeof($err) == 0 && isset($_post['agree'])) {      // set post data in session      session_start();          $_post = $_session['postdata'];                         $con = mysqli_connect("localhost", "x", "y", "z");                                                         // check connection                                                         if (mysqli_connect_errno()) {                                                             echo "failed connect mysql: " . mysqli_connect_error();                                                         }                                                             $sql = "insert esselte_nl (a, b, email, c, d) values                                                             ('$_post[a]',                                                                 '$_post[b]',                                                                 '$_post[email]',                                                                 '$_post[c]',                                                                 '$_post[d]')";                                                          if (!mysqli_query($con, $sql)) {                                                             die('error: ' . mysqli_error($con));                                                         }                                                          mysqli_close($con);     // redirect result.php     exit('<meta http-equiv="refresh" content="0; url=resullt"/>');      return;             session_destroy();     } ?> 

worst thing is, i'm it's small error somewhere , i'm overlooking it, terribly frustrating. if potentially point out whatever i'm doing wrong here, i'd appreciate it.

with friendly regards, user2747008 (i should pick name though)

ps: sorry that, messed copying pasting information.

   $sql = "insert esselte_nl (a, b, email, c, d) values                                                         ('$_post[a]',                                                             '$_post[b]',                                                             '$_post[c]',                                                             '$_post[email]')"; 

your insert statement has 5 field names, 4 values, , aren't in correct order.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -