.
Currently I have a table called "contacts" in the db with fname, address and contact no columns.
.
when I run this, it shows the following error, what am I doing wrong?
Fatal error: Call to a member function fetch_object() on a non-object in C:\xampp\htdocs\newNew\jol.php on line 30
.
The code I have so far is below;
.
Code: Select all
<html>
<body>
<?php
include ("dbConnect.php");
$sql="select * from contacts";
$result=mysql_query($sql);
$i = 0
?>
<form method=post action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table style="font-family"arial; font-size:15" width="600" border="1" cellpadding="1" cellspacing="1" align="center">
<font face=arial size=5 color=blue>
<tr bgcolor=#009933>
<th><b>NAME</b></th>
<th><b>ADDRESS</b></th>
<th><b>PHONE NO</b></th>
<th><b>UPDATE</b></th>
<th><b>DELETE</b></th>
<th><b>CHECK</b></th>
</tr>
<?php
while ($row = $result->fetch_object())
{
echo "<tr>";
echo "<td>";
echo '<input type="text" value="'.$abc['fname'].'" name="name'.$i.'"readonly/>';
echo "</td>";
echo "<td>";
echo '<input type="text" value="'.$abc['address'].'" name="add'.$i.'"/>';
echo "</td>";
echo "<td>";
echo '<input type="text" value="'.$abc['contactno'].'" name="add'.$i.'"/>';
echo "</td>";
echo "<td>";
echo '<input type="submit" value="update" name="adress'.$i.'" />' ;
if (isset($_POST['address'.$i.'']))
{
if (isset($_POST['check'.$i.'']))
{
$jin = $_POST['add'.$i.''];
$cont = $_POST['add'.$i.''];
$nam = $_POST['add'.$i.''];
$update="update contacts set address='$jin' , contactno='$cont' where fname='$name'" ;
$qry = mysql_queery($update);
if (!$qry){echo "Updation Failed!";} else
{
echo "updated successfully";
}
}
else {echo "Please select a checkbox";}
}
echo "</td>" ;
echo "<td>" ;
echo '<input type="submit" value="delete" name="delete'.$i.'" />' ;
if (isset($_POST['delete'.$i.'']))
{
if (isset($_POST['check'.$i.'']))
{
$nam = $_POST['name'.$i.''];
$delete="delete from contacts where fname='$nam'" ;
$qry = mysql_queery($delete);
if (!$qry){echo "Deletion Failed!";} else
{
echo "deleted successfully !";
}
}
else {echo "Please select a checkbox";}
}
echo "</td>" ;
echo "<td>";
echo '<input type="checkbox" name="check'.$i.'" />' ;
echo "</td>" ;
echo "</tr>" ;
$i++;
}
echo "<tr>" ;
echo "<td>" ;
echo '<input type="text" name="txtname" />' ;
echo "</td>";
echo "<td>" ;
echo '<input type="text" name="txtaddress" />' ;
echo "</td>";
echo "<td>" ;
echo '<input type="text" name="txtphone" />' ;
echo "</td>";
echo "<td>" ;
echo '<input type="submit" value="add" name="add" />' ;
if (isset($_POST['add']))
{
$jin = $_POST['txtname'.$i.''];
$cont = $_POST['txtaddress'.$i.''];
$nam = $_POST['txtphone'.$i.''];
if (!$jin or !$cont or !$nam)
{echo "Fill all fields" ;}
else
{
$update="insert into contact (fname, address, contactno) values ('$jin', '$con', '$nam')";
$qry = mysql_query($update);
if (!qry){echo "Adding failed!";}
else
{
header ("location: jol.php");}
}
}
?>
</font>
</form>
</table>
</body>
<html>