0

Page 1: It displays the form fine

<div id = "consult-form">
<?php include('consultation.php') ?>
</div>

Page 2: consultation.php

<div id="acordeon">
<div class="panel-group" id="accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" href="#collapseThree">
          Consult Form
        </a>
      </h4>
  </div>
        <form action="postconsult.php" method="post" name ="consult-form" id="consult-form">
            <div class = "col-md-8">
                <div id="collapseThree" class="panel-collapse collapse">
                  <div class="panel-body">
                        <h5>Why did you sign up?</h5>
                         <textarea class="form-control" name = "q1" id="q1"></textarea>
                      </div>

                        <h5>What are your goals?</h5>
                         <textarea class="form-control" name = "q2" id="q2"> </textarea>

                    <div class="footer text-center">
                        <button type="submit" class="btn btn-fill btn-success"
                            >Submit</button>
                         <button id="reset" class="btn btn-fill btn-danger" type="reset">Reset</button>
                    </div>
                </div>
            </div>
        </form>
  </div>
</div>
</div>

postconsult.php

$comment = 'pleasework';
$last_id = mysqli_insert_id($conn);

$pbr = $conn->prepare("UPDATE `memberInfo` mi
                      INNER JOIN `loginInfo` AS li
                      ON li.userID = mi.UserID
                       SET `q1` = '$comment'
                      WHERE mi.userID = '1026'");
        //mysqli_real_escape_string($conn, $q1);
        //$pbr->bind_param("s", $comment);
        $pbr->execute();

What I originally was trying was calling <button type="submit" class="btn btn-fill btn-success" onClick="submitconsult();">Submit</button> but it gave me the same problem as above

function submitconsult() {

// Returns successful data submission message when the entered information is stored in database.
    var data = $('#consult-form').serialize();
    $.ajax({
        type: "POST",
        url: "postconsult.php",
        data: data,
        cache: false,
        success: function(html) {
        //alert(html);
        //document.getElementById('regform').reset();
        }
        });

}

If I go directly to consultation.php and hit submit it updates the database fine, but it doesn't work when I echo it.

What am I doing wrong?

Thanks

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
noname
  • 305
  • 4
  • 15
  • That's not how mysqli prepared statements work http://stackoverflow.com/questions/1290975/how-to-create-a-secure-mysql-prepared-statement-in-php – Machavity Apr 04 '16 at 19:27
  • Thanks I am still working on the form I just have it like this for testing purposes. – noname Apr 04 '16 at 19:38

1 Answers1

2

There are problem with id consult-form, there are 2 of them: one into first file and second into consultation.php. Try to change first file to something like this:

<div id = "consult-form-wrapper">
<?php include('consultation.php') ?>
</div>
alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46