mysql - SQL syntax error when adding a user to the database through php -
i trying add user through admin control panel on php webpage, , error. you have error in sql syntax; check manual corresponds mysql server version right syntax
cannot seem spot problem life of me, here full page code.
<?php include('session.php'); ?> <?php include ("db.php"); ?> <?php if (isset($_post['create'])) { $username = mysql_real_escape_string($_post['username']); $password = mysql_real_escape_string($_post['password']); $sex = mysql_real_escape_string($_post['sex']); $email = mysql_real_escape_string($_post['email']); $passwordmd5 = md5($password); $sql="insert `username` (`username`, `password`, `email`, `name`, `dob`, `sex`, `phone`, `imagelink`, `coverimage`, `hobby`, `bio`) values ('$_post[username]','$passwordmd5','$_post[email]','$_post[name]','$_post[dob]','$_post[sex]','$_post[phone]','$_post[imagelink]','$_post[coverpicture]'),'$_post[hobby]','$_post[bio]'"; mysql_query($sql) or die(mysql_error()); include ("addition_successful.php"); exit(); } ?> <!doctype html> <html lang="en"> <head> <title>network tv - add record</title> <meta charset="utf-8" /> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="container"> <div class="content"> <h1>network tv add new user</h1> <br> <div class="toolbar"> <a href="data_display.php">return main page</a> </div> <br> </div> </div> <div class="container"> <div class="content"> <div class="separator"></div> <h2>user details</h2> <div class="separator"></div> <form method="post" action="<?php echo basename($_server['php_self']); ?>"> <p>username:</p> <p><input type="text" name="username" id="username" placeholder="input username here ... "></p> <p>password:</p> <p><input type="text" name="password" id="password" placeholder="input password here ... "></p> <p>email:</p> <p><input type="text" name="email" id="email" placeholder="input email address here ... "></p> <p>name:</p> <p><input type="text" name="name" id="name" placeholder="input name here ... "></p> <p>date of birth:</p> <p><input type="date" name="dob" id="dob" placeholder="input date of birth here ... "></p> <p>gender:</p> <p><input type="text" name="sex" id="sex" placeholder="input gender here ... "></p> <p>phone number:</p> <p><input type="text" name="phone" id="phone" placeholder="input phone number here ... "></p> <p>profile picture:</p> <p><input type="text" name="imagelink" id="imagelink" placeholder="input profile picture link here ... "></p> <p>cover picture:</p> <p><input type="text" name="coverpicture" id="coverpicture" placeholder="input cover picture link here ... "></p> <p>hobbys:</p> <p><input type="text" name="hobby" id="hobby" placeholder="input hobbys here ... "></p> <p>bio:</p> <p><input type="text" name="bio" id="bio" placeholder="input bio here ... "></p> <p><input type="submit" name="create" value="create new record"></p> </form> <div class="separator"></div> </div> </div> </body> </html>
the session.php create session when user logs in, , db database connection mysql.
update
you have error in sql syntax; check manual corresponds mysql server version right syntax use near ''none','none'' @ line 1
your closing )
in wrong place:
'$_post[coverpicture]'),'$_post[hobby]','$_post[bio]'"; ^^^^^ here
move end of values:
$sql="insert `username` (`username`, `password`, `email`, `name`, `dob`, `sex`, `phone`, `imagelink`, `coverimage`, `hobby`, `bio`) values ('$_post[username]','$passwordmd5','$_post[email]','$_post[name]','$_post[dob]','$_post[sex]','$_post[phone]','$_post[imagelink]','$_post[coverpicture]','$_post[hobby]','$_post[bio]')";
Comments
Post a Comment