mysql - Insert data to DB with PHP -


this question has answer here:

so i'm creating simple page , want login , passwords go db on login form:

<form id="form_6de933"  name="validate" action="insert.php" method="post" class="login-form narrow-cols"> 

i added action="insert.php" , on insert.php file tried this

 <?php $servername = "localhost"; $username = "xxx"; $password = "xxx"; $dbname = "xxx";  // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) {     die("connection failed: " . $conn->connect_error); }   $sql = "insert nametable (username, password) ('$_post[username]','$_post[password]')";  if ($conn->query($sql) === true) {     echo "new record created successfully"; } else {     echo "error: " . $sql . "<br>" . $conn->error; }  $conn->close(); ?>  

but when click submit this

parse error: syntax error, unexpected '{' in insert.php on line 10.

so can somone me fix error or i'm doing wrong?

your insert query missing "values":

replace this:

$sql = "insert nametable (username, password) ('$_post[username]','$_post[password]')"; 

with this:

$sql = "insert nametable (username, password) values ('$_post[username]','$_post[password]')"; 

also, hope using script testing because script not secure @ all.

hope helps, shah


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -