PHP - Passing An Variable From One Php File To Another
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. Similar TutorialsHi, I need to pass value of variable to another php file. I thought it is possible to do it as following: <form action="products.php"> <INPUT TYPE=hidden NAME='id' . VALUE='$id'> </form> But the problem is like that. The php file inside which I want to write above html code has not using <form> tag and it has no buttons. So how to initiate the transfer of variable into another php file? Is the above idea is not the good idea? Are there any another ways? Hi all, I have my whole script working only the name of the upload file won't pass to the process.php page. Any help much appreciated. Prob just some silly mistake that i made but i can't for the life of me see it. form Code: [Select] <form enctype="multipart/form-data" action="process.php" method="POST" name="books" title="Santa_Book"> <img src="images/book/Enter_your_details.png" width="400" height="60" /><br /> <ul id="inline_list"> <input type="text" name="first_name" id="first_name" value="Text to be displayed here" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/> <label for="sur_name" class="inside">Name</label> <input name="sur_name" type="text" id="sur_name" class="inside" /> <label for="sname">Surname</label> <br /> Sex <select name="sex" id="sex"> <option selected="selected">Please Select....</option> <option value="girl">Girl</option> <option value="boy">Boy</option> </select> <label for="age">Age</label> <input type="text" name="age" id="age" /> <br /> <label for="house_no">House No.</label> <input type="text" name="house_no" id="house_no" /> <br /> <label for="street">Street Name</label> <input type="text" name="street" id="street" /> <br /> <label for="town">Town</label> <input type="text" name="town" id="town" /> <br /> <br /> <select name="bscf1" id="bscf1"> <option selected="selected">Please Select...</option> <option value="Brother1">Brother</option> <option value="Sister1">Sister</option> <option value="Cousin1">Cousin</option> <option value="Friend1">Friend</option> </select> <label for="bscf_name1">Friend / Sibling</label> <input type="text" name="bscf_name1" id="bscf_name1" /> <br /> <select name="bscf2" id="bscf2"> <option>Please Select...</option> <option value="Brother2">Brother</option> <option value="Sister2">Sister</option> <option value="Cousin2">Cousin</option> <option value="Friend2">Friend</option> </select> <label for="bscf_name2">Friend / Sibling</label> <input type="text" name="bscf_name2" id="bscf_name2" /> <br /> <label for="from_name">This book is from...</label> <input type="text" name="from_name" id="from_name" /> <br /> <input name="uploadedfile" type="file" id="uploadedfile" value="Upload Image" /> <br /> </ul> <br /> <input type="submit" value="Continue" /> </form> process.php page Code: [Select] <?php // Database connect $con = mysql_connect("mysql1.myhost.ie","admin_book","root123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("book_test", $con); //Parse Values from Coupon.php Form $first_name = mysql_real_escape_string(trim($_POST['first_name'])); $sur_name = mysql_real_escape_string(trim($_POST['sur_name'])); $sex = mysql_real_escape_string(trim($_POST['sex'])); $age = mysql_real_escape_string(trim($_POST['age'])); $house_no = mysql_real_escape_string(trim($_POST['house_no'])); $street = mysql_real_escape_string(trim($_POST['street'])); $town = mysql_real_escape_string(trim($_POST['town'])); $bscf1 = mysql_real_escape_string(trim($_POST['bscf1'])); $bscf_name1 = mysql_real_escape_string(trim($_POST['bscf_name1'])); $bscf2 = mysql_real_escape_string(trim($_POST['bscf2'])); $bscf_name2 = mysql_real_escape_string(trim($_POST['bscf_name2'])); $from_name = mysql_real_escape_string(trim($_POST['from_name'])); $uploadedfile = mysql_real_escape_string(trim($_POST['name'])); if ($sex == 'girl') { $his_her = 'her'; } else { $his_her = 'his'; } if ($sex == 'girl') { $him_her = 'her'; } else { $him_her = 'his'; } $sql="INSERT INTO details (first_name, sur_name, sex, age, house_no, street, town, bscf1, bscf_name1, andy, bscf2, bscf_name2, his_her, him_her, from_name, uploadedfile) VALUES ('$first_name','$sur_name','$sex','$age','$house_no','$street','$town','$bscf1','$bscf_name1','and','$bscf2','$bscf_name2','$his_her','$him_her','$from_name','$uploadedfile')"; // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $target_path = "uploads/"; $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"; } else{ echo "There was an error uploading the file, please try again!"; } echo 'Thank you '. $first_name . ' for entering your details bro.<br />'; echo 'surname is : '. $sur_name . '.<br />'; echo 'sex is : '. $sex . '.<br />'; echo 'age is: '. $age . ' .<br />'; echo 'bscf friend 1 is : '. $bscf1 . '.<br />'; echo 'bscf name 1 is : '. $bscf_name1 . '.<br />'; echo 'bscf friend 2 is : '. $bscf2 . '.<br />'; echo 'bscf name 2 is : '. $bscf_name2 . '.<br />'; echo 'his_her is : '. $his_her . ' .<br />'; echo 'him_her is : '. $him_her . '.<br />'; echo 'From Name is : '. $from_name . '.<br />'; echo 'Uploaded file is : '. $uploadedfile . '.<br />'; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } ?> I had an iframe working for the last few months on a site at hostgator. Yesterday, it quit working (403 permissions error). After a long bout of trouble-shooting, I found out that it has something to do with mod_security that they have suddenly enabled (have no idea as I'm not a Linux guy). They told me they fixed the problem on my domain by whitelisting it as an exception, but strangely, even though the permissions error went away, the actual src= box of the iframe, which was the url variable I was passing in the url, no longer loads. So.. I'm trying to break this down into the simplest form to figure it out. I just understand php basics so needing some verification that I'm doing this right/wrong. Here's my code.. page1.php Code: [Select] <? $testurl = "http://google.com"; ?> <a href="http://mysite.blah/page2.php?url=<? echo $testurl; ?>">page2.php</a> page2.php Code: [Select] if (isset($_GET['testurl'])) echo $testurl; else echo "sorry dude"; I am only able to print "sorry dude". Am I doing something wrong or shouldn't this send the url? Thanks for the help! hello all, I'm new here and I'm learning mysql/php. Currently I have a dynamic table on one of my webpages, and the loop code looks like this:while ($i < $numRows) { $fname = mysql_result($result, $i, "fname"); $fcode = mysql_result($result, $i, "fcode"); $ftype = mysql_result($result, $i, "ftype"); $fdesc = mysql_result($result, $i, "fdesc"); ?> <tr> <td><a href="showfunction.php?fname=<?php echo "$fname"; ?>" target="_self"> <?php echo "$fname"; ?></a></td> <td> <?php echo "$fdesc"; ?> </td> <td><div align="center"> <?php echo "$ftype"; ?> </div></td> </tr> <?php $i++; } ?> what I would like to do is pass the ''fname'' variable to the "showfunction" page so it can printed from the database. Here is the relevant portion of the page:<body><div class="codeblock"> <div class="title">Code:<br /> </div><code><pre> <?php echo $fcode; ?> </pre></code></div> <br /><pre><hr /> </pre> I know that doesn't work, and I didn't expect it to because there is no way to 'get' the 'fname' variable from the preceeding script. I do not want to use the GET method with this because from what I understand, you can only use it with Forms. I really don't want to put controls in all of my table fields just to be able to pass the function name to the next page. Does that make sense? If I could get a jumpstart on this one last hurdle, I would appreciate it. thank you so much! Cheers. How, if possible, can a $varĀ be passed to theĀ forms action php file? I tried everything with no success. Edited December 24, 2019 by cyberRobotRemoved email address The below script for some reason isn't passing along the product_id variable. Code: [Select] $product_id=$_GET['product']; session_start(); $error=$_SESSION['error']; $content.='<div class="product_information_text review_form"> <div class="review_header">Write a Review for '.$product_name.'</div> <form action="./review_process.php?product='.$product_id.'"> <p class="form_item"><label>Name:</label> <input type="text" name="review_name" size="30" /></p>'; if(isset($error[0])){$content.='<p class="red">This field is required.</p>';} $content.=' <p class="form_item"><label>E-Mail:</label> <input type="text" name="review_email" size="30" /></p> <p class="form_item"><label>Location:</label> <input type="text" name="review_location" size="30" /></p> <p class="form_item"><label>Describe Yourself:</label> <input type="text" name="review_describe" size="30" /></p> <p class="form_item"><label>Review Title:</label> <input type="text" name="review_title" size="30" /></p> <p class="form_item"><label>Best Use of Product:</label> <input type="text" name="review_best_use" size="30" /></p> <p class="form_item"><label>Product Pros:</label> <input type="text" name="review_pros" size="30" /></p> <p class="form_item"><label>Product Cons:</label> <input type="text" name="review_cons" size="30" /></p> <p class="form_item"><label>Product Rating:</label><br /> <div class="rating_radio"><input type="radio" name="review_product_rating" value="1" /> <br />1</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="2" /> <br />2</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="3" checked /> <br />3</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="4" /> <br />4</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="5" /> <br />5</div> <div class="worst">(Worst)</div><div class="best">(Best)</div> </p> <p> </p> <p class="form_item"><label>Comments on Product:</label><br /> <textarea name="review_text" rows="10" cols="60"></textarea> </p> <p><input type="submit" value="Submit" name="Submit" /></p> </form> </div> '; session_unset(); session_destroy(); That code shows the proper product=$product_id value in the form action tag. Code: [Select] $product_id=$_GET['product_id']; $review_name=$_POST['review_name']; $review_name = stripslashes($review_name); $review_name = mysql_real_escape_string($review_name); if($review_name==""){ $error0=1; } else{ $error0=0; } $review_title=$_POST['review_title']; $review_title = stripslashes($review_title); $review_title = mysql_real_escape_string($review_title); if($review_title==""){ $error1=1; } else{ $error1=0; } $review_email=$_POST['review_email']; $review_email = stripslashes($review_email); $review_email = mysql_real_escape_string($review_email); if($review_email==""){ $error2=1; } else{ $error2=0; } $review_location=$_POST['review_location']; $review_location = stripslashes($review_location); $review_location = mysql_real_escape_string($review_location); if($review_location==""){ $error3=1; } else{ $error3=0; } $review_describe=$_POST['review_describe']; $review_describe = stripslashes($review_describe); $review_describe = mysql_real_escape_string($review_describe); if($review_describe==""){ $error4=1; } else{ $error4=0; } $review_best_use=$_POST['review_best_use']; $review_best_use = stripslashes($review_best_use); $review_best_use = mysql_real_escape_string($review_best_use); if($review_best_use==""){ $error5=1; } else{ $error5=0; } $review_pros=$_POST['review_pros']; $review_pros = stripslashes($review_pros); $review_pros = mysql_real_escape_string($review_pros); if($review_pros==""){ $error6=1; } else{ $error6=0; } $review_cons=$_POST['review_cons']; $review_cons = stripslashes($review_cons); $review_cons = mysql_real_escape_string($review_cons); if($review_cons==""){ $error7=1; } else{ $error7=0; } $review_product_rating=$_POST['review_product_rating']; $review_product_rating = stripslashes($review_product_rating); $review_product_rating = mysql_real_escape_string($review_product_rating); $review_text=$_POST['review_text']; $review_text = stripslashes($review_text); $review_text = mysql_real_escape_string($review_text); if($review_text==""){ $error8=1; } else{ $error8=0; } $review_show="n"; date_default_timezone_set('US/Eastern'); $review_date = date("F j, Y, g:i a T"); $error="".$error0."".$error1."".$error2."".$error3."".$error4."".$error5."".$error6."".$error7."".$error8.""; if($error!=="000000000"){ session_start(); $_SESSION['error']=$error; header("Location: ./store.php?product=".$product_id."#review"); } else{ $sql="INSERT INTO $tbl_name3 (product_id, review_show, review_title, review_email, review_name, review_location, review_date, review_describe, review_best_use, review_pros, review_cons, review_product_rating, review_text) VALUES ('$product_id', '$review_show', '$review_title', '$review_email', '$review_name', '$review_location', '$review_date', '$review_describe', '$review_best_use', '$review_pros', '$review_cons', '$review_product_rating', '$review_text')"; mysql_query($sql); echo "Thank You for submitting your review. It should appear on the site within 48 hours."; } The above redirects to store.php?product=#review with no product id. Ideas on why? Hi, can anybody please tell me how i can make "Arson" into a php variable Code: [Select] <script type="text/javascript" src="js/swfobject.js"></script> <script type="text/javascript"> swfobject.embedSWF( "open-flash-chart.swf", "my_chart", "550", "400", "9.0.0", "expressInstall.swf", {"data-file":"ofc-chart.php?crime=Arson"} ); </script> I'm an hour worth of searches into this. It's 2:30. I just want some nice person to give me the answer. I'm trying to pass a variable using href to another page. It works great if the variable is only one word. But it only passes the first word. There are multiple posts on this topic, but I can't seem to get any of those fixes to work for me. Here the code. Code: [Select] <?php $query = "select DISTINCT city from daily where open_bid>0 order by city ASC"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $details=''; $details.='<li class="menu"><span class="name"><a href=list.php?city='.$row['city'].'>'.$row['city'].'</a>'; $details.='</li>'; echo($details); } ?> As you can imagine, some cities names are made up of two words. This is only passing the first word. Thanks for your help. Hi, I am trying to pass a variable when posting a form. This is my form with the select: Code: [Select] <form id="form1" name="form1" method="post" action="products_2.php?id_subcategoria= WHAT SOULD I PUT HERE?"> <select name="subcats" class="subcatsSelectMenu" id="subcats" onchange="this.form.submit()"> <option value="">Ver placas por tipos</option> <?php do { ?> <option value="<?php echo $row_subcats_RS['id_subcategoria']?>"><?php echo $row_subcats_RS['subcategoria_esp']?></option> <?php } while ($row_subcats_RS = mysql_fetch_assoc($subcats_RS));$rows = mysql_num_rows($subcats_RS); if($rows > 0) { mysql_data_seek($subcats_RS, 0); $row_subcats_RS = mysql_fetch_assoc($subcats_RS); } ?> </select> </form>How can I pass the variable in the URL? Thanks Trying to set up an error message when someone tries to upload a file without the approved .ext. I have it working so it won't up load but I am trying to get an error to print out. I was thinking that I could do something like this if the ext are wrong set $errorMsg1 == 1; and then the page will refresh and I would pass that variable to echo out if ($errorMsg1 == 1){ echo "Invalid"; } else { but it isn't passing can anyone help me with this? Tyring to keep it simple this is the code to select an image else{ $result = mysql_query("SELECT * FROM photos WHERE userID LIKE '$clientID'"); while ($r=mysql_fetch_array($result)) { $photo_1=$r['photo_1']; $photo_2=$r['photo_2']; $photo_3=$r['photo_3']; $photo_4=$r['photo_4']; $photo_5=$r['photo_5']; echo " <form enctype='multipart/form-data' action='' method='POST'> <input type='hidden' name='MAX_FILE_SIZE' value='500000' /> <div id='imageTop'>Image &#35;1</div> "; if ($errorMsg1 == 1){ echo "Invalid"; } echo " <div id='imageBottom'> <span class='image'>"; if (empty($photo_1)) { echo " <img src='uploads/noPhoto.gif' width='75' height='75' class='zip'> "; } else { echo "<a href='uploads/$photo_1' ><img src='uploads/$photo_1' width='75' height='75' class='zip'></a> "; } echo " </span> <span class='action'> <input type='file' name='photo_1' class='zip'><br><br> <input type='checkbox' name='delete_1'>Select to Delete image </span> </div> } this is the code of what to do with that image if (isset($_POST['delete_1'])) { $query = "UPDATE photos SET photo_1='' WHERE userID='$clientID'"; $result = mysql_query($query) or die(mysql_error()); echo " <div id='aboutUpdate'><img src='img/loader.gif'> Information is updating</div> "; echo "<meta http-equiv=refresh content=\"0; URL=photos.php\">"; } else if ($one != NULL) { $extension = strrchr($_FILES['photo_1']['name'],'.'); $extension = strtolower($extension); if($extension != '.jpg' && $extension != '.gif' && $extension != '.png' && $extension != '.bmp' ){ $errorMsg1 == 1; echo "<meta http-equiv=refresh content=\"0; URL=photos.php\">"; } else { $photoNumber="_1"; $finalName="$clientID$photoNumber"; $save_path = "uploads/"; $target_path = $save_path . basename( $_FILES['photo_1']['name']); $NewPhotoName = $finalName; $withExt = $NewPhotoName . $extension; $filename = $save_path . $NewPhotoName . $extension; if(move_uploaded_file($_FILES['photo_1']['tmp_name'], $filename)) { $query = "UPDATE photos SET photo_1='$withExt' WHERE userID='$clientID'"; $result = mysql_query($query) or die(mysql_error()); echo " <div id='aboutUpdate'><img src='img/loader.gif'> Information is updating</div> "; echo "<meta http-equiv=refresh content=\"0; URL=photos.php\">"; } } else { This is driving me MAD! The Variable gets passed through the URL but when I try and echo the result I gte NOTHING. First Page. Code: [Select] <?php include'config.php'; $result = mysql_query("SELECT * FROM carbontrust"); while($entry = mysql_fetch_array($result)) Print "$entry[contact] - $entry[company] :: <a href='edit.php?id=$entry[id]'>Edit</a><br>"; exit; ?> Second Page. (Where I want the Variable passed to) Code: [Select] <?php include'config.php'; $id = $_GET['id']; echo "ID: $id"; } ?> Its probably just a stupid error but iv looked through a load of tutorials and this should be correct. :/ Okay, I have been looking into this for the last 3 hours, and cant find shit. I have a page with a javascript game where the player moves around on a map. They have an X and Y coordinate, but I'm having a problem. The problem is I need to store that info in a database, and I'm having trouble learning AJAX. Heres a little list of things: Play loads the game. A php variable is taken from a database. The player goes to those X and Y coordinates. The player may move around. Once they move, the player is sent to a php page that updates the Database information. The page is refreshed to the game again, where they may then move around some more. The problem is, when the page is changed the values are lost. For some reasons cookies aren't working at all (like just not working for anything, even a completely different file.) I heard something about using $_GET or $_POST, but I dont see how... I'm new to php and was wondering how I would be able to do the following: -I have a search page that allows someone to search for a particular user in the database -In the results, I want to have a <a href> link to another page which will run a sql query based on which user's link was clicked and list their posts. So right now I have been trying this code to build that href link: Code: [Select] echo '<td><a href="viewuser.php?username='.urlencode($row['username']).'>View user</a></td>'; However on the following page it is unable to retrieve the 'username' field. Please forgive my limited knowledge of php. I am trying to pass a variable from 1 page to the next. I have SCRIPT A (I didn't write it) that parses an rss feed and then calls SCRIPT B to insert it into a database. Everything works great.. and all I'm trying to do is add a new piece of information. In my db, I added a column called 'city'. There are currently 25 different SCRIPT A's (25 different city names). I could create 25 SCRIPT Bs and call them individually, but I'm trying to use 1 SCRIPT B and just send the city name. I've read about POST and GET but still not sure on this? Can't I just hard code my city name into each SCRIPT A like this: Code: [Select] $city = "miami"; And then put this at the top of SCRIPT B? Code: [Select] $city = $_GET['city']; Well.. apparently, I can't because that doesn't work. Again.. sorry for the dumb question. It's my first time attempting anything with php. Thanks. Help I am trying to pass a php variable into a javasript function. Here is my code.
<a href="<?php echo $row['track']; ?>" download="<?php echo $row['track']; ?>" onclick="myhit(<?php echo $row['track']; ?>)">Download</a> <script> function myhit(top){ alert(top); } </script>the javascript function is never called I have a menu that i want to be added to every page of my coding using a hidden variable, but i cannot get it to work. I using this with a few if conditions. the index page should navigate every page. can anyone help? I have attached the files to illustrate the coding i have done so far. [attachment deleted by admin] i need to pass the id called id from the maim page to an iframe, but it failes to send. i'm wondering if anyone knows why it fails. Code: [Select] <iframe src="details.php?ID=<?php echo $ID; ?>" width="700px" height="150px"> </iframe> <head> <script language="javascript" type="text/javascript" src="datetimepicker.js"> </script> </head> <form action="main.php?id=test.php" method="post"> <p>Start Date: <input name="start" id="start" type="text" size="10"> <a href="javascript:NewCal('start','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a> End Date: <input name="end" id="end" type="text" size="10"> <a href="javascript:NewCal('end','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a> <input name="submit" type="submit" value="Look Up"> </form> <?php if(isset($_POST['submit'])) { $start = $_POST['start']; $end = $_POST['end']; $sql = "SELECT * FROM `corps` WHERE `notedate` BETWEEN '$start' AND '$end'"; $results = mysql_query($sql) OR DIE(mysql_error()); $numrow = mysql_num_rows($results) ; $i = 0; While ($i < $numrow) $shownotes = mysql_result($results,$i,'notes'); echo $shownotes."<br>"; { Echo "Records found ".$i."<br>"; $i++; } } The $start, and $end don't seem to be getting any values Hello I'm trying to pass a php variable from produto.php to another file descProduto.php it ajax but without success. Please someone can tell me what I'm doing wrong? The ajax is working fine but I can't get the value/variable on descProduto.php
file index.php
<script type="text/javascript" src="jquery-1.11.min.js"></script> |