Jump to content

Converting MYSQL to MYSQLI?


rex_2012

Recommended Posts

Hello (I think I could have posted this in the wrong PHP area! - so posting it here),

 

I'm pretty new at building websites using php (and mysql) and was most recently given the task to create a database image gallery, which was to be accessed through a php website. 

I made a full site which allowed me to upload said images  & it worked perfectly. However after doing my last checks I have been told that mysql is deprecated and that I need to use mysqli.

 

I've had a look at some tutorials on websites to help direct me but it's simply confusing me more and more each time I look at it. 

Is it possible I am over thinking this and there is an easier way to approach it?

 

Thank you kindly.

This is my php code:

 

 
    <?php
    
    //This is the directory where images will be saved
    $target = "images/";
    $target = $target . basename( $_FILES['photo']['name']);
    
    //This gets all the other information from the form
    $name= (isset($_POST['image_author']));
    $description= ($_POST['image_description']);
    $pic=($_FILES['photo']['name']);
    
    
    // Connects to your Database
    mysql_connect("localhost", "root", "root") or die(mysql_error()) ;
    mysql_select_db("image_gallery") or die(mysql_error()) ;
    
    //Writes the information to the database
    mysql_query("INSERT INTO images (image_author, image_description, image_pathname)
    VALUES ('$name', '$description', '$pic'");
    
    //Writes the photo to the server
    if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
    {
    
    //Tells you if its all ok
    echo "The file has been uploaded, and your information has been added to the directory <p> <a href='upload.php'> Go back</a>";
    }
    else {
    
    //Gives and error if its not
    echo "Sorry, there was a problem uploading your file.";
    }
    ?>

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.