php - MySQL Syntax Error On Line 1(2) -


i beginner web developer. first attempt @ connecting mysql database. getting following syntax error (after connecting db?). know there similar questions out there, think must missing specific. patience!

error: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'name, email, password, gender) values ('','','', '')' @ line 1

<?php $con=mysqli_connect("localhost", "shiftedr_admin", "", "shiftedr_whosthedeeusers"); // check connection if (mysqli_connect_errno())   {   echo "failed connect mysql: " . mysqli_connect_error();  } $sql="insert users2 (full name, email, password, gender) values ('$_post[fullname]','$_post[email]','$_post[password]', '$_post[gender]')";  if (!mysqli_query($con,$sql))      {   die('error: ' . mysqli_error($con));  }  echo "1 record added";  mysqli_close($con);  ?> 

i've double checked values match how in db , case sensitive. "full name" how in both users2 table , php i'm calling from.

the html code using submit script follows:

<div class="reformed-form" style="width: 400px; border-right-color:"> <form method="post" name="accountcreation" id="accountcreation" action="insertnewaccounts.php" style="background-color:#ccffff;"> <center><h1 style="position:relative;left:0px;"> account creation </h1>      <table>     <tr>     <td align="right"> full name: </td>     <td align="left"><input type="text" id="fullname nameerror"  name="fullname" min="4" class="spacing" placeholder="your full name"/> </td></tr>     <tr>     <td align="right">email</td>     <td align="left"><input type="text" id="email" name="email"  min="5" placeholder="@" />        </td></tr>     <tr>     <td align="right"> password </td>     <td align="left"><input type="text" id="password" name="password"  class="spacing" placeholder="minimum 6 characters"/>         </td></tr>     <tr>     <td align="right"> confirm password </td>     <td align="left"><input type="text" id="confirmpassword passworderror" class="spacing" name="pwc" placeholder="confirm password"/></td></tr>     <tr>     <td align="right"> owner's' gender: </td>     <td align="left"><input type="radio"> male <input type="radio">female </td></tr>     </table>     </center>     </dl> <input type="submit" value="check" /></center> </form> 

full name has space in syntax invalid. if actual column name "full name," (ouch) need backticks around it.

insert users2 (`full name`, 

your code vulnerable injection , using deprecated mysql api. switch using parameterized queries pdo or mysqli.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

mysql - Pass value between different pages (form) with PHP -