Joseph Mangana Joseph Mangana - 2 months ago 15
HTML Question

Parse error: syntax error, unexpected '$_POST' (T_VARIABLE) in C:\xampp\htdocs\phpmysqliprocedure\add new.php on line 7

1.this is my code please help me about my problem
thank you.

<?php
include 'connect.php';


if(isset($_POST['btn_submit'])){
$sql = "insert into db_users(username, address, created_at)
values('" $_POST['txt_username'] "', '" $_POST['txt_address'] "', '" date('Y-m-d H:i:s') "')
";
if(mysqli_query($con, $sql)){
header('Location:index.php');
}else{
echo "Error" mysqli_error($con);
}
}
?>
<h2>Add User</h2>
<form action="" method="post">
<table>
<tr>
<td>Username</td>
<td><input name="txt_username"></td>
</tr>
<tr>
<td>Address</td>
<td><input name="txt_address"></td>
</tr>
<tr>
<td></td>
<td><input type="submit name="btn_submit"></td>
</tr>
</table>
</form>

Answer

replace this '" $_POST['txt_username']"' by '". $_POST['txt_username']. "'

  $sql = "insert into db_users(username, address, created_at)
        values('". $_POST['txt_username']. "', '" .$_POST['txt_address'] ."', '".date('Y-m-d H:i:s'). "') ";

Hope this will work

Comments