php - WAMP - PHP/MySQL - 为什么我的 POST 调用被破坏

标签 php mysql variables wamp

编辑:修改已修复 - 主要问题似乎是 php/mysql 连接

为了学习如何在网页上使用 MySQL 数据库,我正在学习通过 PHP 连接到 MySQL 实例的基本教程(全部通过 WAMP2 管理)

教程:http://www.freewebmasterhelp.com/tutorials/phpmysql/4使用 PHP_SELF 方法(据我所知现在已贬值)。

我已经尝试了一些我发现的其他建议,但我找不到解决我在 apache 日志中看到的以下错误的方法:

(20024)The given path is misformatted or contained invalid characters: Cannot map POST /%3C$SEARCH.PHP%3E HTTP/1.1 to file, referer: http://localhost/search.php

此错误阻止返回 HTML 页面,我在浏览器中收到 403 错误

似乎这行 HTML/PHP 是罪魁祸首:

<form name="search" method="post" action="<?=$PHP_SELF?>">

我看到建议要么打开 short_open_tag(有些人认为这是个坏主意),要么改变

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 

我无法使这些方法中的任何一种起作用,并且想知道是否有人可以让我知道这次我错过了什么愚蠢的事情...

我正在使用的整个 php 文件是:

<?php 
// // This is only displayed if they have submitted the form 
 if ($searching =="yes") 
 { 
 echo "<h2>Results</h2><p>"; 

 //If they did not enter a search term we give them an error 
 if ($find == "") 
 { 
 echo "<p>You forgot to enter a search term"; 
 exit; 
 } 

 include("dbinfo.php");
 mysql_connect($host,$username,$password);
 mysql_select_db("database") or die(mysql_error()); 

 // We preform a bit of filtering 
 $find = strtoupper($find); 
 $find = strip_tags($find); 
 $find = trim ($find); 

 //Now we search for our search term, in the field the user specified 
 $data = mysql_query("SELECT * FROM main WHERE upper($field) LIKE'%$find%'"); 

 //And we display the results 
 while($result = mysql_fetch_array( $data )) 
 { 
 echo $result['Item1']; 
 echo " "; 
 echo $result['Item2']; 
 echo "<br>"; 
 echo "<br>"; 
 } 

 //This counts the number or results - and if there wasn't any it gives them a little  message explaining that 
 $anymatches=mysql_num_rows($data); 
 if ($anymatches == 0) 
 { 
 echo "Sorry, but we can not find an entry to match your query<br><br>"; 
 } 

 //And we remind them what they searched for 
 echo "<b>Searched For:</b> " .$find; 
 } 
 ?> 


 <h2>Search</h2> 
 <form name="search" method="post" action="<?=$PHP_SELF?>">
 Seach for: <input type="text" name="find" /> in 
 <Select NAME="field">
 <Option VALUE="item1">Item1</option>
 <Option VALUE="item2">Item2</option>
 </Select>
 <input type="hidden" name="searching" value="yes" />
 <input type="submit" name="search" value="Search" />
 </form> 

最佳答案

避免短标签,它们已经过时了,确保使用:

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

加载页面时表单的 html 是什么样子的?

编辑: 在回顾了我的回答之后,我想稍微改一下,因为他们并不是说“过时”,但他们通常会引起问题(对于那些不知道如何完全设置 php 的人),所以对于初学者我建议避免使用它们。

关于php - WAMP - PHP/MySQL - 为什么我的 POST 调用被破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9246087/

相关文章:

c - 我不明白这些变量如何用于 getchar

php - 我如何更新上一个查询

php - 如何再次从1开始更新id列

mysql - 基于 2 列的重复行的 SQL 查询

mysql - 无法在redmine中启动mysql

c++ - 用新对象清除一个对象?

php - 如何获取与 WordPress 博客特色图像关联的图像文本?

php - MySql:选择按两列分组的总数

php - 创建下拉菜单和描述更改

javascript - 使用 Javascript 变量作为 IFrame 中超链接的一部分