Search code examples
phpmysqllamp

Script won't write into database LAMP


Hi there recently i've installed linux and installed lamp + phpmyadmin, this scrip worked fine on xampp while I've used win, but now it won't execute, i've changed infos in dbconnect.php file, and if I manually insert row it displays normally. So can anyone tell me where is the problem...?

php problematic script:

<?php
include ("dbc.php");
session_start();
    function GetImageExtension($imagetype)
     {
       if(empty($imagetype)) return false;
       switch($imagetype)
       {
           case 'image/bmp': return '.bmp';
           case 'image/gif': return '.gif';
           case 'image/jpeg': return '.jpg';
           case 'image/png': return '.png';
           default: return false;
       }
     }
if (!empty($_FILES["uploadedimage"]["name"])) {
    $file_name=$_FILES["uploadedimage"]["name"];
    $temp_name=$_FILES["uploadedimage"]["tmp_name"];
    $imgtype=$_FILES["uploadedimage"]["type"];
    $ime=$_FILES["ime"];
    $link=$_FILES["link"];
    $ext= GetImageExtension($imgtype);
    $imagename=date("d-m-Y")."-".time().$ext;
    $target_path = "images/".$imagename;
    $postavio=$_SESSION['user_name'];
if(move_uploaded_file($temp_name, $target_path)) {
    $query_upload="INSERT into linkovi ( ime , link , postavio , slika , datum ) VALUES ('".$_POST["ime"]."','".$_POST["link"]."','".$postavio."','".$target_path."','".date("Y-m-d")."')";
    mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error()); 
    header("Location:dodaj-film.php?uploaded=1");
}else{
   exit("Error While uploading image on the server");
   header("Location:dodaj-film.php?uploaded=0");
}
}
?>

Solution

  • Use mysqli_query() or PDO::query(), mysql_query is obsolete in PHP 5.5

    If this doesn't work please add this and report us the errors.

    <?php
    
    ini_set('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting(-1);
    
    include ("dbc.php");
    //Rest of your code...