我得到一个错误“PHP调用未定义的函数”我不知道这个错误的原因可以有人给我一个线索如何解决这个问题?我是html和css的新手。
这是我的PHP代码。
<?php
//for connecting db
include('connect.php');
if (!isset($_FILES['image']['tmp_name'])) {
echo "";
}
else
{
$file=$_FILES['image']['tmp_name'];
$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name= addslashes($_FILES['image']['name']);
move_uploaded_file($_FILES["image"]["tmp_name"],"gallery/" . $_FILES["image"]["name"]);
$photo="gallery/" . $_FILES["image"]["name"];
$query = "insert into images (photo)VALUES('$photo')";
$result = mysql_query($query);
echo '<script type="text/javascript">alert("image successfully uploaded ");window.location=\'index.php\';</script>';
}
?>
<!DOCTYPE html>
<html>
<head>
<link href="css/style.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="js/slider.js"></script>
<script>
$(document).ready(function () {
$('.flexslider').flexslider({
animation: 'fade',
controlsContainer: '.flexslider'
});
});
</script>
</head>
<body>
<div class="container">
<form class="form" action="" method="POST" enctype="multipart/form-data">
<div class="image">
<p>Upload images and try your self </p>
<div class="col-sm-4">
<input class="form-control" id="image" name="image" type="file" onchange='AlertFilesize();'/>
<input type="submit" value="image"/>
</div>
</div>
</form>
<div class="flexslider">
<ul class="slides">
<?php
// Creating query to fetch images from database.
$query = "select * from images order by Id desc limit 5";
$result = mysql_query($query);
while($r = mysql_fetch_array($result)){
?>
<li>
<img src="<?php echo $r['photo'];?>" width="400px" height="300px"/>
</li>
<?php
}
?>
</ul>
</div>
</div>
</body>
</html>
这是我的sql代码。
<?php
// hostname or ip of server
$servername='localhost';
// username and password to log onto db server
$dbusername='root';
$dbpassword='';
// name of database
$dbname='pegasus';
////////////// Do not edit below/////////
$link=mysql_connect("$servername","$dbusername","$dbpassword");
if(!$link){
die("Could not connect to MySQL");
}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
?>
答案 0 :(得分:1)
使用MySQL和PHP的最新和最佳实践是面向对象的解决方案。这是一个例子:
define("HOST", "localhost");
define("USER", "username ");
define("PASS", "password");
define("DATABASE", "pegasus");
$mysqli = new mysqli(HOST, USER, PASS, DATABASE);
$q = "UPDATE products SET amount_sold = 6";
$mysqli->query($q);
以下是有关此编码实践的更多信息:
希望这有帮助。