php - 如何在php mysql查询中搜索where条件column_name ='bolt 1/2 inch'

标签 php mysql

我的数据库表中有一个列包含“ bolt 1/2 英寸”

在变量中传递正斜杠时,我被绞死了。如果没有斜杠,则代码工作正常。

$par_stockDescription = 'bolt 1/2 inch'
$description = mysql_real_escape_string($par_stockDescription);

$sql_getStockId = "SELECT stock_id,units FROM table_name WHERE description ='".$description ."';

$result_stockId =db_query($sql_getStockId);
$arr_stockId = db_fetch($result_stockId);
echo  $arr_stockId['stock_id']; 

最佳答案

您的字符串配额不正确,请使用:

$sql_getStockId = "SELECT stock_id,units FROM table_name WHERE description ='".$description ."'";

关于php - 如何在php mysql查询中搜索where条件column_name ='bolt 1/2 inch',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23239865/

相关文章:

php - 无法将照片上传到我的应用程序到网络服务器

mysql - SQL group by 按列分组内的自定义分组集

mysql - 为什么我尝试使用 Perl 的 DBD::mysql 时会出现错误?

mysql - 根据id的mysql对行进行排序

java - Android应用程序与rest api php codeigniter管理面板

php - 代码和 SQL 查询中有什么错误?为什么网页上没有任何显示?

php - 通过大学代理从本地 LAMP 连接到远程 MySQL 数据库

php - 如何自定义 Laravel whereBetween 子句使上限不受限制?

php - 结合两个mysql结果

mysql - SQL 子查询火爆