Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am try for search from database code is this below
//this is search form
<!DOCTYPE html>


<title>Search Example
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">





Search




//this is show table and search
<?php
$con = mysqli_connect('localhost','root','','labrptdb') or die('Unable To connect');
if(count($_POST)>0) {
$lab = isset($_POST["labno"]) ?? '';
$result=mysqli_query($con,"select * from report where labno = '$lab'");
}
?>
<!DOCTYPE html>


<title>Image retrieve
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">







<?php

$i=0;
while($row = mysqli_fetch_array($result)) {
if($i%2==0)
$reportname="even";
else
$reportname="odd";
?>

<?php
$i++;

}


?>
ID NAME CONTACT NO. ADDRESS LAB NO. AGE GENDER REF.DOCTOR IMAGE TIME UPDATE AND DELETE
<?php echo $row["id"]; ?> <?php echo $row["name"]; ?> <?php echo $row["contactno"]; ?> <?php echo $row["address"]; ?> <?php echo $row["labno"]; ?> <?php echo $row["age"]; ?> <?php echo $row["gender"]; ?> <?php echo $row["refdoctor"]; ?> <?php echo ''; ?> <?php echo $row["datetime"]; ?> ">Delete
">Update



<?php
mysqli_close($con);
?>


and the error show
( ! ) Notice: Undefined variable: conn in E:\wamp\www\addform\searchreport_pat.php on line 6
Call Stack
# Time Memory Function Location
1 0.0000 367376 {main}( ) ...\searchreport_pat.php:0

( ! ) Warning: mysqli_affected_rows() expects parameter 1 to be mysqli, null given in E:\wamp\www\addform\searchreport_pat.php on line 6
Call Stack
# Time Memory Function Location
1 0.0000 367376 {main}( ) ...\searchreport_pat.php:0
2 0.0930 400912 mysqli_affected_rows ( ) ...\searchreport_pat.php:6

What I have tried:

<?php
$con = mysqli_connect('localhost','root','','labrptdb') or die('Unable To connect');
if(count($_POST)>0) {
$lab = isset($_POST["labno"]) ?? '';
$result=mysqli_query($con,"select * from report where labno = '$lab'");
}
?>
<?php

$i=0;
while($row = mysqli_fetch_array($result)) {
if($i%2==0)
$reportname="even";
else
$reportname="odd";
?>

<?php echo $row["id"]; ?> <?php echo $row["name"]; ?> <?php echo $row["contactno"]; ?> <?php echo $row["address"]; ?> <?php echo $row["labno"]; ?> <?php echo $row["age"]; ?> <?php echo $row["gender"]; ?> <?php echo $row["refdoctor"]; ?> <?php echo ''; ?> <?php echo $row["datetime"]; ?> ">Delete
">Update <?php
$i++;
}

<?php mysqli_close(con) ; ?>
Posted
Updated 28-Mar-18 21:42pm
Comments
Richard MacCutchan 29-Mar-18 7:03am    
Simple spelling mistake: con not conn.

See PHP: mysqli_connect - Manual[^]; PHP is not Perl.
 
Share this answer
 
Quote:
Notice: Undefined variable: conn in E:\wamp\www\addform\searchreport_pat.php on line 6

Quote:
Warning: mysqli_affected_rows() expects parameter 1 to be mysqli, null given in E:\wamp\www\addform\searchreport_pat.php on line 6

Your posted code does not contain a mysqli_affected_rows() call or the variable conn.

It looks like you have a line containing
PHP
mysqli_affected_rows($conn)
in E:\wamp\www\addform\searchreport_pat.php on line 6. It might help to change the link parameter to $con. But that is just a guess because you did not showed us the code that fails.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900