PHP - Passing A Variable Without Using Get And Post
www.mywebpage.co.uk/page22
Is it possible to produce a variable with the value = page22 using only the url above, I know that usually you would use get and post, but I was just curious to know if this had been done before. Similar TutorialsHi, I'm trying to edit some database fields, I have text1, text2, text3, text4, text5, text6 etc.. They are displayed on the index.php page, with an edit link so the user can choose which set to edit // Extract details from database $sql = "SELECT * FROM data WHERE id=1"; $stmt = $db->prepare($sql); $stmt->execute(); $e = $stmt->fetch(); <h1><?php echo $e['text1']) ?></h1> <p><?php echo ($e['text2']); ?></p> <p><a href="edit.php">EDIT</a></p> <h1><?php echo $e['text3']) ?></h1> <p><?php echo ($e['text4']); ?></p> <p><a href="edit.php">EDIT</a></p> <h1><?php echo $e['text5']) ?></h1> <p><?php echo ($e['text6']); ?></p> <p><a href="edit.php">EDIT</a></p>
edit.php: // Extract details from database $sql = "SELECT * FROM data WHERE id=1"; $stmt = $db->prepare($sql); $stmt->execute(); $e = $stmt->fetch(); <form method="post" action="process.php" enctype="multipart/form-data"> <label>Page Title <input type="text" name="text1" maxlength="90" value="<?php echo $e['text1'] ?>" /> </label> <br> <label>Title Text</label> <textarea name="text2"><?php echo $e['text2'] ?></textarea> <input id="button" type="submit" name="submit" value="Save Changes" /> and then update them: process.php $sql = "UPDATE data SET text1=?, text2=? WHERE id=1 LIMIT 1"; $stmt = $db->prepare($sql); $stmt->execute( array( $_POST['text1'], $_POST['text2'] ) ); $stmt->closeCursor(); Question: How can I pass the form values dynamically from the index.php page so I don't have to hard code text1, text2 etc into the edit.php and process.php page and have a different update & process page for each set of data?
Thanks in advance. i want to pass the information getting from the form and after storing in to the variables to a new php file ..how to pass all the value getting from the form I have an hml page that uses option values and lets the user select values. the values are php pages which when they submit pass the chosen value to the next page I show a snip below. I wanted to have the form action grab the formVar passed to it- but I can't seem to get it going. I figure I just may not be putting the post in correctly- any help appreciated <head><title>page2</title></head> <body> <form action=="<?php $_POST['formVar']; ?>" method="POST"> i created an array like this while{ $ir = 0; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['id_sub']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['seminar_topic']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['seminar_mark']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['attendance']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['internal_mark']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['external_mark']; $ir++; } echo "<input type='hidden' name='ar_std' id='ar_std' value='$stud' /> </table>" ; and it is able to print in the same page using foreach ($stud as $v1) { echo "$v1\n<br>"; foreach ($v1 as $v2) { echo "$v2\n<br>"; } } and in the next page $ar_stud[]=$_POST["ar_std"]; I'm getting an error PHP Warning: Invalid argument supplied for foreach() in save.php on line 25 PHP Stack trace: I'm stuck at trying to figure out out to complete the 3 Step scripts to accomplish passing $variables between 2 different servers. Since there will actually be 12 Non-POST $variables involved in the SERVER #1 to SERVER #2 transfer , it doesn't appear that trying to put these all in a URL string and going the 'GET' route is practical.
I'm just using 3 short test variables in the examples. My eyeballs started rolling within I ran across something about 'CURL' that might be a necessary part of the solution?
The code I have been able to hammer out so far is below as STEP 1, STEP 2 and STEP 3.
STEP 1
<?php // submit.php // STEP 1 // On (LOCAL) SERVER #1 TO relay $variables to 'process.php' on (REMOTE) SERVER #2 // To submit $variables to directly another destination server script // NOTE: The $variable are NOT the result of Form Input !!! // For login Authenticaion ALL 3 must match db entries on SERVER #2 // NOTE: (Again) The $variables are NOT the result of Form Input !!! $userid = "adam"; $passwd = "eve"; $pscode = "peterpan"; // NOTE: (Again) The $variable are NOT the result of Form Input !!! // These $variables are needed for MySQL db INSERT on the destination URL server // For testing simplicity (actual data will be 12 $variables) $a = "apple"; $b = "banana"; $u = "1234567; // // Not sure if something called 'CURL' is needed here ??? // $submit_to_url = http://www.blahblah.com/process.php"; ?>STEP 2 <?php // processor.php // STEP 2 // ON SERVER #2 TO RECEIVE DATA DIRECTLY FROM SERVER #1 'submit.php' // To receive and process the $variables into a MySQL db on SERVER #2 // NOTE: The $variables are NOT the result of Form Input !!! // First validate $userid, $passwd & $pscode against `verify` table MySQL records require '/SERVER_2_securelocation_for_database_connection/secret_mysqli.php'; if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // // Not sure if something called 'CURL' is needed here ??? // // These login $variables are from submit.php on SERVER #1 $userid $passwd $pscode $sql="SELECT `userid`, `passwd`, `pscode` FROM `verify` WHERE `userid` = '$userid'" AND `passwd` = '$passwd` AND `pscode` = '$pscode'; $result = mysqli_query($con,$sql); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } // // Then some Authentication code if ALL 3 components match // // If Authentication = true then $passed = "YES" must sent // be sent back to the 'finalstep.php' script on SERVER #1 // If Authentication (or connection) = false ... $passed = "NO" $return_to_url = http://www.blahblah.com/finalstep.php"; // These $variables are from submit.php on SERVER #1 $a = "apple"; $b = "banana"; $u = "1234567"; $sql="INSERT INTO `data` (`a`, `b`, `u`) VALUES ('$a', '$b', '$u')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } // If $SQL INSERT into `data` on SERVER #2 works ... // $status = "Pending" must be sent back to the 'finalstep.php' // script on SERVER #1 for MySQL db Table insertion // If $SQL INSERT into `data` = false, then $status = "Error" // NOTE: The '$u' $variable also needs send back to finalstep.php !!! $return_to_url = http://www.blahblah.com/finalstep.php"; mysqli_close($con); ?>STEP 3 <?php // finalstep.php // STEP 3 // ON SERVER #1 TO RECEIVE DATA DIRECTLY BACK FROM SERVER #2 process.php // To receive the $passed, $status and $u $variables for final step action // NOTE: The $variable are NOT the result of Form Input !!! require '/SERVER_1_securelocation_for_database_connection/secret_mysqli.php'; if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // These $variables are from process.php on SERVER #2 $passed $status $u $sql="UPDATE `tracking` SET `passed` = '$passed', `status` = '$status' WHERE `uniqueid` = '$u' "; $result = mysqli_query($con,$sql); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con); ?>Thanks very much for any assistance and guidance. -freakingOUT Greetings... I have been staring at my whiteboard pondering a new architecture for processing data in an application. New for me anyways. I want to create a more centralized and modular method of handling data. For ease of explanation I will put it into the context of a login system which is where I first started thinking about this. I know there are a lot of login systems out there but I wanted to create one from scratch which utilizes PDO although that specific thing is not germane to my main question. Here we go... Lets say that for my Registration, Login and Forgot Password pages the forms on each page were directed to "Process.php" The idea is that process.php will provide the centralized platform to deal with data, acting as a choke point in the application making it easier to secure. This will also provide the means to quickly develop new parts of an application knowing that my methods of dealing with data area already well defined and secure. There is one hole in the idea that I can see though. If the user data being submitted to the process.php page does not meet the security requirements then the user must be sent back to the previous page. I dont' want to lose the data they have already entered into the forms. ie. I want to have it appear in the form fields... makes sense right. Now here comes my question... is there a way to pass POST data when using header("location: http://mySite/previousPage.php") It seems from my experiments that the data is lost. I do not use header(); often. In previous designs I have usually created each part of a login system as seperate and self contained entities apart from using a common db object. I know there are other ways around this, using session data for instance but this idea has been eating away at me for a little while and I feel its time to ask around for some advice. It has become a matter of curiosity. I have found some info on sending POST data using header but it did not seem to meet the requirement that the user and the POST data be sent to another page synchronously. At first I thought that maybe I would just do validation on the frontend / view pages (not to be taken as clientside) and if it was valid, then submit it to process.php, validate it again the let it be handled appropriately to its particular end but then I run into the same problem plus there is the extra overhead of validating the data twice. I guess thats it for now. Sorry if that was a little long-winded... its part of my process, helps me to better understand what I really want to know. Using header() on a receiving page from a form page... the redirecting header() with POST data, sending the user to a new/previous page. Possible? I am retrieving a rowfrom a table and when I post the row variable it doesnt read it. ___ $query = "SELECT * FROM $tbl_name"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['name']; echo "<br />"; $postinfo = 'p_doctor_name=' . $row .'&p_name_type=A&p_search_type=BEGINS'; __ This outputs p_entity_name=&p_name_type=A&p_search_type=BEGINS Note that it is missing $row Do I need to put it in an array? 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 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 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. 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> 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? 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. :/ 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! 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 { 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. i have two functions. In function two it has $id=9. how do i get function one to echo $id? how do i adjust the below example to accomplish this? Code: [Select] $newdb = new Database(); class Database { function one() { $newdb->two(); echo $id; } function two() { $id = 9 return $id; } } 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 have this code in a form, i need to pass a variable $time to next page, how can i do that ? if( $sErr ) print "<script language='javascript' type='text/javascript'>location.href='#error';</script>";;; else: print "<script language='javascript' type='text/javascript'>location.href='paypal.php';</script>";;; |