PHP - MySQL

connecting to mysql database through php script

Page 1 of 1

3 Replies - 3998 Views - Last Post: 01 December 2010 - 05:12 AM Rate Topic: -----

#1 smal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-November 10

PHP - MySQL

Posted 30 November 2010 - 05:08 AM

whenever I try to connect to MySQL database using folowing php script I am getting errors as follows.

Quote

Warning: mysql_query() expects parameter 2 to be resource, string given in /opt/lampp/htdocs/database/crodb/le1.php on line 64

Quote

Warning: mysql_query() expects parameter 2 to be resource, string given in /opt/lampp/htdocs/database/crodb/le1.php on line 66

Quote

Warning: mysql_select_db() expects parameter 2 to be resource, string given in /opt/lampp/htdocs/database/crodb/le1.php on line 68

Quote

Warning: mysql_fetch_field() expects parameter 1 to be resource, null given in /opt/lampp/htdocs/database/crodb/le1.php on line 69

Quote

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /opt/lampp/htdocs/database/crodb/le1.php on line 70



My PHP Script is as follows:

<body>
<table width="760" border="0" align="center">
  <tr>
    <td><h1><center>
      LENS Library Plate1
    </center></h1>
      <div align="left"><br>
   
    </div>
  <?
   
//mysql_connect() or die ("Problem connecting to DataBase"); 
//$query = "select cloneid from plate1"; 
//$result = mysql_db_query("crocodile", $query); 
//$r = mysql_fetch_array($result);
//$cloneid=$r["cloneid"];<br>
function seqcheck($cloneid)  
{
  $usr="***";
   $prd="***";
mysql_connect('localhost',$usr,$prd) or die ("Problem connecting to DataBase"); 
//$cloneid=$_GET['cloid'];
$query = "select * from pl1 where cloneid='$cloneid'"; 
//$query = "select * from pl1 where cloneid=($'cloneid')"; 
//$result = mysql_db_query("crocodile", $query);
Line No.64 $result = mysql_query("crocodile", $query);
//$result = mysql_db_query("crocodile", $query); 
Line No.66 $result = mysql_query("crocodile", $query);
  $query1 = "select sequence from pl1 where cloneid='$cloneid'";
Line No.68 $result1= mysql_select_db("crocodile",$query1);
Line No.69 $s = mysql_fetch_field($result1);
Line No.70 $s1= mysql_fetch_array($result1);
$seq= $s1["sequence"];
if (is_null($seq)) 
{ 
echo "<a href=\"ld1.php?cloneid=$cloneid\" title=$cloneid target=_self><font color=#cccccc>$cloneid</font>  </a>";
}
else
{
if ($result) { 
echo"<a href=\"ld1.php?cloneid=$cloneid\" title=sequencenotyetadded target=_self><font color=#000000>$cloneid</font> </a>";
}
}
}

This post has been edited by Dormilich: 01 December 2010 - 05:19 AM
Reason for edit:: please use [code] /* your code source here */ [/code] tags when posting code


Is This A Good Question/Topic? 0
  • +

Replies To: PHP - MySQL

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3553
  • View blog
  • Posts: 10,332
  • Joined: 08-June 10

Re: PHP - MySQL

Posted 30 November 2010 - 05:14 AM

you’re inappropriately mixing the calling syntax of mysql_query() and mysql_db_query(), of which the latter is deprecated and its use is highly discouraged. additionally, you lack the DB selection necessary for mysql_query().


INHO, another example why the mysql_* functions should not be used any more.

This post has been edited by Dormilich: 30 November 2010 - 05:16 AM

Was This Post Helpful? 0
  • +
  • -

#3 smal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-November 10

Re: PHP - MySQL

Posted 01 December 2010 - 05:05 AM

<?
   
//mysql_connect() or die ("Problem connecting to DataBase"); 
//$query = "select cloneid from plate1"; 
//$result = mysql_db_query("crocodile", $query); 
//$r = mysql_fetch_array($result);

Quote

Deprecated: mysql_db_query() [function.mysql-db-query]: This function is deprecated; use mysql_query() instead in /opt/lampp/htdocs/database/crodb/le1.php on line 63

Quote

Deprecated: mysql_db_query() [function.mysql-db-query]: This function is deprecated; use mysql_query() instead in /opt/lampp/htdocs/database/crodb/le1.php on line 65

Quote

Warning: mysql_select_db() expects parameter 2 to be resource, string given in /opt/lampp/htdocs/database/crodb/le1.php on line 68

Quote

Warning: mysql_fetch_field() expects parameter 1 to be resource, null given in /opt/lampp/htdocs/database/crodb/le1.php on line 69

Quote

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /opt/lampp/htdocs/database/crodb/le1.php on line 70

//PHP-Script is as follows

<?   
//mysql_connect() or die ("Problem connecting to DataBase"); 
//$query = "select cloneid from plate1"; 
//$result = mysql_db_query("crocodile", $query); 
//$r = mysql_fetch_array($result);
//$cloneid=$r["cloneid"];<br>
function seqcheck($cloneid)  
{
  $usr="***";
   $prd="***";
mysql_connect('localhost',$usr,$prd) or die ("Problem connecting to DataBase"); 
//$cloneid=$_GET['cloid'];
$query = "select * from pl1 where cloneid='$cloneid'"; 
$result = mysql_query("crocodile", $query);
$result = mysql_query("crocodile", $query);
$query1 = "select sequence from pl1 where cloneid='$cloneid'";
$result1= mysql_query("crocodile",$query1);
$s = mysql_fetch_field($result1);
$s1= mysql_fetch_array($result1);
$seq= $s1["sequence"];
if (is_null($seq)) 
{ 
echo "<a href=\"ld1.php?cloneid=$cloneid\" title=$cloneid target=_self><font color=#cccccc>$cloneid</font>  </a>";
}
else
{
if ($result) { 
echo"<a href=\"ld1.php?cloneid=$cloneid\" title=sequencenotyetadded target=_self><font color=#000000>$cloneid</font> </a>";
}
}
}

echo "<DIV ALIGN=center>";
echo"  <table width=400  height=30O border=1 cellpadding=0 cellspacing=0 bordercolor=#444476 >";
echo "  
<tr>
   <td>&nbsp;</td>
    <td bgcolor=#444476><strong>01</td>
    <td bgcolor=#444476><strong>02</td>
    <td bgcolor=#444476><strong>03</td>
    <td bgcolor=#444476><strong>04</td>
    <td bgcolor=#444476><strong>05</td>
    <td bgcolor=#444476><strong>06</td>
    <td bgcolor=#444476><strong>07</td>
    <td bgcolor=#444476><strong>08</td>
    <td bgcolor=#444476><strong>09</td>
    <td bgcolor=#444476><strong>10</td>
    <td bgcolor=#444476><strong>11</td>
    <td bgcolor=#444476><strong>12</td>
    <td bgcolor=#444476><strong>13</td>
    <td bgcolor=#444476><strong>14</td>
    <td bgcolor=#444476><strong>15</td>
    <td bgcolor=#444476><strong>16</td>
    <td bgcolor=#444476><strong>17</td>
    <td bgcolor=#444476><strong>18</td>
    <td bgcolor=#444476><strong>19</td>
    <td bgcolor=#444476><strong>20</td>
    <td bgcolor=#444476><strong>21</td>
    <td bgcolor=#444476><strong>22</td>
    <td bgcolor=#444476><strong>23</td>
    <td bgcolor=#444476><strong>24</td>
  </tr>
  <tr>
    <td bgcolor=#444476><div align=center><strong>A</div></td>
  	<td>";seqcheck("1LA1");echo"</td>
    <td>";seqcheck("1LA2");echo"</td>
    <td>";seqcheck("1LA3");echo"</td>
    <td>";seqcheck("1LA4");echo"</td>
    <td>";seqcheck("1LA5");echo"</td>
    <td>";seqcheck("1LA6");echo"</td> 
    <td>";seqcheck("1LA7");echo"</td>
    <td>";seqcheck("1LA8");echo"</td>
    <td>";seqcheck("1LA9");echo"</td>
    <td>";seqcheck("1LA10");echo"</td>
    <td>";seqcheck("1LA11");echo"</td>
    <td>";seqcheck("1LA12");echo"</td>
    <td>";seqcheck("1LA13");echo"</td>
    <td>";seqcheck("1LA14");echo"</td>
    <td>";seqcheck("1LA15");echo"</td>
    <td>";seqcheck("1LA16");echo"</td>
    <td>";seqcheck("1LA17");echo"</td>
    <td>";seqcheck("1LA18");echo"</td>
    <td>";seqcheck("1LA19");echo"</td>
    <td>";seqcheck("1LA20");echo"</td>
    <td>";seqcheck("1LA21");echo"</td>
    <td>";seqcheck("1LA22");echo"</td>
    <td>";seqcheck("1LA23");echo"</td>
    <td>";seqcheck("1LA24");echo"</td>
  </tr>
    # Mod Edit: omitting B – P, code not necessary
   echo " </table>";
 
?>


If, I delink the html part of script it works partially.

kindly help me in resolving this issue.

with thanks
s.mahalingam

This post has been edited by Dormilich: 01 December 2010 - 05:19 AM
Reason for edit:: please use [code] /* your code source here */ [/code] tags when posting code

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3553
  • View blog
  • Posts: 10,332
  • Joined: 08-June 10

Re: PHP - MySQL

Posted 01 December 2010 - 05:12 AM

regarding the deprecation messages. yes, mysql_db_query() is deprecated in PHP 5.3. there are better alternatives.

regarding the warnings. you still get the call syntax wrong, see mysql_query()

This post has been edited by Dormilich: 01 December 2010 - 05:14 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1