php - No data insertion when button pressed -
when press submit button insert record, pulls out no error when check database find no records submitted too. please wrong script. started php
<?php if (isset($_post['submitted'])){ include('connections/connect.php'); $term= $_post['term']; $details= $_post['details']; $sql = "insert people (term,details) values ($term,$details)"; $newrecord ="inserted successfully"; } ?>
connect.php
<?php $hostname_speedapp = "localhost"; $database_speedapp = "mydb"; $username_speedapp = "root"; $password_speedapp = "password"; $mydb= mysqli_connect($hostname_mydb, $username_mydb, $password_mydb) or trigger_error(mysql_error(),e_user_error); ?>
html
<form id="form1" name="form1" method="post" action="page1.php"> <p> <label for="term"></label> <input type="text" name="term" id="term" /> </p> <p> <label for="details"></label> <input type="text" name="details" id="details" /> </p> <p> <input type="submit" name="button" id="button" value="submit" /> <input name="submitted" type="hidden" value="submitted" /> </p> </form> <p> <?php $newrecord ?>
add this
$sql = "insert people (term,details) values ($term,$details)"; if (mysqli_query($mydb, $sql)) { echo "new record created successfully"; } else { echo "error: " . $sql . "<br>" . mysqli_error($mydb); }
edit 01
$hostname_speedapp = "localhost"; $database_speedapp = "mydb"; $username_speedapp = "root"; $password_speedapp = "password"; $mydb= mysqli_connect($hostname_mydb, $username_mydb, $password_mydb) or trigger_error(mysql_error(),e_user_error);
and top of page1.php
include("connect.php");
Comments
Post a Comment