Save image url to Mysql Database

后端 未结 2 868
执念已碎
执念已碎 2021-01-24 14:58

I have a database named \'mysqlproject\' that contains two tables. One of the tables that i am interesting in is named markers and declared in database like this :



        
相关标签:
2条回答
  • 2021-01-24 15:17

    If you want to do an INSERT, then your VALUES is misplaced.

    Do:

    $results = mysql_query("INSERT INTO markers (PhotosEvent) VALUES ('$dataURL')...
    

    Also make sure session_start(); is loaded, since you are using sessions.

    After seeing the comments in your question, then if

    UPDATE markers SET PhotosEvent = '$dataUrl' WHERE id = $_SESSION['id']
    

    or

    UPDATE markers SET PhotosEvent = '$dataUrl' WHERE id = '".$_SESSION['id']."'
    

    did not work, then that could be the reason.

    Add error reporting to the top of your file(s) which will help during production testing.

    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    

    and mysql_error()

    Using those error reporting methods will help find errors found in your code.

    0 讨论(0)
  • 2021-01-24 15:26

    Found it!

    define('UPLOAD_DIR', 'EventImages/');
    $img = $_POST['imgBase64'];
    $img = str_replace('data:image/png;base64,', '', $img);
    $img = str_replace(' ', '+', $img);
    
    
    $data = base64_decode($img);
    $file = UPLOAD_DIR . uniqid() . '.png';
    $success = file_put_contents($file, $data);
    print $success ? $file : 'Unable to save the file.';
    
    
    $result=mysql_query("SELECT id FROM markers ORDER BY id DESC LIMIT 1");
    while ($row = mysql_fetch_array($result)){
    $LastInsertID=$row['id'];
    }
    $results = mysql_query("UPDATE markers SET PhotosEvent='".$file."' WHERE id = '".$LastInsertID."'");    
    

    now it works ok.. I am fetcing the last known id that is in table Markers and i save the image's url that is stored in variable $file in the database!! I also save the image to folder EventImages as i did before!!

    0 讨论(0)
提交回复
热议问题