html - Fatal Error with PhP on submit -
i'm making form can add records database through browser. when press submit, comes error
fatal error: call member function execute() on boolean in /srv/http/career.php on line 56
line 56 based of php line:
$result->execute($_post); it's not related connection of database, works because able view made records.
full code
html
<form method="post"> <label for="jobtitle">job title</label> <input type="text" name="jobtitle" /> <br> <label for="reference">reference</label> <input type="text" name="reference" /> <br> <label for="salary">salary</label> <input type="text" name="salary"/> <br> <label for="location">location</label> <input type="text" name="location"/> <br> <br> <label for="description">description</label> <input type="text" name="description"/> <br> <br> <input type="submit" value="submit" name="submit"/> </form> php
<?php if(isset($_post['jobtitle'],$_post['reference'],$_post['salary'],$_post['location'],$_post['description'])){ $result= $pdo->query('insert jobs (job_title, job_ref, job_salary, job_location, job_desc) values ("' . $_post['jobtitle'] . '","' . $_post['reference'] . '","' . $_post['location'] . '","' . $_post['description'] .'")'); unset($_post['submit']); $result->execute($_post); } ?> any appreciated
instead of using query() , concatenating values sql string, try using prepared statement this:
$stmt = $pdo->prepare('insert jobs (job_title, job_ref, job_salary, job_location, job_desc) values (?, ?, ?, ?, ?)'); $stmt->bindvalue(1, $_post['jobtitle']); $stmt->bindvalue(2, $_post['reference']); $stmt->bindvalue(3, $_post['salary']); $stmt->bindvalue(4, $_post['location']); $stmt->bindvalue(5, $_post['description']); $stmt->execute(); there many benefits approach, including making easier tell when you're missing 1 of values trying insert (salary).
Comments
Post a Comment