简体   繁体   中英

PHP call to undefined function mysql_connect

Im getting an error "PHP call to undefined function" i don't know what the cause of this error can someone give me a clue how to solve this? im new to html and css.

here is the error. 在此处输入图片说明

here is my sql 在此处输入图片说明

here is my php code.

<?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>

here is my sql code.

<?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());

?>

The most up to date and best practice for using MySQL with PHP is the object-oriented solution. Here is an example:

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);

Here is more info on this coding practice:

http://codular.com/php-mysqli

Hope this helps.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM