1

I have this web service

http://www.example.com/addregisteredusers.php?emailId=test@tets.com&userName=

php code:

    $emailId=$_REQUEST['emailId'];      
$userName=$_REQUEST['userName'];

    $insertDetails=mysql_query("INSERT INTO `registration` (`userName`, `emailId`) VALUES ('$userName', '$emailId')");

when go to database the userName field is empty.

Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
Ayman Hussein
  • 3,817
  • 7
  • 28
  • 48
  • 1
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Apr 01 '14 at 11:04
  • What collation do you use? – Rowland Shaw Apr 01 '14 at 11:04
  • You have no error checking in place to see if the query was successful or to report any messages if it was not. – Quentin Apr 01 '14 at 11:04
  • collation: utf8_general_ci – Ayman Hussein Apr 01 '14 at 11:05
  • @Quentin: so if i use mysqli this issue will be solved? – Ayman Hussein Apr 01 '14 at 11:12
  • What are those symbol you inserted in Username text? – Yuva Raj Apr 01 '14 at 11:23
  • How did you realise that your username field was empty? The characters you are trying to insert are very rare indeed, and I would expect them to be unsupported by most fonts, including, for instance, the font used by your console. Perhaps your data was in fact correctly inserted. – RandomSeed Apr 01 '14 at 11:26
  • someone tried to register with these chars, what can i do with him? – Ayman Hussein Apr 01 '14 at 11:31
  • type: in this comment how stackoverflow dealing with them and store them into database and print them correctly !!!! – Ayman Hussein Apr 01 '14 at 11:33
  • @AymanHussein I see only boxes. Are these special characters are like Copyright symbol, smileys? – Yuva Raj Apr 01 '14 at 11:38
  • not boxes, your browser seems can not handle them or your os is not have the correct font. what is your browser and os you are using? – Ayman Hussein Apr 01 '14 at 11:43

3 Answers3

1

I have created table with fields like below screens

Structure of table

enter image description here

Datas in the table

enter image description here

I have used this code.

     $emailId = mysql_real_escape_string($_REQUEST['email']);
$userName = mysql_real_escape_string($_REQUEST['uname']);

mysql_query("INSERT INTO `new` (`userName`, `emailId`) VALUES ('$userName', '$emailId')") or die(mysql_error());
Ananth
  • 1,520
  • 3
  • 15
  • 28
1

i solved the problem by change table and field charset from utf8 to utf8mb4

Ayman Hussein
  • 3,817
  • 7
  • 28
  • 48
-1

please run this one

$insertDetails = mysql_query("INSERT INTO `registration` (`userName`, `emailId`) VALUES ('".$userName."', '".$emailId."')");
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335