nicedad Posted September 9, 2015 Share Posted September 9, 2015 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> Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted September 9, 2015 Share Posted September 9, 2015 (edited) 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 September 9, 2015 by QuickOldCar Quote Link to comment Share on other sites More sharing options...
nicedad Posted September 9, 2015 Author Share Posted September 9, 2015 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, Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted September 9, 2015 Share Posted September 9, 2015 http://php.net/manual/en/mysqli-result.fetch-array.php Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted September 9, 2015 Share Posted September 9, 2015 Also don't supress the errors with an @, if do not want to see them turn off error reporting and log them a live site. During development the error reporting really helps though. Quote Link to comment Share on other sites More sharing options...
nicedad Posted September 9, 2015 Author Share Posted September 9, 2015 Thanks guys, your input was really helpful. best wishes, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.