get value from MySQL database with PHP

前端 未结 4 1206
无人及你
无人及你 2020-12-20 07:51
$from = $_POST[\'from\'];
$to = $_POST[\'to\'];
$message = $_POST[\'message\'];

$query  = \"SELECT * FROM Users WHERE `user_name` = \'$from\' LIMIT 1\";
$result = m         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-20 08:22

    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.

提交回复
热议问题