douzhuang1900 2014-05-22 16:15
浏览 28
已采纳

仅使用PHP发送POST值

I want to use my webpage to recognize if a $_POST is set and the, if it is, print it in the page, so this is what I really have now:

if (isset($_POST['error'])) {
    echo '<div id="error">'.$_POST['error'].'</div>';
}

But what I want is that, when an if statement that I have in the same document returns true, to send a POST request to that same file and so, show the error message with the $_POST. Is this possible or it is another easy way for doing it?

Sorry for not explaining so well, this is my code:

if (password_verify($_POST['oldpassword'], $result['password'])) {
    // Upload password to database
} else {
    // Set the $_POST['error'] to an error message so I can show it in the error DIV.
}

Thanks!

  • 写回答

1条回答 默认 最新

  • dongling5411 2014-05-22 16:26
    关注

    You can define a $message athe beginning of your page then handle the errors you want to show

    $message = '';
    if (password_verify($_POST['oldpassword'], $result['password'])) {
       // Upload password to database
    } else {
       //set a proper message ID which will be handled in your DIV
       $message_id = 1;
       header('location: /current_path.php?message='.$message_id);
    }
    

    Now in the div you can show it as

    if (!empty($_GET['message'])) {
       echo '<div id="error">';
       if ($_GET['message'] == 1) { echo 'First message to show.'; }
       elseif ($_GET['message'] == 2) { echo 'Second message to show.'; }
       echo '</div>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)