弹出三个错误,如何修复 [英] Three more errors pop up, how can it be fix
问题描述
hi
我已经纠正了你们向我指出的错误,但现在我还有三个错误,我不知道如何解决它。一直在网上寻找类似但无济于事的东西。这是错误。它是相同的代码。
错误no1。
注意:未定义的变量:查询在 C:\ wamp64 \\\\\\\\\\\\\\\\\\\\ 70
错误编号2:
警告:mysqli_query():空白查询位于 C:\ wamp64 \ www。\\\\\\\\\\\\\\\\\\\\\ -digit> 70
错误号码3:
警告:mysqli_num_rows()要求参数 1 为mysqli_result,布尔值为 in C:\ wamp64 \过网站上的\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
这个项目必须在明天递交,所以你知道,对我来说这是整晚。任何帮助将不胜感激。我在这里。谁能告诉我如何在我的数据库中插入和显示图像,尝试了一切,现在已经用完了想法
我尝试了什么:
< pre > <? php
$ db_host = ' localhost';
$ db_username = ' root';
$ db_password = ;
$ con = mysqli_connect($ db_host,$ db_username,$ db_password)或 die(mysqli_connect_error());
mysqli_select_db($ con,' food')或 die(mysqli_error($ con));
if(isset($ _ POST [' submit'])&& isset( $ _GET [' img_id']))
{
$ sql = < span class =code-string> SELECT * FROM tbl_images WHERE img_id = {$ img_id};
$ result = mysqli_query($ con,$ sql)或 die( 错误: .mysql_error($ con));
$ rowcount = mysqli_num_rows($ result);
}
?>
< html >
< ; 正文 >
< 表格 < span class =code-attribute> method = post enctype = multipart / form-data >
< br / >
< 输入 类型 = 文件 名称 = image >
< br / > < br / >
< input type = 提交 名称 = 提交 value = upload >
< / form >
<? php
if(isset($ _ POST [ ' submit'])&& isset($ _ FILES [' file']))
{
if( getimagesize($ _ FILES [' image'] [' tmp_name'])== false)
{
echo < span class =code-string> 请选择图像;
}
else
{
$ name = addslashes($ _ FILES [' image'] [' 名称跨度>]);
$ image = base64_encode(file_get_contents(addslashes($ _ FILES [' image'] [< span class =code-string>' tmp_name'])));
saveimage($ name,$ image);
}
}
函数saveimage($ name,$ image) // 此函数将图像保存到db
{
$ con = mysqli_connect($ db_host,$ db_username, $ db_password, tbl_images);
$ sql = INSERT INTO tbl_images(name,image)value('$ name,'$ image' )跨度>;
$ query = mysqli_query($ con,$ sql);
if($ query)
{
echo 成功;
}
其他
{
echo not Upload;
}
}
displayimage();
函数displayimage() // 此函数将用于显示db中的图像
{
$ db_host = ' localhost';
$ db_username = ' root';
$ db_password = ;
$ con = mysqli_connect($ db_host,$ db_username,$ db_password);
$ sql = SELECT * FROM tbl_images;
$ query = mysqli_query($ con,$ query);
$ num = mysqli_num_rows($ query);
for($ i = 0; $ i< $ num; $ i ++)
{
$ result = mysqli_fetch_array($ query);
$ img = $ result [' image'];
echo ' < img src = data:image; base64,'。$ img。' >';
}
mysqli_close($ con);
}
?>
< / body >
< / html >
解决方案
db_host = ' localhost';
db_username = ' root';
< blockquote> db_password = ;
hi
I have since corrected the error that you guys have pointed out to me but now I have three more errors and i have no idea how to fix it. been searching the net for something similiar but to no avail. here are the errors. it is the same codes.
error no1.
Notice: Undefined variable: query in C:\wamp64\www\luana_itec244\php\dashboard.php on line 70
error no 2:
Warning: mysqli_query(): Empty query in C:\wamp64\www\luana_itec244\php\dashboard.php on line 70
error no. 3:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp64\www\luana_itec244\php\dashboard.php on line 71
this project has to be handed in tomorrow so you know, it is a whole night for me. any help would be greatly appreciated. here i what I have. can someone tell me how do i get to insert and display images in my database, have tried everything, am now ran out of ideas
What I have tried:
<pre><?php
$db_host='localhost';
$db_username='root';
$db_password="";
$con=mysqli_connect($db_host,$db_username, $db_password) or die (mysqli_connect_error());
mysqli_select_db($con, 'food') or die (mysqli_error($con));
if(isset($_POST['submit']) && isset($_GET['img_id']))
{
$sql= "SELECT * FROM tbl_images WHERE img_id={$img_id}";
$result=mysqli_query($con, $sql) or die("Error:" .mysql_error($con));
$rowcount=mysqli_num_rows($result);
}
?>
<html>
<body>
<form method="post" enctype="multipart/form-data" >
<br/>
<input type="file" name="image">
<br/><br/>
<input type="submit" name="submit" value="upload">
</form>
<?php
if(isset($_POST['submit'])&& isset($_FILES['file']))
{
if(getimagesize($_FILES['image']['tmp_name'])== false)
{
echo "Please select an image";
}
else
{
$name=addslashes($_FILES['image']['name']);
$image=base64_encode(file_get_contents(addslashes($_FILES['image']['tmp_name'])));
saveimage($name, $image);
}
}
function saveimage($name,$image)//this function is saving the images to the db
{
$con = mysqli_connect($db_host, $db_username, $db_password,"tbl_images");
$sql="INSERT INTO tbl_images(name,image) value('$name, '$image')";
$query=mysqli_query($con, $sql);
if($query)
{
echo "Success";
}
else
{
echo "not Upload";
}
}
displayimage();
function displayimage()//this function will be used to display the images from the db
{
$db_host='localhost';
$db_username='root';
$db_password="";
$con = mysqli_connect($db_host, $db_username, $db_password);
$sql="SELECT * FROM tbl_images";
$query=mysqli_query($con, $query);
$num=mysqli_num_rows($query);
for($i=0; $i<$num; $i++)
{
$result=mysqli_fetch_array($query);
$img=$result['image'];
echo'<img src="data:image;base64, '.$img. '">';
}
mysqli_close($con);
}
?>
</body>
</html>
解决方案 db_host='localhost';
db_username='root';
db_password="";
这篇关于弹出三个错误,如何修复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!