PHP - Assign A Return Value Of A Php File To A Variable
Hello All,
I have two php files original.php and return.php retrun.php file returns a variable after I pass $channel_name to it Code: [Select] return $return_variable; I want to assign this return variable to a variable in original.php Something like this Code: [Select] $results = include ('return.php?channel='.$channel_name.'');I am not sure how to do the above code. When I call the return.php from a browser it works properly. Thanks for any help Similar Tutorialsdoes anyone knows how to fill this value to a variable (code below works on the screen): Code: [Select] (str)$txt->value; echo (str)$txt->value; I need to get the value from the code above into $myvalue (code below does not work): Code: [Select] (str)$txt->value; $myvalue = (str)$txt->value; echo $myvalue; Hi everybody, im reading up on arrays and im still stuck... Is it possible to assign an array to a variable? I need something like... Code: [Select] &needvariable = $row->User Hopefully this makes sense... I have a page that lists out some basic information about each quiz this particular student has taken (call it "quiz summary"). I am creating another page that will have all details of a particular quiz by itself (call it "quiz detail"). If I have a link for each quiz on the "quiz summary" page, how do I tell the "quiz detail' page which link they clicked on? Or which quiz they have selected. I was thinking it would work if I assigned a session variable to each link and then the "quiz detail" page could verify which returns true still and show details for that quiz. Would this logic work? Npot sure how to do it anyone though. thanks for any help! Why doesn't this code work... Code: [Select] // Initialize variables. $form_value = ''; $form_value = $_POST['form_value']; I get this error... Quote Notice: Undefined index: form_value Thanks, Debbie basically, I have one calculation that relies on the value returned by an if statement, but i can;t for the life of me figure it out correctly... Here is what i am trying to accomplish: Here is the code for the IF i need to get the value of if ($loadedMiles < 500) { (500 - $loadedMiles) * .25 * $mainRate; } And here is the reason why i need it: if ($loadSize == "Full") { $loadedmiles + thevalueoftheif; } basically i will need to have a way to get the values of the functions in the IF statements if that makes any sense... thanks in advance! Running a simple query: SELECT team, rank from table ORDER BY rank ASC returns 8 records in order from 1 to 8 I then want to a assign a new variable to each that I can use for later queries ie: team with rank 1 = $team1 team with rank 2 = $team2 team with rank 3 = $team3 etc.... Thanks in advance. i have Created a Session with this code $_SESSION['USER_NAME'] = trim($_POST['username']) How can i access the $_SESSION['USER_NAME'] in other Pages ; and will this code for $var = $_SESSION[USER_NAME] can i get the SESSIOn value in " $var" variable ?? I have a made a section on my site where I can upload files to a specific directory, rename them and delete them. So I don't have to go through a FTP program. When renaming and deleting a file I connect using FTP commands with PHP, except when uploading. When uploading it gets the file that has been uploaded from the form on the page before which has its own code using <input type="file"> to search for a local file, then when submit is clicked it uploads it. Then on my PHP script it moves that file from the temp upload folder to the actual site. Bottom line is, is there any way I can make a button that opens a file browser on the users PC and returns the filepath chosen? So I can use FTP to upload the file rather than the form? Undefined variable: return line 38 that line is : echo $return; Below is a look at my full code. Code: [Select] <?php class cms { var $host; var $username; var $password; var $db; function connect() { $con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } function get_content($id = ''){ if($id !=""): $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id = '$id'"; $return = '<a href="index.php">Go Back?</a>'; else: $sql = "SELECT * FROM cms_content ORDER BY id DESC"; endif; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0): while($row = mysql_fetch_assoc($res)) { echo '<h1><a href="index.php?id=' . $row['id'] .'">' . $row['title'] .'</a></h1>'; echo '<p>' . $row['body'] . '</p>'; } else: echo '<p> Sorry! This Page doesn\'t exist!</p>'; endif; echo $return; } }//Ends our class ?> I get the following error when I try to pass a value to a methiod in a loop: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 This one has me very baffled. It will work the first time, and seems to work every other time, so I have no clue what is wrong. Here is the code: This code is part of my "display" class: function display_partner ($type,$loc,$rand=0,$narrow=0) { $this->partners = new partner($this->cxn); $display = ' <div id="cont_info" class="partner-list"> <div> <h3 class="settings">'.ucfirst($loc).' '.ucfirst($type).last_letter($type).'s</h3> </div> <div class="settings-value" style="height:12px;padding:0;margin:0;text-align:right;padding-right:10px;"> <a href="" class="trunc">Add your organization to this list</a></p> </div> <div style="height:2px;padding:0;margin:0;"> <hr class="account" /> </div> '; $ids = $this->partners->get_partners_list($type,$loc,$rand); for ($b=0;$b<sizeof($ids->id);$b++) { $this->partnerID = $ids->id[$b]; $display .= ($narrow)? $this->card_partner_narr():$this->card_partner(); if ($b!=(sizeof($ids->id)-1)) { $display .= '<hr class="account" />'; } } if (sizeof($ids->id)==0) { $display .= '<div style="color:#999999;display:line;text-align:center;height:20px;">No Partners found for '.ucfirst($loc).' '.ucfirst($type).'</div>'; } $display .= ' </div>'; return $display; } function card_partner () { $this->partners->set_partner_id($this->partnerID); $part_info = $this->partners->get_partner_info(); if ($part_info) { $display .= ' <table class="settings"> <tr> '.$this->show_if($part_info['partLogo']['val'],'<td class="settings-value" rowspan="2"><img src="'.LOGO_FOLDER.$part_info['partLogo']['val'].'" '.resize_img(LOGO_FOLDER.$part_info['partLogo']['val'],175).'alt="'.$part_info['partName']['val'].'" /></td>').' <td class="settings-value" colspan="2"><h5>'.$part_info['partName']['val'].'</h5></td> </tr> <tr> <td class="settings-value"> <span style="color:999999;">'.$part_info['partAddress']['val'].'<br /> '.$part_info['partCity']['val'].', '.$part_info['partST']['val'].' '.$part_info['partZIP']['val'].'<br /> '.$part_info['partPhone']['val'].'</span><br /> <a href="'.$this->form->show_href($part_info['partWeb']['val']).'" target="_blank">'.$part_info['partWeb']['val'].'</a> </td> <td class="settings-value">'.$part_info['partInfo']['val'].'</td> </tr> </table> '; } return $display; } This code is part of my "partners" class: function set_partner_id($partID) { echo '<p>partID: '.$partID.' '.gettype($partID).'<br> $this->partner->id: '.$this->partner->id.'</p>'; $this->partner->id = $partID; ///*** ERROR HAPPENS HERE ***/ echo '<p>id set: '.$this->partner->id.'<br> $this->partner->id: '.$this->partner->id.'</p><hr>'; } function get_partner_id() { return $this->partner->id; } // gets user info at login function get_partner_info() { $this->partner = $this->cxn->proc_info('partner','partID',$this->partner->id);//$this->partner->id return $this->partner; } The following is the output generated: partID: 24 string $this->partner->id: id set: 24 $this->partner->id: 24 partID: 26 string $this->partner->id: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 id set: $this->partner->id: partID: 17 string $this->partner->id: id set: 17 $this->partner->id: 17 partID: 25 string $this->partner->id: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 id set: $this->partner->id: As you can see, the value passes to $this->set_partner_id($partID) each time. It is formatted as a string. When it assigns the value to $this->partner->id, however, sometimes it works, and sometimes it doesn't. It's probably something obvious, but I've racked my brain to see what it is. Any ideas? Hey, In my script I am currenlty working on I have 2 classes one which calls the second in the hope it will return a value to it but doesnt send the variable back. The example code below give you and idea of what I am looking for as my script it too long to add. Code: [Select] class oneClass{ function bar(){ $var1 = "test" $two = twoClass(); $result = $two->foo($var1); echo $result; } } class twoClass{ function foo($var1){ $result = $var1 . ' is successful!'; $this->fooTwo($result); } function fooTwo($result){ $result = $result . ' Pass me back now?'; return($result); //Want to pass the variable back to "oneClass->bar();" } } // Starts script $testme = new oneClass(); $testme->bar(); This is a very simple example but states what i am wanting to. Any ideas would be much appreciated! Thanks This is object programming right? Is there a performance issue with this? for example: $notfications = ( blah blah ) ? : ''; then if ($notificatiosn != blabla){ echo 'hey'; }or.... $notifications = function(){ do my stuff here then return 'hey'; }Which way is faster or slower? Reason I Ask this is because I've been doing some object orientated programming in javascript, and didn't know you could do it in php. I'd rather do the objective way so I don't have to use so many freaking variables above the regular way, lol. Edited by Monkuar, 22 January 2015 - 12:22 PM. I'm not versed in PHP OOP and I have some code that I need to echo out onto a page. I don't know what the meaning of $ct->something is in this code. Is this an array of some type? How do I echo out the $ct->title onto another page? Use a function call? I just don't know what all of the $ct variables are and how to get to them. Any help is appreciated. Code: [Select] function current_theme_info() { $themes = get_themes(); $current_theme = get_current_theme(); if ( ! isset( $themes[$current_theme] ) ) { delete_option( 'current_theme' ); $current_theme = get_current_theme(); } $ct->name = $current_theme; $ct->title = $themes[$current_theme]['Title']; $ct->version = $themes[$current_theme]['Version']; $ct->parent_theme = $themes[$current_theme]['Parent Theme']; $ct->template_dir = $themes[$current_theme]['Template Dir']; $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir']; $ct->template = $themes[$current_theme]['Template']; $ct->stylesheet = $themes[$current_theme]['Stylesheet']; $ct->screenshot = $themes[$current_theme]['Screenshot']; $ct->description = $themes[$current_theme]['Description']; $ct->author = $themes[$current_theme]['Author']; $ct->tags = $themes[$current_theme]['Tags']; $ct->theme_root = $themes[$current_theme]['Theme Root']; $ct->theme_root_uri = $themes[$current_theme]['Theme Root URI']; return $ct; } I think I might have already asked something similar, but... my code has: $ip = gethostbyaddr($_SERVER['REMOTE_ADDR']); $host = $_SERVER['HTTP_HOST']; my field header for "$host" is "VISITOR DOMAIN ADDRESS". I'm not sure what I was thinking. That's not possible to capture is it? Last I read, and I think someone here told me, it is only possible to capture the IP and server name of the requesting computer? the var $ip in my report, for instance, returns: 173-28-199-198.client.mchsi.com if I visit the page, and that is the name of the server assigned to my ISP. on PHP's doc page, there are the vars REMOTE_HOST and REMOTE_USER and I haven't tried those. Their example does not list any return value for those vars. what do they return? Edited November 23, 2019 by ajetrumpetI have found postings close, but not close enough to find my error. I am looking up data from a MySql table and putting it in a dropdown box on a form. I can select the item, but apparently not really. I am not able to echo it, or post it to a record. I'm sure I am missing something simple, but... Code attached if anyone can show me the errors of my ways. Thank you. hi , i have an error in my php . It will display successful only if all file being upload , if there have one file not upload . it go to blankpage not tell any error or success.I have file that being upload to different path folder
$fileName14 = basename($_FILES["penaja"]["name"]); $targetFilePath14=$targetDir14. $fileName14; $fileType14 = pathinfo($targetFilePath14,PATHINFO_EXTENSION); $allowTypes14= array('pdf','PDF','docx','DOCX'); //kesihatan $targetDir15 ="folder/pda-semakan/kesihatan/"; $fileName15 = basename($_FILES["umpapkp"]["name"]); $targetFilePath15=$targetDir15. $fileName15; $fileType15 = pathinfo($targetFilePath15,PATHINFO_EXTENSION); $allowTypes15= array('pdf','PDF','docx','DOCX'); //jhepa $targetDir16 ="folder/pda-semakan/jhepa/"; $fileName16 = basename($_FILES["umpajhepa"]["name"]); $targetFilePath16=$targetDir16. $fileName16; $fileType16 = pathinfo($targetFilePath16,PATHINFO_EXTENSION); $allowTypes16= array('pdf','PDF','docx','DOCX'); if(in_array($fileTypeg, $allowTypesg)){ if(in_array($fileType, $allowTypes)){ if(in_array($fileType1, $allowTypes1)){ if(in_array($fileType2, $allowTypes2)){ if(in_array($fileType3, $allowTypes3)){ if(in_array($fileType4, $allowTypes4)){ if(in_array($fileType5, $allowTypes5)){ if(in_array($fileType6, $allowTypes6)){ if(in_array($fileType7, $allowTypes7)){ // Upload file to server if(move_uploaded_file($_FILES["gambar"]["tmp_name"], $targetFilePathg)){ if(move_uploaded_file($_FILES["surat"]["tmp_name"], $targetFilePath)){ if(move_uploaded_file($_FILES["ic"]["tmp_name"], $targetFilePath1)){ if(move_uploaded_file($_FILES["sijilkelahiran"]["tmp_name"], $targetFilePath2)){ if(move_uploaded_file($_FILES["sijilspm"]["tmp_name"], $targetFilePath3)){ if(move_uploaded_file($_FILES["sijilberhenti"]["tmp_name"], $targetFilePath4)){ if(move_uploaded_file($_FILES["sijilmatrik"]["tmp_name"], $targetFilePath5)){ if(move_uploaded_file($_FILES["sejulai"]["tmp_name"], $targetFilePath6)){ if(move_uploaded_file($_FILES["bmjulai"]["tmp_name"], $targetFilePath7)){
Hey, I wanted to know if there is any difference between catching a return value and assigning into a variable, and just catching the value when when you just simply call the function on its own. Here is what I mean below In the first example I called the return by simple calling the function. In the second example I catched the return value through a variable, and then echoed it out. Code: [Select] <?php // Example 1 function text (){ $string = "this is a string </br>"; return $string;} echo text(); // Example 2 function text (){ $string = "this is a string </br>"; return $string; } $new_value = text(); echo $new_value; } ?> I'm new to php and i have a html form with 2 forms and 2 submit buttons, 1 of the forms is solely for uploading an image i downloaded the php script as i don't understand the code well enough to write it myself. The second form asks for your name and email then when you click submit it writes a new html file with the included information. I have managed to upload a file successfully and write the html document with the information successfully but i can't get the image to write into the html document. My file_upload.php script contains the variable for the image name, now how would i get the variable string from file_upload.php and use that name in compile.php. Here's my code. -------------- Form.html -------------- <!DOCTYPE html> <html lang="en"> <head> <title></title> </head> <body> <form action="compile.php" method="post"> <p>input name:<input type="text" name="name"/></p><br /> <p>email:<input type="text" name="email" /></p><br /> </form> <br /> <form enctype="multipart/form-data" method="post" action="file_upload.php"> Choose your file he <input name="file1" type="file" /><br /><br /> <input type="submit" value="Upload It" /> </form> </body> </html> ------------- compile.php ------------- <?php $name = $_POST['name']; $price = $_POST['price']; $desc = $_POST['desc']; $file = "new.html"; $handle = fopen($file,'w'); $data = "<!DOCTYPE html> <html> <head> <title></title> </head> <body> <table style='border-radius:8px;'> <tr> <td style='border-radius:8px;'> <h1>$name</h1> </td> </tr> </table> <table> <tr> <td> <ul> <lh>Product name: $name</lh> <br><br> <li>Price: $price</li><br> <li>Description: $desc</li><br> </ul> </td> <td> <img src='uploads/$fileName' width='' height='' alt='' title='' /> </td> </tr> </table> </body> </html>"; fwrite($handle, $data); print "data written"; fclose($handle); ?> ------------ file_upload.php ------------ <?php // Set local PHP vars from the POST vars sent from our form using the array // of data that the $_FILES global variable contains for this uploaded file $fileName = $_FILES["file1"]["name"]; // The file name $fileTmpLoc = $_FILES["file1"]["tmp_name"]; // File in the PHP tmp folder $fileType = $_FILES["file1"]["type"]; // The type of file it is $fileSize = $_FILES["file1"]["size"]; // File size in bytes $fileErrorMsg = $_FILES["file1"]["error"]; // 0 for false... and 1 for true // Specific Error Handling if you need to run error checking if (!$fileTmpLoc) { // if file not chosen echo "ERROR: Please browse for a file before clicking the upload button."; exit(); } else if($fileSize > 5000000000) { // if file is larger than we want to allow echo "ERROR: Your file was larger than 5mb in file size."; unlink($fileTmpLoc); exit(); } else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) { // This condition is only if you wish to allow uploading of specific file types echo "ERROR: Your image was not .gif, .jpg, or .png."; unlink($fileTmpLoc); exit(); } // Place it into your "uploads" folder mow using the move_uploaded_file() function move_uploaded_file($fileTmpLoc, "uploads/$fileName"); // Check to make sure the uploaded file is in place where you want it if (!file_exists("uploads/$fileName")) { echo "ERROR: File not uploaded<br /><br />"; echo "Check folder permissions on the target uploads folder is 0755 or looser.<br /><br />"; echo "Check that your php.ini settings are set to allow over 2 MB files, they are 2MB by default."; exit(); } // Display things to the page so you can see what is happening for testing purposes echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />"; echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />"; echo "It is a <strong>$fileType</strong> type of file.<br /><br />"; echo "The Error Message output for this upload is: <br />$fileErrorMsg"; ?> Hi Guys, I'm working on an image resizer, to create thumbnails for my page. The resizer works on principle of include a DIRECT link to the image. But what I want to do is put in the PHP Variable in the URL string, so that it points to that file and resizes it accordingly. My code is as follows : Code: [Select] <img src="thumbnail.php?image=<?php echo $row_select_property['image_url']; ?> Image Resize : Code: [Select] <?php // Resize Image To A Thumbnail // The file you are resizing $image = '$_GET[image_url]'; //This will set our output to 45% of the original size $size = 0.45; // This sets it to a .jpg, but you can change this to png or gif header('Content-type: image/jpeg'); // Setting the resize parameters list($width, $height) = getimagesize($image); $modwidth = $width * $size; $modheight = $height * $size; // Creating the Canvas $tn= imagecreatetruecolor($modwidth, $modheight); $source = imagecreatefromjpeg($image); // Resizing our image to fit the canvas imagecopyresized($tn, $source, 0, 0, 0, 0, $modwidth, $modheight, $width, $height); // Outputs a jpg image, you could change this to gif or png if needed imagejpeg($tn); ?> What I am trying to do is pass on the variable "image=<?php echo $row_select_property['image_url']; ?>" to the Thumbnail script. At the moment I am passing it through the URL string, but it doesnt seem to load the graphic. I'll try expand on this more, should you have questions as I am finding it a little difficult to explain. Thanks in advance. Hi, I have a variable named $siteName stored in the server.php file in the data directory data/server.php Now in the header.php page I want to retrieve the $siteName variable so it can be used in the header information. This is what I have but it isnt working. server.php Code: [Select] <?php $siteName = 'My+Test+Site'; ?><?php $adminEmail = 'pwithers2009@hotmail.co.uk'; ?><?php $sendmailLoc = '/usr/sbin/sendmail'; ?><?php $imgdir = 'http://www.tropicsbay.co.uk/images/'; ?><?php $imgdirbase = '/home/tropicsb/public_html/images/'; ?> header.php Code: [Select] <?php include("data/server.php"); $siteName = $_GET['siteName']; echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>$siteName Admin Panel</title> <link rel="stylesheet" href="admin.css" type="text/css" /> </head> <div id="pagehead"> <div id="navigation"> <img alt="" src="images/leftNav.gif" height="32" width="4" id="leftNav" /> <img alt="" src="images/rightNav.gif" height="32" width="4" id="rightNav" /> <div id="globalLink"> <a href="admin.php?cmd=manage&username=admin&password=$adminpw" id="gl1" class="glink" onmouseover="ehandler(event,menuitem1);">Users</a><a href="admin.php?cmd=editTemplate&username=admin&password=$adminpw" id="gl2" class="glink" onmouseover="ehandler(event,menuitem2);">Templates</a><a href="admin.php?cmd=mysqlBackup&username=admin&password=$adminpw" id="gl3" class="glink" onmouseover="ehandler(event,menuitem3);">Database</a><a href="admin.php?cmd=paymentLog&username=admin&password=$adminpw" id="gl4" class="glink" onmouseover="ehandler(event,menuitem4);">Payment</a><a href="admin.php?cmd=profileFields&username=admin&password=$adminpw" id="gl5" class="glink" onmouseover="ehandler(event,menuitem5);">Setup</a><a href="admin.php?cmd=changeAdminpw&username=admin&password=$adminpw" id="gl6" class="glink" onmouseover="ehandler(event,menuitem6);">Preferences</a><a href="admin.php?cmd=logout&username=admin&password=$adminpw" id="gl7" class="glink" onmouseover="ehandler(event,menuitem6);">Logout</a></div> </div></div> <div id="pagelayout"> <img alt="" src="images/leftCurve.gif" height="6" width="6" id="left" /> <img alt="" src="images/rightCurve.gif" height="6" width="6" id="right" /> <div id="pageName"> <h2>$siteName Admin Panel<h2> </div>'; ?> Any ideas on how to do this, it seems to work ok in one of my other scripts. Thanks |