I am making a website for my high school annual project. The following error occurs in the php file :
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /host/home1/jbts/html/db/Plot-log.php on line 89
this is php source.
<?php
$link=mysqli_connect("localhost","xxxx","xxxxxxxxx","jbts");
if (!$link)
{ echo "MySQL error : "; echo mysqli_connect_error(); exit(); }
mysqli_set_charset($link,"utf8");
$sql = "select * from Plot-log";
$result = mysqli_query($link, $sql);
?>
and I used in html file like this.
<tr>
<? while($row=mysqli_query($con, $sql)){ ?>
<tr>
<td> <?=$row[0]?></td>
<td> <?=$row[1]?></td>
<td> <?=$row[2]?></td>
</tr>
<?
}
?>
To output the data you need to use one of the fetching methods - in this case mysqli_fetch_assoc
<?php
/* be consistent with the name of the db connection object - $link */
$link=mysqli_connect("localhost","xxxx","xxxxxxxxx","jbts");
if( !$link ) exit( "MySQL error : ". mysqli_connect_error() );
mysqli_set_charset( $link, "utf8" );
$sql = "select * from `Plot-log`";
$result = mysqli_query( $link, $sql );
?>
The names below need to be changed to the actual names of the columns in the table.
<?php
if( $result ){
while( $rs=mysqli_fetch_assoc( $result ) ){
echo "
<tr>
<td>{$rs['FIELD_NAME_1']}</td>
<td>{$rs['FIELD_NAME_2']}</td>
<td>{$rs['FIELD_NAME_3']}</td>
</tr>";
}
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.