get value from MySQL database with PHP -
$ to = $ _POST ['from']; $ From = $ _POST ['from']; $ Message = $ _POST ['message']; $ Query = "Choose" from users where 'user_name` is from' $ 1 '; $ Result = mysql_query ($ query); While ($ row = mysql_fetch_array ($ result, MYSQL_ASSOC)) {$ fromID = $ line ['user_id']; }
I am trying to be user_id for the user in my database $ formID, like each row in the Users table:
user_id | User_name | User_type 1 | Hristo | Agent
So I need to be $ = 1 to
, but the above code is not working. Any ideas why?
Try this:
$ from = mysql_real_escape_string ([' '] $ _POST); $ From = mysql_real_escape_string ($ _ POST ['from']); $ Message = mysql_real_escape_string ($ _ POST ['message']); $ Query = "Select * from user where user_name = '$ 1' from ';'; $ result = mysql_query ($ query) or die (mysql_error ()); while ($ row = mysql_fetch_assoc ($ result)) {$ FromID = $ line ['user_id'];}
Also, make sure that:
- You are connected to the database
- You need to get data from the post, try
var_dump
such as your code likevar_dump (from $)
Comments
Post a Comment