php - Wrong to insert data in database using a insert function -


function written correct query too. information not saved in database in table users. query when print it.

insert 'users' value(null,'omardz','bankdz@gmail.com','3a9d086dcf50424fc60ccbc52173d49d','freelancer')   include('config.php'); 

// config file include user,pass,host,database, connect without problem!

function add_new_user($username,$email,$password,$type)  {   global $sbr_connect;   if(empty($username) || empty($email) || empty($password) || empty($type))     return false;    $n_username = mysql_real_escape_string(strip_tags($username),$sbr_connect);   $n_email    = mysql_real_escape_string(strip_tags($email),$sbr_connect);   $n_password = md5(mysql_real_escape_string(strip_tags($password),$sbr_connect));   $n_type     = mysql_real_escape_string(strip_tags($type),$sbr_connect);    $query = sprintf("insert 'users' value(null,'%s','%s','%s','%s')",$n_username,$n_email,$n_password,$n_type);   $qresult = mysql_query($query);    echo $query;    if(!$qresult)     return false;    return true;    }   $resultt= add_new_user('omardz','bankdz@gmail.com','mououuu','man'); if($resultt)  {    echo 'success';    sbr_db_close(); } 

this part of query:

insert 'users'             ^     ^ 

you're using single quotes table not correct identifier qualifiers.

either remove them insert users

or use ticks

insert `users` 

or die(mysql_error()) mysql_query() have signaled syntax error.


sidenote:

consider using mysqli prepared statements, or pdo prepared statements, they're safer.


references:


about password storage.

md5 old , considered broken.

use crypt_blowfish or php 5.5's password_hash() function. php < 5.5 use password_hash() compatibility pack.


this sbr_db_close(); custom function , have no idea does. make sure works.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -