Jump to content

Warning: mysql_fetch_assoc() expects parameter 1 to be resource


venuscreats

Recommended Posts

Hello,

Im developing simple user registration system with my knowledge.but got this error with this file

 

<?php
//database connection
require_once("dbconnection/connect.php");

$success_massage ="";

if (isset($_POST['hiddenstudentid']))
$passstudent_id=$_POST['hiddenstudentid'];
else 
$passstudent_id=$_POST['student_id_hidden'];


$sql=mysql_query("SELECT * FROM student WHERE StudentID=$passstudent_id");
echo $sql;


while ($row=mysql_fetch_assoc($sql))
{
$update_nic=$row['NIC'];
$update_name=$row['Student_Name'];
$update_addr=$row['Address'];
$take_bday=$row['Birthday'];
echo $take_bday;
$update_bday=date('d',strtotime($take_bday));
$update_month=date('m',strtotime($take_bday));
$update_year=date('y',strtotime($take_bday));
$update_tele=$row['Telephone'];
$update_email=$row['Email'];

}

if (isset($_POST['btnupdate']))
{
$insert_nic=$_POST['nic_txt'];
$insert_name=$_POST['name_txt'];
$insert_addr=$_POST['address_txt'];
$insert_bday=$_POST['bdate'];
$insert_month=$_POST['bmonth'];
$insert_year=$_POST['byear'];
$insert_tele=$_POST['telephone_txt'];
$insert_email=$_POST['email_txt'];

$Birthday =date("$insert_year-$insert_month-$insert_bday");//Bday eka $Birthday ta set kereema.


$sql="update student set NIC='$insert_nic',Student_Name='$insert_name',Address='$insert_addr',Birthday='$Birthday',Telephone='$insert_tele',Email='$insert_email' where StudentID=$passstudent_id" ;

/*(Student_ID,NIC,Student_Name,Address,Birthday,Telephone,Email)values('$student_id','$insert_nic','$insert_name','$insert_addr','$Birthday','$insert_tele','$insert_email')";*/

//echo $sql;
$result=mysql_query($sql) or die ("database error");

$success ="Records updated successfully";
$success_massage =$success;	
header('Location:editdisplay.php');
}
if ($_POST['btndelete']=='DELETER')
{
$delete = "delete from student where StudentID=$passstudent_id";
$result =mysql_query($delete) or die ("data deleting error");

$delete_massage="Record deleted";	
//$success_massage = $delete_massage;

}
if (isset($_POST['btncancel']))
{
header ('Location:registration.php');	
}	

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function GetConfirmation()
{
var res=confirm("Are you sure to delete this Student?");

if(res==true)
{
	var btn=document.getElementById("btndelete");
	btn.value="DELETER";
        // alert ("YES");
	document.editForm.submit();

}
}

</script>


</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="406" border="1">
    <tr>
      <td width="149"> </td>
      <td width="241">Student Registration</td>
    </tr>
    <tr>
      <td>NIC</td>
      <td><label for="nic_txt"></label>
      <input type="text" name="nic_txt" id="nic_txt" value="<?php echo $update_nic ?>" /><input type="hidden" name="student_id_hidden" id="student_id_hidden" value="<?php echo $passstudent_id ?>" />
      </td>
    </tr>
    <tr>
      <td>Name</td>
      <td><label for="name_txt"></label>
      <input type="text" name="name_txt" id="name_txt" value="<?php echo $update_name ?>" /><span style="color:#F00"><?php echo $massage_name?></span></td>
    </tr>
    <tr>
      <td>Address</td>
      <td><label for="address_txt"></label>
      <input type="text" name="address_txt" id="address_txt" value="<?php echo $update_addr ?>" /><span style="color:#F00"><?php echo $massage_address?></span></td>
    </tr>
    <tr>
      <td>Birthday</td>
      <td><label for="bdate"></label>
        <select name="bdate" id="bdate">
        <option selected="selected"><?php echo $update_bday ?></option>
        <?php 

  for ( $i=1;$i<=31;$i++)
 {echo '<option>'.$i.'</option>';
  }
	?>
        </select>
        <label for="bmonth"></label>
        <select name="bmonth" id="bmonth">
        <option selected="selected"><?php echo $update_month ?></option>
        <?php 
	echo '<option>'.'-month-'.'</option>';
	for ($b=1;$b<=12;$b++)
	 {echo '<option>'.$b.'</option>';

		}
	?>
        </select>
        <label for="byear"></label>
        <select name="byear" id="byear" />
        <option selected="selected"><?php echo $update_year ?></option>
        <?php 
	echo '<option>'.'-year-'.'</option>';
	for ($b=1960;$b<=2000;$b++)
	 {echo '<option>'.$b.'</option>';

		}
	?>
        
      </select><span style="color:#F00"><?php echo $massage_bday?></span></td>
    </tr>
    <tr>
      <td>Email</td>
      <td><label for="email_txt"></label>
      <input type="text" name="email_txt" id="email_txt" value="<?php echo $update_email?>" /></td>
    </tr>
    <tr>
      <td>Telephone</td>
      <td><label for="telephone_txt"></label>
      <input type="text" name="telephone_txt" id="telephone_txt" value="<?php echo $update_tele?>"/></td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" name="btnupdate" id="btnupdate" value="Update" />
     
      <input type="submit" name="btndelete" id="btndelete" value="Delete" onclick="GetConfirmation()" />
      <input type="submit" name="btncancel" id="btncancel" value="Cancel" /></td>
    </tr>
  </table>
  <?php echo $success_massage?>
</form>
</body>
</html>

 

got error from these codes in this file

 

if (isset($_POST['hiddenstudentid']))
$passstudent_id=$_POST['hiddenstudentid'];
else 
$passstudent_id=$_POST['student_id_hidden'];


$sql=mysql_query("SELECT * FROM student WHERE StudentID=$passstudent_id");
echo $sql;

 

it is showing this error this this warning error.in here that details from DB will show in form.and im going to edit them from this file.

 

please help me to find the error.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.