Hi Every body
Once again I'm in problem and want some help from you all
I have written a small code to search a particular value in MySql database and then to display the record based on that value - Like to search a Employee code in database and then to display detail of that Employee in same page after that if user want he/she can delete that record. But I am getting 2 error
Notice: Undefined index: dtext in C:\catasset\deleteadministrator.php on line 53

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\catasset\deleteadministrator.php on line 55

Please see the code mentioned here and I am attaching files for better understanding.

<body onload="fo();">
<h1>Welcome <font color="#FF6600"><?php echo $_SESSION['loginname']; ?></font></h1>| <a href="logout.php">Logout</a>
<p>This is a password protected area only accessible to members. </p>
<div align="center">
<form name="viby" method="post" action="">
 <table width="366" border="1">
   <tr>
    <td><h2 class="style5">ENTER CUSTODIAN ID</h2></td>
    <td><input name="dtext" type="text" /></td>
    <td><input type="submit" name="Submit" value="VIEW" /></td>
   </tr>
  </table>
</form>
</div>
<form method="post" action="deleteadministratorexe.php">
<table width=100% border=1>
  <tr>
    <td width=42 height=28 bgcolor=#FFFF99>ID</td>
    <td width=61 bgcolor=#FFFF99>CODE</td>
    <td width=77 bgcolor=#FFFF99>Password</td>
    <td width=92 bgcolor=#FFFF99>Departmenet ID </td>
    <td width=77 bgcolor=#FFFF99>E-Mail</td>
    <td width=108 bgcolor=#FFFF99>Security Level </td>
    <td width=81 bgcolor=#FFFF99>Last Login </td>
    <td width=92 bgcolor=#FFFF99>Account ID </td>
    <td width=75 bgcolor=#FFFF99>Customer Name </td>
    <td width=77 bgcolor=#FFFF99>Customer Rank </td>
    <td width=123 bgcolor=#FFFF99>Customer PH </td>
  </tr>
<?php
$qry = "SELECT * FROM users_table where cust_id = $_POST[dtext]" or die("Display Error: ".mysql_error()); 
$result = mysql_query($qry); 
    while($row=mysql_fetch_array($result))
    {
      echo " <tr>
      <td><input name=t1 type=text id=t14 value=$row[0]  ></td>
      <td><input name=t2 type=text id=t2 value=$row[1]  ></td>
      <td><input name=t3 type=text id=t3 value=$row[2]  ></td>
      <td><input name=t4 type=text id=t4 value=$row[3]  ></td>
      <td><input name=t5 type=text id=t5 value=$row[4]  ></td>
      <td><input name=t6 type=text id=t6 value=$row[5]  ></td>
      <td><input name=t7 type=text id=t7 value=$row[6] ></td>
      <td><input name=t8 type=text id=t8 value=$row[7] ></td>
     <td><input name=t9 type=text id=t9 value=$row[8] ></td>
     <td><input name=t10 type=text id=t10 value=$row[9]  ></td>
     <td><input name=t11 type=text id=t11 value=$row[10] ></td>
       </tr>";
}
?>
  <tr>
    <td height="23" colspan="6"><input align="right" name="RESET" type="reset" id="RESET" value="Reset" /></td>
    <td colspan="5"><input align="left" name="DELETE" type="submit" id="DELETE" value="Submit" /></td>
  </tr>
</table>
</form>
||<a href="member.php"> GO TO INDEX</a>
</body>
</html>

Thanx in advance Please help me...!

Recommended Answers

The first notice you get is because $_POST[dtext] may not have been set. This will result in an invalid query, after which it will fail, and put false in $result.

Since $result is false (because the query failed), mysql_fetch_array cannot be called.

The solutions would be:
1. Check …

Jump to Post

Hi Every body
Once again I'm in problem and want some help from you all
I have written a small code to search a particular value in MySql database and then to display the record based on that value - Like to search a Employee code in database and then …

Jump to Post

All 5 Replies

The first notice you get is because $_POST[dtext] may not have been set. This will result in an invalid query, after which it will fail, and put false in $result.

Since $result is false (because the query failed), mysql_fetch_array cannot be called.

The solutions would be:
1. Check if $_POST has a valid value, if so, then build the query and execute it.
2. After the query you should check if $result is false. If it is, then there was an error. If it is not, you can retrieve the results.

Hope this helps.

Hi Every body
Once again I'm in problem and want some help from you all
I have written a small code to search a particular value in MySql database and then to display the record based on that value - Like to search a Employee code in database and then to display detail of that Employee in same page after that if user want he/she can delete that record. But I am getting 2 error
Notice: Undefined index: dtext in C:\catasset\deleteadministrator.php on line 53

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\catasset\deleteadministrator.php on line 55

Please see the code mentioned here and I am attaching files for better understanding.

