Jump to content

Recommended Posts

Hello everyone,
I'm a newbie in PHP thus have an issue running the following code. it always says

(Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\showDetails1.php on line 5) or see attached image.

in this code I try to inquiry data from a table using a dropdow list.

 

Is there anyone of help? any help will be appreciated.

<?php
$link = mysqli_connect("localhost","root","", "home_work");
//mysql_select_db("home_work",$link);
$sql = "SELECT * FROM dropdown ";
$aResult = mysql_query($sql);
if($_REQUEST['frm_action'] == 3)
{
if ($_REQUEST['cust_id'] == 0)
{
$id = $_REQUEST['cust_id'];
$sqlCustomer = "SELECT * FROM dropdown ";
}
else
{
$id = $_REQUEST['cust_id'];
$sqlCustomer = "SELECT * FROM dropdown WHERE id ='$id'";
}
$aCustomer = mysql_query($sqlCustomer);
}
?>
<html>
<head>
<script type="text/javascript">
function changeSID()
{
oForm       = eval(document.getElementById("frmForm"));
iCustomerId = document.getElementById("sid").value;
url         = "showDetails1.php?frm_action=3&cust_id=" +iCustomerId;
document.location = url;
}
</script>
</head>

<body>
<form name="frmForm" id="frmForm" >
<table border="0" cellspacing="2" cellpadding="2" width="40%">
<tr>
<td align="right" ><strong>Sid</strong></td>
<td align="left"><select name="sid" id="sid" onchange="javascript:changeSID();">
<option value="">Select</option>
<option value="0">All</option> 

<?php
$sid1 = $_REQUEST['cust_id'];

while($rows=mysql_fetch_array($aResult,MYSQL_ASSOC))
{
$id  = $rows['id'];
$sid = $rows['sid'];
if($sid1 == $id)
{
$chkselect = 'selected';

}
else
{
$chkselect ='';
}
?>
<option value="<?php echo  $id;?>"<?php echo $chkselect;?>><?php echo $sid;?></option>
<?php } ?>
</td>
</tr>
<?php if($_REQUEST['frm_action'] == 3) { ?>
<tr>
<td colspan="2">
<table  style="border:1px solid #003366;" cellspacing="2" cellpadding="2" width="100%" bgcolor="#003366">
<tr bgcolor="#EFEFEF">
<td><b><font color='Red'>Sid</font></b></td>
<td><b><font color='Red'>Sname</font></b></td>
<td><b><font color='Red'>Age</font></b></td>
</tr>
<?php
while($row1 = @mysql_fetch_array($aCustomer,MYSQL_ASSOC))
{
$sid   = $row1['sid'];
$sname = $row1['sname'];
$age   = $row1['age'];
?>
<tr bgcolor="#FFFFFF">
<td><b><font color='#663300'><?php echo $sid;?></font></b></td>
<td><b><font color='#663300'><?php echo $sname;?></font></b></td>
<td><b><font color='#663300'><?php echo $age;?></font></b></td>
</tr>
<?php } ?>
</table>
</td>
</tr>
<?php } ?>
</table>
</form>
</body>
</html>

post-179690-0-44236100-1441793449_thumb.png

Link to comment
https://forums.phpfreaks.com/topic/298107-quiry-from-dropdown-list-problem/
Share on other sites

You are using 2 different database functions, need to use one type.

 

mysqli_ or pdo is what should be using

 

stop using any mysql_ related finctions

 

Can see some examples here

Edited by QuickOldCar

Hi QuickOldCar,

thanks a lot for your help. I tried to fix the problem as you adviced. Unfortunately, occured another one regarding mysql_fetch_array ( ) function

(Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\wamp\www\showDetails1.php on line 46).

here is the improve code:

<?php
$link = mysqli_connect("localhost","root","", "home_work");
//mysql_select_db("home_work",$link);
$sql = "SELECT * FROM dropdown ";
$aResult = mysqli_query($link, $sql);
if($_REQUEST['frm_action'] == 3)
{
if ($_REQUEST['cust_id'] == 0)
{
$id = $_REQUEST['cust_id'];
$sqlCustomer = "SELECT * FROM dropdown ";
}
else
{
$id = $_REQUEST['cust_id'];
$sqlCustomer = "SELECT * FROM dropdown WHERE id ='$id'";
}
$aCustomer = mysqli_query($link, $sqlCustomer);
}
?>
<html>
<head>
<script type="text/javascript">
function changeSID()
{
oForm       = eval(document.getElementById("frmForm"));
iCustomerId = document.getElementById("sid").value;
url         = "showDetails1.php?frm_action=3&cust_id=" +iCustomerId;
document.location = url;
}
</script>
</head>

<body>
<form name="frmForm" id="frmForm" >
<table border="0" cellspacing="2" cellpadding="2" width="40%">
<tr>
<td align="right" ><strong>Sid</strong></td>
<td align="left"><select name="sid" id="sid" onchange="javascript:changeSID();">
<option value="">Select</option>
<option value="0">All</option> 

<?php
$sid1 = $_REQUEST['cust_id'];

while($rows=mysql_fetch_array($sqlCustomer, MYSQL_ASSOC))
{
$id  = $rows['id'];
$sid = $rows['sid'];
if($sid1 == $id)
{
$chkselect = 'selected';

}
else
{
$chkselect ='';
}
?>
<option value="<?php echo  $id;?>"<?php echo $chkselect;?>><?php echo $sid;?></option>
<?php } ?>
</td>
</tr>
<?php if($_REQUEST['frm_action'] == 3) { ?>
<tr>
<td colspan="2">
<table  style="border:1px solid #003366;" cellspacing="2" cellpadding="2" width="100%" bgcolor="#003366">
<tr bgcolor="#EFEFEF">
<td><b><font color='Red'>Sid</font></b></td>
<td><b><font color='Red'>Sname</font></b></td>
<td><b><font color='Red'>Age</font></b></td>
</tr>
<?php
while($row1 = @mysql_fetch_array($aCustomer,MYSQL_ASSOC))
{
$sid   = $row1['sid'];
$sname = $row1['sname'];
$age   = $row1['age'];
?>
<tr bgcolor="#FFFFFF">
<td><b><font color='#663300'><?php echo $sid;?></font></b></td>
<td><b><font color='#663300'><?php echo $sname;?></font></b></td>
<td><b><font color='#663300'><?php echo $age;?></font></b></td>
</tr>
<?php } ?>
</table>
</td>
</tr>
<?php } ?>
</table>
</form>
</body>
</html>

cheers,

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.