0

When I send below query to the database from a php page, the passed values are not displaying. But each time a newrow is added.

$query1="INSERT INTO login(username,password,type)
VALUES("."'".$m_nic."',"."'".$f_name."',"."'".$type."')";
$login_set=mysql_query($query1,$connection);
Will Tate
  • 33,439
  • 9
  • 77
  • 71
  • 1
    The obvious question is, how/where are you setting `$m_nic`, `$f_name` and `$type`? If you're getting new, blank rows on each query that's probably the first place to look. – OddEssay Nov 11 '13 at 13:34
  • What type is your username, pw and type in your db? And what type are they in your php script? – Lithilion Nov 11 '13 at 13:42

1 Answers1

0
  1. How can I prevent SQL injection in PHP?
  2. mysql_* functions are deprecated. USe mysqli_*

Your code should look like this:

$q = mysqli_prepare($connection, 'INSERT INTO login (username, password, type) VALUES (?, ?, ?)';

mysqli_stmt_bind_param($q, 'sss', $m_nic, $f_name, $type);
mysqli_stmt_execute($q);
Community
  • 1
  • 1
speccode
  • 1,562
  • 9
  • 11