开发者

How to catch data from a drop down list to use it in SQL query?

开发者 https://www.devze.com 2023-03-01 13:27 出处:网络
I\'ve been trying to fix this code but I couldn\'t. if ($_POST[\'number\']) { $number = $_POST[\'number\'开发者_如何学编程];

I've been trying to fix this code but I couldn't.

if ($_POST['number']) {
    $number = $_POST['number'开发者_如何学编程];
    $code = $_POST['code']; // I INSERTED THIS HERE TO GET THE DROPDOWN LIST VALUE
    //-connect  to the database  
    $db = mysql_connect(SERVER, USERNAME, PASSWORD) or die('cannot connect to the database  because: '.mysql_error());
    //-select  the database to use  
    $mydb = mysql_select_db(DATABASE);
    //-query  the database table  
    $sql = "SELECT * FROM carmdi WHERE ActualNB LIKE '%".$number."%' AND CodeDesc LIKE '%".$code."%'";
    //-run  the query against the mysql query function  
    $result = mysql_query($sql);

This is not the full code, but I inserted $code=$_POST['code']; but it shows a white page, but when I use this instead $code="g";

It works fine, I don't know why it's not working from the dropdown menu.

can you help me please with this ?

thanks


check if $_POST['code'] is set or not


what does $_POST['code'] contains? tried to var_dump it?

by the way

 if ($number = $_POST['number'] && $code = $_POST['code']) {

looks much nicer ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消