0

I have a form action script. I have been struggling to find the issue. There is a problem with my insert which I cannot find.

What am I missing. When I run the script I get a HTTP 500 error

PHP

    //prepare sql and bind parameters for to insert child data
$stmt2 = $conn->prepare("INSERT INTO `Child`(`fullnames`, `idnr`, `date_of_birth`, `School`) VALUES (:Fullname, :IDNR, :DateofBirth, (SELECT `school_id` FROM `Schools` WHERE `School` = :School) )");
$stmt2->bindParam(':Fullname', $fullname);
$stmt2->bindParam(':IDNR', $idnr);
$stmt2->bindParam(':DateofBirth', $dob);
$stmt2->bindParam(':School', $school);

// insert a row - child
$fullname = $_POST['name'];
$idnr = $_POST['idnr'];
$dob = $_POST['dob'];   
$school = $_POST['school'];
$stmt2->execute();

HTML

<form action="insert_child_profile.php">
<div class="section"><span>1</span>Child's Basic detail</div>
<div class="inner-wrap">
    <label>Full Name <input type="text" name="name" required /></label>
    <label>ID Number <input type="text" name="idnr" required /></label>
    <label>Date Of Birth <input type="text" name="dob" required/></label>
</div>

   <div class="section"><span>2</span>School</div>
<div class="inner-wrap">

<div class="ui-widget">
<label>What school does the child attend<input  type="text" name="school" id="school" class="form-control" required placeholder="Enter school Name"/></label>
<div id="schoollist"></div>  
</div>
<br>
<br>
<br>
<br>
<div class="button-section">
 <input type="submit" name="Sign Up" />
    </div>
 </div>
</form>
CharlieT
  • 373
  • 4
  • 26
  • can you add this two lines to the top of your php file and then you will get a more useful error message that way it is easier to find the culprit. It could be wrong table name, wrong structure, missing comma in sql statement,... error_reporting(E_ALL); ini_set('display_errors', 1); – flynorc Nov 10 '17 at 23:32
  • When you get a 500 error, check the error log on the server to see the PHP error message. – Barmar Nov 10 '17 at 23:38
  • Thanks. I did. The error is Notice: Undefined index: for each of the variables (fullname, id, dob and school. It doesn't make send. I did bindparam and identified variable source? – CharlieT Nov 10 '17 at 23:38
  • 3
    *cough* `
    ` *cough*
    – HPierce Nov 11 '17 at 00:09
  • 1
    @HPierce hehe pretty loud cough there. Hope you're not catching cold, but I hear ya ;-) – Funk Forty Niner Nov 11 '17 at 00:13
  • @HPierce. HAHA. Many thanks. Been a while since I felt this stupid. – CharlieT Nov 11 '17 at 00:39

0 Answers0