Hello i try to update the Image using Update Query in MySQL here's the code

$pic = $_FILES['photo']['name'];
$sql = "UPDATE `std_login` SET `imagename` = '$pic' WHERE `std_id_no` = '$std_id'";

the File upload works, but not Stored in Database. what to do? help me please.

Member Avatar for diafol

You've given the SQL, but not how you process the query with php. So we'll wait until you give the rest of the code. BTW use a prepared statement and bind the parameter ($pic).

Here's the full code sir.

<?php
include('../includes/db.php');
 if (!isset($_SESSION['std_id'])) 
 {
header('Location: ../index.php');
 }

$std_id = $_SESSION['std_id'];
$pic = $_FILES['photo']['name'];
$_FILES['photo']['name'];
$_FILES['photo']['size'];
$_FILES['photo']['type'];
$_FILES['photo']['tmp_name'];

if($_FILES['photo']['name'])
{
    //if no errors...
    if(!$_FILES['photo']['error'])
    {
        //now is the time to modify the future file name and validate the file
        if($_FILES['photo']['size'] > (1024000)) //can't be larger than 1 MB
        {
            $valid_file = false;
            $message = 'Oops!  Your file size is to large.';
        }
        elseif($valid_file=true)
        {
            $target = "../images/students/" .basename($_FILES['photo']['name']);
            move_uploaded_file($_FILES['photo']['tmp_name'], $target);
            $message = 'Congratulations!  Your file was accepted.';
        }
    }
    //if there is an error...
    else
    {
        //set that to be the returned message
        $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['photo']['error'];
    }
}


$sql = "UPDATE std_login SET imagename = '$pic' WHERE std_id_no = test";
mysql_query($sql);
header("location: index.php");
?>

How to bind it? i dont have any clue how to fix this.

Member Avatar for diafol

Sorry been on holiday. If you still need help with this, please say yes :)

You are trying to Update Image of student against their ID. pass the value of session variable in querry. like this.

$sql = "UPDATE std_login SET imagename = '$pic' WHERE std_id_no ='$std_id';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.