Jump to content

syntax on where


deansaddigh

Recommended Posts

Can someone help me. trying to say update details where admin_id equals the admin_id in the session.

 

//Store the filename, path other criteria in the database 
	$query = "UPDATE admin(avatar_name, avatar_path)
	VALUES('$filename', '$filepath')
	WHERE admin_id = $_SESSION['admin_id']";

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/201159-syntax-on-where/
Share on other sites

Than you, it doesnt error out now so thats a start but i wont update the db it just gets an error, i looked and my update is incorrect it should be this

 

$query = "UPDATE admin SET avatar_name='$filename', avatar_path='$filepath'

WHERE admin_id = {$_SESSION['name']}";

 

but i still get

Unable to add the avatar details to the database

 

Which is related to this code, can you see what i am doing wrong

 

<?php

include "securitycheck.php";

include("includes/connection.php");



    // Where the file is going to be placed 
    $avatarimage = "avatarImages/";

//This path will be stored in the database as it does not contain the filename
$currentdir = getcwd();
$path = $currentdir . '/' . $avatarimage;



//Use this path to store the path of the file in the database.
echo $filepath = $avatarimage;


//Create the folder if it does not already exist
if(!file_exists('avatarimages'))
    {
        if(mkdir('avatarimages'))
        {
            echo 'Folder ' . 'avatarImages' . ' created.';
        }
        else
        {
            echo 'Error creating folder ' . 'avatarImages';
        }
    }


//Store the folder for the course title.
    if(!file_exists( $filepath ))
    {
        if(mkdir( $filepath ))
        {
            echo 'Folder ' .  $avatarimage . ' created.';
        }
        else
        {
            echo 'Error creating folder ' .  $avatarimage;
        }
    }


// Where the file is going to be placed 
    $target_path = $filepath;

    // Add the original filename to our target path. Result is "uploads/filename.extension"
    $target_path = $target_path . '/' . basename( $_FILES['uploadedfile']['name']); 


if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
{
	echo "The file ".  basename( $_FILES['uploadedfile']['name'])." has been uploaded";
	$filename =  $_FILES['uploadedfile']['name'];

	//Store the filename, path other criteria in the database 
	$query = "UPDATE admin SET avatar_name='$filename', avatar_path='$filepath'
	WHERE admin_id = {$_SESSION['name']}";


	//Perform the query
	$add = mysql_query($query, $conn)
		or die("Unable to add the avatar details to the database");



	$message = 'Upload Successful';
	//Close the connection to the database	
	mysql_close($conn);
	header("Location:  admin.php? message=$message");
	exit();
} 
else
{	
	$message = 'There was an error uploading the file, please try again!';

	//Close the connection to the database	
	mysql_close($conn);
	header("Location:add_student_photos.php? message=$message");
	exit();
}
?>

Link to comment
https://forums.phpfreaks.com/topic/201159-syntax-on-where/#findComment-1055406
Share on other sites

Ok, so now it still wont send details to db.

 

I have echo out the sql query to check it and it gives me this

UPDATE admin SET avatar_name=1236336869_scary.gif, avatar_path=avatarImages/ WHERE email = [email protected] to add the avatar details to the database

 

Which looks correct its got the name and path and updating it where email should equal my email.

 

Why wont it upload it still gives this message

to add the avatar details to the database

 

Heres the bit of code

 

//Store the filename, path other criteria in the database 
	$query = "UPDATE admin SET avatar_name=$filename, avatar_path=$filepath
	WHERE email = {$_SESSION['user']}";




	//Perform the query
	$add = mysql_query($query, $conn)
		or die("Unable to add the avatar details to the database");

Link to comment
https://forums.phpfreaks.com/topic/201159-syntax-on-where/#findComment-1055414
Share on other sites

Archived

This topic is now archived and is 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.