$from = $_POST[\'from\'];
$to = $_POST[\'to\'];
$message = $_POST[\'message\'];
$query = \"SELECT * FROM Users WHERE `user_name` = \'$from\' LIMIT 1\";
$result = m
Try this:
$from = mysql_real_escape_string($_POST['from']);
$to = mysql_real_escape_string($_POST['to']);
$message = mysql_real_escape_string($_POST['message']);
$query = "SELECT * FROM Users WHERE user_name = '$from' LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
$fromID = $row['user_id'];
}
Also, make sure that:
var_dump
with your vars eg var_dump($from)
Use mysql_fetch_assoc instead
though it should. try this code
$from = mysql_real_escape_string($_POST['from']);
$to = mysql_real_escape_string($_POST['to']);
$message = mysql_real_escape_string($_POST['message']);
$query = "SELECT * FROM Users WHERE `user_name` = '$from' LIMIT 1";
$result = mysql_query($query) or trigger_error(mysql_error().$query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$fromID = $row['user_id'];
echo $fromID;
if it will throw no errors but still print no id, add this line
var_dump($row);
and post here it's output
not that you shouldn't use a user name but user id to address particular user.
while($row =
mysql_fetch_assoc($result)){ $fromID = $row['user_id'];
}