Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:33:54+00:00 2026-06-17T20:33:54+00:00

I have two functions and I am stumped on how to pass a variable

  • 0

I have two functions and I am stumped on how to pass a variable between them. Here is what I have so far.

function copy_photo ($image_url, $image_description){
$rand_string = rand(0001, 9999);//create simple random string   
$image_type = substr(strrchr($image_url,'.'),1);//get image type
$local_directory = "./images/";//folder to put photo
$local_image_name = $local_directory . $image_description . "-" . $rand_string . $image_type;//full directory and new image name to place photo 

copy($image_url, $local_image_name);// I want the function to first copy the image here
return $local_image_name;// <---this is the variable I want to pass on
}

function store_data ($local_image_name){
 //simple PDO statement to insert newly created local image url into database
}

copy_photo ($image_url, $image_description);//copy photos to folder 
store_data ($image_description);//store $image_description in database

What I would like to happen is for the copy_photo function to first copy the photo and then return $local_image_name and pass it to the store_data function for storage in a database. I keep getting an error that $image_description is null when store_data tries to store it into the database. How can I successfully pass $local_image_name from one function to the next?

Thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:33:55+00:00Added an answer on June 17, 2026 at 8:33 pm

    You assign the return value of the function to a variable, then pass that variable to the next function.

    $image_name=copy_photo ($image_url, $image_description);//copy photos to folder 
    store_data ($image_name);//store $image_description in database
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions here function Preloader() {} Preloader.prototype = { init:function() { //
I have two functions that return simple strings. Both are registered. $.views.helpers({ parseDate: function
I have two functions in an ActionScript class, they are: private function loaderCompleteHandler(event:Event):void {
I have two functions hooked on the submit event of a form. Each function
i have two functions, the parent function is __triggerAction, than child function is __triggerNormal
I have two functions named ChangeText() & ChangeColor(), the first function called ChangeText who
I have two functions in my js file: function all_opened() { allToggle(true); } function
I have two functions that execute two ajax calls. If I call one function
I have two functions: Function 1: ImageToByteArray: Is used to Convert an Image into
I have two functions function getImgStr(imgName){ thisStr = '<img src=/_shared/img/discovery/200x100/'+imgName+'.jpg>'; return thisStr; } function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.