whenevr i execute ne "select *"for any database the error belo is shown,is there any setting in phpadmin....coz this problem occured 1 fine day.....pls help.
<html>
<head></head>
<body><html>
<head>
</head>
<body>
<?php
$con = mysql_connect("localhost");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("snippets",$con);


if(isset($_POST['update'])){
$UpdateQuery = "UPDATE lectures SET Topic='$_POST[topic]', Name='$_POST[name]', Attendance='$_POST[attendance]' WHERE Topic='$_POST[hidden]'";               
mysql_query($UpdateQuery, $con);
};

if(isset($_POST['delete'])){
$DeleteQuery = "DELETE FROM lectures WHERE Topic='$_POST[hidden]'";          
mysql_query($DeleteQuery, $con);
};

if(isset($_POST['add'])){
$AddQuery = "INSERT INTO lectures (Topic, Name, Attendance) VALUES ('$_POST[utopic]','$_POST[uname]','$_POST[uattendance]')";         
mysql_query($AddQuery, $con);
};



$sql = "SELECT * FROM lectures";
$myData = mysql_query($sql);
echo "<table border=1>
<tr>
<th>Topic</th>
<th>Name</th>
<th>Attendance</th>
</tr>";
while($record = mysql_fetch_array($myData)){
echo "<form action=mydata5.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=text name=topic value=" . $record['Topic'] . " </td>";
echo "<td>" . "<input type=text name=name value=" . $record['Name'] . " </td>";
echo "<td>" . "<input type=text name=attendance value=" . $record['Attendance'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['Topic'] . " </td>";
echo "<td>" . "<input type=submit name=update value=update" . " </td>";
echo "<td>" . "<input type=submit name=delete value=delete" . " </td>";
echo "</tr>";
echo "</form>";
}
echo "<form action=mydata5.php method=post>";
echo "<tr>";
echo "<td><input type=text name=utopic></td>";
echo "<td><input type=text name=uname></td>";
echo "<td><input type=text name=uattendance></td>";
echo "<td>" . "<input type=submit name=add value=add" . " </td>";
echo "</form>";
echo "</table>";
mysql_close($con);

?>

</body>
</html>
<?php
$con=mysql_connect("localhost");
echo "ok";
if(!$con){
die("could not connect".mysql_error());
}
mysql_select_db("snippets",$con);
$sql = "SELECT * FROM lectures";
$myData = mysql_query($sql,$con);
echo "<table border=1>
<tr>
<th>Topic</th>
<th>Name</th>
<th>Attendance</th>
</tr>";
while($record = mysql_fetch_array($myData)){
echo "<form action=mydata5.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=text name=topic value=" . $record['Topic'] . " </td>";
echo "<td>" . "<input type=text name=name value=" . $record['Name'] . " </td>";
echo "<td>" . "<input type=text name=attendance value=" . $record['Attendance'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['Topic'] . " </td>";

echo "</tr>";
echo "</form>";

}
echo "</table>";
mysql_close($con);

?>

</body>
</html>

ok
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\snippets\data.php on line 13

this is the error...... table name is lectures n cols are Topic Name Attendance db is snippets

Member Avatar for LastMitch

@pavitrakannan

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\snippets\data.php on line 13

Why do you have 2 of this in your code?

line 8 to line 12

$con = mysql_connect("localhost");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("snippets",$con);

line 67 to line 72

$con=mysql_connect("localhost");
echo "ok";
if(!$con){
die("could not connect".mysql_error());
}
mysql_select_db("snippets",$con);

Can you give a good reason why you have this twice?

It should be only one

mysql_fetch_array returns either a resource, or false.

If it returns false, then there is an error in your query. It is always good to check if the query result was false so you can debug and SQL errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.