drsfgwuw61488 2014-07-16 13:15
浏览 43
已采纳

php无法使用特殊字符或空格从URL获取mysql结果?

I have been trying to fix this issue for 2 days now with no avail.

basically, I am trying $_GET results from mysql based on whatever is in the URL passed on from the previous page.

the url is like this: http://mydomain.com/manufacturer/abc

to achieve this URL, i am using .htaccess which works fine.

but if the url has an empty space or a - or any other special characters, my php file won't GET the results from the mysql database.

so this won't work:

http://mydomain.com/manufacturer/a-b-c

or this won't work:

http://mydomain.com/manufacturer/a b c

nor does this:

http://mydomain.com/manufacturer/a+bc

etc etc....

I am using smarty which so far was a very straight forward process but now that it has come to this, it has proven to be a bit difficult.

my php file looks like this:

if (isset($_GET['man'])) {
$man = $_GET['man'];
if( ! $stmt = $db_conx->prepare("SELECT id, man, product_name FROM `$TabelName` WHERE `man` = ?") ) {
  die( $db_conx->error );
}

$stmt->bind_param('s', $man);
if ( ! $stmt->execute() ) {
  die( $stmt->error );
}
$stmt->bind_result($id, $man, $product_name);
$stmt->store_result();

while($stmt->fetch()) {
    $value[] = array('id'=>$id, 'man'=>$man, 'product_name'=>$product_name);
}
}


// Assign this array to smarty...
$smarty->assign('man', $value);



// Assign this array to smarty...
$smarty->assign('$man', $value);

}

and this is my htaccess file:

RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^manufacturer/([a-zA-Z0-9]+)$ manufacturers.php?manu=$1
RewriteRule ^manufacturer/([a-zA-Z0-9]+)/$ manufacturers.php?manu=$1

I have tried urlencode and urldecode in every which way possible, and nothing seemed to work.

could someone please advise on this issue?

Thanks in advance

  • 写回答

2条回答 默认 最新

  • drjmrg8766 2014-07-16 13:20
    关注

    Just try this:

    RewriteRule ^manufacturer/(.*)/?$ manufacturers.php?manu=$1
    

    Note the /?, you don't need the second rule, this thing does it for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件