<body onload="fo();">
<h1>Welcome <font color="#FF6600"><?php echo $_SESSION['loginname']; ?></font></h1>| <a href="logout.php">Logout</a>
<p>This is a password protected area only accessible to members. </p>
<div align="center">
<form name="viby" method="post" action="">
 <table width="366" border="1">
   <tr>
    <td><h2 class="style5">ENTER CUSTODIAN ID</h2></td>
    <td><input name="dtext" type="text" /></td>
    <td><input type="submit" name="Submit" value="VIEW" /></td>
   </tr>
  </table>
</form>
</div>
<form method="post" action="deleteadministratorexe.php">
<table width=100% border=1>
  <tr>
    <td width=42 height=28 bgcolor=#FFFF99>ID</td>
    <td width=61 bgcolor=#FFFF99>CODE</td>
    <td width=77 bgcolor=#FFFF99>Password</td>
    <td width=92 bgcolor=#FFFF99>Departmenet ID </td>
    <td width=77 bgcolor=#FFFF99>E-Mail</td>
    <td width=108 bgcolor=#FFFF99>Security Level </td>
    <td width=81 bgcolor=#FFFF99>Last Login </td>
    <td width=92 bgcolor=#FFFF99>Account ID </td>
    <td width=75 bgcolor=#FFFF99>Customer Name </td>
    <td width=77 bgcolor=#FFFF99>Customer Rank </td>
    <td width=123 bgcolor=#FFFF99>Customer PH </td>
  </tr>
<?php
$qry = "SELECT * FROM users_table where cust_id = $_POST[dtext]" or die("Display Error: ".mysql_error()); 
$result = mysql_query($qry); 
    while($row=mysql_fetch_array($result))
    {
      echo " <tr>
      <td><input name=t1 type=text id=t14 value=$row[0]  ></td>
      <td><input name=t2 type=text id=t2 value=$row[1]  ></td>
      <td><input name=t3 type=text id=t3 value=$row[2]  ></td>
      <td><input name=t4 type=text id=t4 value=$row[3]  ></td>
      <td><input name=t5 type=text id=t5 value=$row[4]  ></td>
      <td><input name=t6 type=text id=t6 value=$row[5]  ></td>
      <td><input name=t7 type=text id=t7 value=$row[6] ></td>
      <td><input name=t8 type=text id=t8 value=$row[7] ></td>
     <td><input name=t9 type=text id=t9 value=$row[8] ></td>
     <td><input name=t10 type=text id=t10 value=$row[9]  ></td>
     <td><input name=t11 type=text id=t11 value=$row[10] ></td>
       </tr>";
}
?>
  <tr>
    <td height="23" colspan="6"><input align="right" name="RESET" type="reset" id="RESET" value="Reset" /></td>
    <td colspan="5"><input align="left" name="DELETE" type="submit" id="DELETE" value="Submit" /></td>
  </tr>
</table>
</form>
||<a href="member.php"> GO TO INDEX</a>
</body>
</html>

Thanx in advance Please help me...!

Thats just because u didn't check for the existence of POST variables in ur code.
When u execute ur script for the first time, u have no value submitted as POST and thus recieve an error...
Solution to this is... before running the query for retrieval, check if u have POST variables set.. Something like this--

if (isset($_POST['dtext'])){
//ur retrieval and display code goes here
}

This should solve it..
Cheers!!

Thats just because u didn't check for the existence of POST variables in ur code.
When u execute ur script for the first time, u have no value submitted as POST and thus recieve an error...
Solution to this is... before running the query for retrieval, check if u have POST variables set.. Something like this--

if (isset($_POST['dtext'])){
//ur retrieval and display code goes here
}

This should solve it..
Cheers!!

Thak you for your consideration...
Should I put this code in between your code

if (isset($_POST['dtext']))
{
$qry = "SELECT * FROM users_table where cust_id = $_POST[dtext]" or die("Display Error: ".mysql_error()); 
$result = mysql_query($qry); 
        while($row=mysql_fetch_array($result))
	{
	echo " <tr>
		<td><input name=t1 type=text id=t14 value=$row[0]  ></td>
		<td><input name=t2 type=text id=t2 value=$row[1]  ></td>
		<td><input name=t3 type=text id=t3 value=$row[2]  ></td>
		<td><input name=t4 type=text id=t4 value=$row[3]  ></td>
		<td><input name=t5 type=text id=t5 value=$row[4]  ></td>
		<td><input name=t6 type=text id=t6 value=$row[5]  ></td>
		<td><input name=t7 type=text id=t7 value=$row[6] ></td>
		<td><input name=t8 type=text id=t8 value=$row[7] ></td>
		<td><input name=t9 type=text id=t9 value=$row[8] ></td>
		<td><input name=t10 type=text id=t10 value=$row[9]  ></td>
		<td><input name=t11 type=text id=t11 value=$row[10] ></td>
	           </tr>";
	}

}

Thank You very much Venkat your solution work fine

Thank You very much Venkat your solution work fine

Glad i could help..
Cheers!!

Be a part of the DaniWeb community

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