doushui20090526 2016-06-27 09:18
浏览 239

404错误 - 在此服务器上找不到请求的URL / <。 为什么?

I've just finished setting up AMP on a new MacOS El Capitan installation. I don't know why but every time I try to run a simple HTML form with some PHP processing I get a 404 error. I've tried it with the default MacOS document root, I've also tried with the user-level document root, and I've even installed MAMP as a last-resort move. In all these setups the result is always the same when I hit the submit button: 404.

<?php if(isset($_POST['submit'])) { 
$name = $_POST['name'];
$post = $_POST['post'];
$link = $_POST['link']; 
echo $name; 
echo $post; 
echo $link; 
echo "all good";
} 
?>

<form name="upload" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
   Name:<br>
   <input type="text" name="name"><br>
   Post:<br>
   <input type="text" name="post"><br>
   Link:<br>
   <input type="text" name="link"><br>
   <input type="submit" name="submit" value="Submit Form"><br>
</form>

The error is "The requested URL/< was not found on this server."

What am I missing??

Many thanks in advance for your help!

  • 写回答

1条回答 默认 最新

  • douhui7136 2016-06-27 11:15
    关注

    Looks like the action for your form isn't parsing correctly. Your code runs fine on my server as it is - however, every server is different. You could try moving the double quotes inside the php section to see if that's tripping up the parser somehow:

    Change

     <form name="upload" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
    

    to

    <form name="upload" action=<?php echo "\"".htmlspecialchars($_SERVER['PHP_SELF'])."\""; ?> method="post">
    

    or alternatively

    <form name="upload" action=<?php echo "'".htmlspecialchars($_SERVER['PHP_SELF'])."'"; ?> method="post">
    

    In theory all of these should result in the same thing - but it's worth a try.

    评论

报告相同问题?

悬赏问题

  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn