0

Please help i cant understand as it gives

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in data.php on line 25 error my code is

    $sql1= mysql_query("SELECT `First Name`, `Address`, `Email`, `Contact No`, `PIN No`, `State`, `Country` FROM $tbl_name3 WHERE EUID='$cuname'");
$sql2= mysql_query("SELECT * FROM $tbl_name3 WHERE EUID='$cuname'");
$row2 = mysql_fetch_row($sql2);
$row1 = mysql_fetch_row($sql1);
$eFirstname = $row1[0];
$eAddress = $row1[1];
$eEmail = $row1[2];
$eContact = $row1[3];
$ePin = $row1[4];
$eState = $row1[5];
$eCountry = $row1[6];

5 Answers5

0

mysql_query returns as follows

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

You should use somethink like this

<?php
$result = mysql_query("SELECT * FROM $tbl_name3 WHERE EUID='$cuname'");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
$row = mysql_fetch_row($result);

?>

Note: mysql_query was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.Alternatives to this function include: mysqli_query() or PDO::query()

Tamil
  • 1,113
  • 8
  • 22
0

You should declare your row1 and row 2 as string array.

Example:

$row1 = "one,two,three,four";
$array = explode (",",$row1)
HiDeo
  • 10,128
  • 8
  • 45
  • 46
Guruprasad N
  • 1
  • 1
  • 4
0

Try this:

$row1 = mysql_fetch_row($sql1, MYSQL_ASSOC);  

There seems to be a problem in the way you are using function.

Note: mysql_query was deprecated in PHP 7.0. Instead, the MySQLi or PDO_MySQL extension should be used.

Milan Gupta
  • 1,151
  • 8
  • 20
0

Hi It seems that your query is not getting executed because of some error and thats why you are getting this error. use mysql error function to see error in your query.

$sql1= mysql_query("SELECT First Name, Address, Email, Contact No, PIN No, State, Country FROM $tbl_name3 WHERE EUID='$cuname'") or die(mysql_error());

$sql2= mysql_query("SELECT * FROM $tbl_name3 WHERE EUID='$cuname'") die(mysql_error());

Also i Strogly recommed use PDO as mysql is depreciated and completely removed from PHP7.

Passionate Coder
  • 6,650
  • 2
  • 16
  • 36
0

use :

while ($row=mysql_fetch_row($sql2)) {
enter code here
}
Gur Janjua
  • 243
  • 1
  • 11