PHP - How Do I Get This Variable To That Page?
Code: [Select]
SOLVED I want to use a variable I defined on another page, but I don't know how. Here's the original page with the variable: cart.php Code: [Select] $total += $qty*$row['price']; Here's the new page new page without the variable: checkout.php Code: [Select] //I want the value $total onto this page Thanks Similar TutorialsSome code from my pages ,
Page1 ( Redirecting page )
<html> <title>login_redirect.</title> body> <form name="redirect" action="http://mysite/page2.php" method="post"> <input type="hidden" name="mac" value="$(mac)"> </form> <script language="JavaScript"> <!-- document.redirect.submit(); //--> </script> </body> </html>Page 2 ( select product ) <?php session_start(); ini_set('display_errors',1); error_reporting(E_ALL); include '../lib/config.php'; include '../lib/opendb.php'; // get user mac adres from redirect post page1 $_SESSION['macid'] = $_POST['mac']; // set $macid for other use ( maybe not needed, am learning ) $macid = $_SESSION['macid']; // echo $macid does show mac adress, so variable is not empty here if (!empty($_POST["submit"])) { $product_choice = $_POST['accounttype']; $query= "SELECT AccountIndex, AccountCost, AccountName FROM AccountTypes WHERE AccountIndex='$product_choice'"; $result = mysql_query($query) or die('Query failed. ' . mysql_error()); while($row = mysql_fetch_array($result)) { $_SESSION['AccountIndex'] = $row['AccountIndex']; $_SESSION['AccountCost'] = $row['AccountCost']; $_SESSION['AccountName'] = $row['AccountName']; } header('Location: page3.php'); } // did leave out the other/html/form stuff herePage 3 ( show Session variables ) <?php ini_set('display_errors',1); error_reporting(E_ALL); session_start(); print_r($_SESSION); ?>Now, on page 3 i do see the right session varables, only the "macid" is empty. why ? 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>";;;
My index.php, $output .= ' <div class="col-sm-3 col-lg-4 col-md-3"> <div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;"> <audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;"> <source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive"> </audio> <p align="center"><strong> '. $row['voice_name'] .'</strong></p> <p style="font-size: 12px;"> Id : '. $row['voice_id'].' <br /> Name : '. $row['voice_name'].' <br /> Gender : '. $row['voice_gender'].' <br /> Genres : '. $row['voice_genres'].' <br /> Voice Modulation : '. $row['voice_voice_modulation'].' <br /> Languages : '. $row['voice_languages'].' <br /> Jingle Moods : '. $row['voice_jingle_moods'].' <br /> Ivr : '. $row['voice_ivr'].' <br /> </p> <button type="button" class="btn btn-primary" type="submit" onclick="addCart('. "'".$row["voice_id"]."'".','."'". $row["voice_name"]."'".');" style="padding: 5px 83px 5px 83px;">Add to PlayList </button> same page ajax :
<script> function addCart(voice_id, voice_name) { $.ajax({ type: 'POST', url: 'cart.php', data: { voice_id : voice_id, voice_name : voice_name }, dataType: 'text', success: function(data) { // alert(data); } }); } $(document).ready(function(){ }); </script> and get.php
<?php $voice_id =" "; $voice_name=" "; if(isset($_POST['voice_id']) && isset($_POST['voice_name'])) { $voice_id = $_POST['voice_id']; $voice_name = $_POST['voice_name']; } echo "$voice_id, . "&". , $voice_name"; ?> if click button, the value send but the get.php not properly get the value and display on the php page. Edited June 12, 2019 by aveeva I currently have a php form that asks for first name, last name and email address then when they click submit it sends me an email with this information. I also have a javascript that pops up a window saying their message was sent with an ok button that redirects them back to the main page. I'd like to change this to redirect them to a new php page with a certificate with their name on it taken from the previous php form (but still email me the information). My form action currently points back to the same php page for verification of information (like valid email address, etc.) so I can't point that to a new page. Is there any way to do this? The variables I have for the first name and last name are just $firstname and $lastname. I want to include a variable (for example an object $user) in each PHP page. Previously I declared $var in an include file then included that file in every page, however it generates an error in Zend Studio and it's also not very good programming style. I want to know how I can do it any other way. I was thinking of using constants but I don't know if constants should be used for this purpose and also I do not think constants can be defined as objects. Thank you very much for your help. Im not sure that it is possible, but I thought I would post and ask anyway. I want to use a page redirect such as: Code: [Select] <?php header("Location: http://www.redirect-to-home.com/"); exit; ?> However, due to the nature of the redirect and the header having to be sent first, Im not sure how I could use a variable or probably better, something like HTTP_HOST. In a post I made elsewhere on here, someone posted this code: Code: [Select] if($_SERVER['HTTP_HOST'] == "localhost"){ // For local development define('SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/template'); define('SITEPATH', $_SERVER['DOCUMENT_ROOT'] . 'template'); } else{ // For production web define('SITEURL', "http://" . $_SERVER['HTTP_HOST']); define('SITEPATH', $_SERVER['DOCUMENT_ROOT']); I began thinking then, I wonder is something like that could be used as a page redirect as a very basic and simple prevention to direct access to a specific folder on the site? But Im not sure how to make it work, Im just not that experienced in PHP yet. I dont know if using an index.html file would be better over an index.php file either. Im still experimenting a little trying to figure things out. So is there a way to use a php variable to redirect someone back to the home page? I know you can use .htaccess and things like that as well, but I wanted to see if this could be done also. Thanks in advance for any help. Hello, I'm trying to build a small project; and as part of it - I want users to search and when presented with relevant enteries in the SQL database - they should be able to click and retrieve a page dedicated to that entity. The problem I am having is in passing the 'id' of the search result onto the next (description) page. Code: [Select] $SQL = "SELECT * FROM loads"; $result = mysql_query($SQL); while ($db_field = mysql_fetch_assoc($result)) { $clickid = $_GET['id']; print $db_field['id'] ."<a href=\"load_info.php?id=$id" . $id . "\" target=\"_self\" title=\"\">More Info</a>;"; print $db_field['depart:'] . "<BR>"; print $db_field['dest'] . "<BR>"; } I thought it was easy enough to pass the variable like above ("load_info.php?id=$id) and then grab it on the next page like so: $val = $_GET['clickid']; Unfortunately, it doesn't retrieve the info from the page before. If I insert a number in there, it does work correctly, but I really need the ID of the database entry to pass on so as to provide the user with further information. If anyone could help it would be appreciated. L. i knw dis mst a simple question but how to pass variable to other page for eg i hav created a page where user submits username n telephone then via sms some random number goes to user mobile ...i want this random number variable in other page dis is my code for startreg.php <form action="startregprocess.php" method="post"> username:<input type="text" name="username"> telephone<input type="text" name="telephone" <input type="submit" name="submit"> </form> <?php srand ((double) microtime( )*1000000); $random_number = rand( ); echo $random_number; ?> i want tht $random_number in other page called startregprocess.php Hi, I am new to Php and having problems with redirecting of page particularly sending variables across pages. I have this page1 which contains an if else statement. If { User types in two text fields code should be executed and the page should be resubmitted to the same page with database results. For this reason I am using the form attribute of the page and directing the action variable in the form attribute to page1 ( this page itself) on submit. Else { Now if user types in only one text field, it should go to another page wherein the another page should be able to receive the value entered by the user in the page1. I have got suggestions saying I can do this by using page header redirect to another page and concating the value of the textbox to the header variable. I am using this in page 1 <code> header("Location: Decryption.php?usersubmit=".urlencode($_POST($usersubmit))); </code> // Usersubmit is the value entered in the textbox field by the user. and in page 2 <code> $userId = $_GET['usersubmit']; </code> But of no use. I also tried creating a session variable here and using the session variable in the page2. But that does not work either. } Someone please help me. Let me know if you have any questions? Thanks, So i got the following problem: i got some pages : index.php , comment.php, viewArticle.php When i try to submit something from comment.php appear a error "Undefined variable:result" The var result is defined in index.php When i click on one article from the list the function viewArticle() is requiring viewArticle.php and the function addcomment() is requiring comment.php The addcomment function() is in viewArticle function() I can't figure out what's wrong but I guess have something to do whit the form action="index.php?action=viewArticle&articleid=<?php echo $result['article']->id?>" index.php code Code: [Select] <?php include('config.php'); $action = isset($_GET['action'])?$_GET['action']:""; switch($action) { case 'viewArticle':viewArticle();break; default:homepage(); } function homepage() { $result = array(); $data = Article::getlist(1); $result['article']=$data['result']; $result['total']=$data['totalrows']; require('homepage.php'); } function viewArticle() { if( !isset($_GET['articleid']) )homepage(); $result = array(); $result['article'] = Article::getbyid((int)$_GET['articleid']); $result['name'] = $result['article']->name; addcomment(); require('viewArticle.php'); } function addcomment() { if(isset ($_POST['submit'] )) { $comment = new Comment; $set = array(); $set['usern']="HJhj"; $set['com']="aca wqeq"; $set['page']=7; $comment->storeFormValues($set); $comment->insertc(); } else require('comment.php'); } ?> viewArticle.php code Code: [Select] <center> <h1> <?php echo $result['article']->text ?> </h1> comment.php code: Code: [Select] <form method='post' action="index.php?action=viewArticle&articleid=<?php echo $result['article']->id?>" > <input type="hidden" name="id" value="56"/> <ul> <li> <input type="text" name="usern" id="usern" /> </li> <li> <textarea name="com" id="com" COLS=40 ROWS=6></textarea> </li> <input type="hidden" name="page" value="56" /> <input type="submit" name="submit" value="submit" /> </form> Hi im trying to pass a variable through a url. Here's the code : echo"<td class='tableContent'><span onmouseover=\"tooltip.show('Click to add details to ".$result['workObject']."');\" onmouseout=\"tooltip.hide();\"><a href='addRemarksBucc.php?workObject=".$result['workObject']."'>".$result['systemRemarks']."</a></span></td>"; and here's the code to the next page: <table width="550" border="0" cellspacing="5" cellpadding="0"> <tr> <td width="78" valign="top">Work Object</td> <td><input name="workObject" id="workObject" type="text" value="<?php $_GET['workObject']; ?>" /></td> </tr> <tr> <td valign="top">Remark Details</td> <td><textarea name="errorMessage2" cols="50" rows="10" id="errorMessage2" accesskey="p" tabindex="1"></textarea> <input name="workObject2" type="hidden" value="" /></td> </tr> <tr> <td valign="top"> </td> <td> </td> </tr> <tr> <td> </td> <td><input name="submit" type="submit" class="btn" id="submit" accesskey="R" tabindex="11" value="Submit" /> <input name="reset" type="reset" class="btn" id="reset" accesskey="e" tabindex="12" value="Reset" /></td> </tr> </table> What am I doing wrong? The address bar shows the right url but the second page doesn't display any value for workObject. Thanks! Ok this is some noob question here I have a page that has few separate pieces of php code embeded within html code. Each piece is separated with Code: [Select] <?php ... ?> tags, everything works fine. I need to assign a variable in first (from the top) piece of php code. Then I want to be able to use that variable in all others php pieces across this same page.... I searched and searched and first tried to do it like : First piece: Code: [Select] <?php function id() { $id="blah"; } ?> Second piece : Code: [Select] <?php id(); ... echo $id; ?> didn't work, then I tried First place: Code: [Select] <?php $id="blah"; function id() { global $id; } ?> Second piece : Code: [Select] <?php echo $id; ?> After struggling and reading for few days all about global, static, and regular variables i finally decided to ask professionals to help.... please let me know if you need me to make the question description more clear or smn id not passing onto next page. when i view the source code the id value is there. <a href='view_designs2.php?id='198'> but when the next page loads there is nothing in the address bar. Code: [Select] <?php echo "<table width='1000' align='center'>"; $data=mysql_query("SELECT * FROM design WHERE jobno='$id' AND status!='rejected'") or die (mysql_error()); $counter = 0; while ($info=mysql_fetch_array($data)){ $img5=$info['name']; $id=$info['id']; $img=$info['thumbs']; echo "<td>"; echo "Design By "."$img5 "."<br><br>"; echo "<a href='view_designs2.php?id='$id'><img src='../dthumbs/$img' style='text-align: center; width:250px; max-height:250px; border: solid 10px; border-radius: 5px; border-color:tan; -moz-box-shadow: 3px 3px 4px #000; -webkit-box-shadow: 3px 3px 4px #000; box-shadow: 3px 3px 4px #000; -ms-filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000'); filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000'); ''>"; echo "<br><br></td>"; $counter = $counter + 1; if ($counter==3){ echo "<tr>"; $counter=0; } } echo "</tr></table>"; ?>' Hi, I know it is probely not a regex question but I don't know the right category. I have 2 variables like $variable1 and $ variable2 which are placed in a loop now I want the $variable to be echo't in a link like <a href="http://exampe.com/$variable1"/> On this dynamicly generated page I want to output the $varible1 of this link and $variable2 while($row = mysql_fetch_assoc($result)) { echo " <tr>"; echo " <td>" . $row["variable1"] . "</td>"; echo " <td>" . $row["variable2"] . "</td>"; echo " </tr>"; code is Code: [Select] <?php $limit=12; if(isset( $_GET['page'])) $page=$_GET['page']; if($page<=0) $page = 1; else {$start=0;} $sql=mysql_query("select * from tbl_gallery where status=1 And category_name='0'"); $count=mysql_num_rows($sql); $totalcount=ceil($count/$limit);$start=($page-1)*$limit; $s=mysql_query("select * from tbl_gallery where status=1 And category_name='0' limit $start, $limit"); while($result=mysql_fetch_array($s)){ $start++; ?> please find the mistake i'm creating a page counter which updates a value in a database each time the page is loaded. I'm trying to make it so that it checks to see if a session has been set, if not, it updates the database, and then sets the session. This way it wont update every time someone refreshes the page. $id=$_GET['id']; if(!isset($_SESSION[$id])){ $_SESSION[$id]= $id; $views = $row['views'] + 1; $update_views=mysql_query("UPDATE topic SET views='".$views."' WHERE topic_id='".$id."'") i want to set the session variable as that of the page id ($id) The problem is that it keeps updating the database everytime the page is reloaded. I'm not sure if i'm setting the session variable correctly. Any ideas would be great Thanks I have a class that I created, halfway down my page I call a function from the class which prints some code and also changes a variable inside the class. It's a search class basically it prints out the search results and saves the total amount of results into the variable. I want to display the amount of results above the results like so:- echo $Search->results; $Search->GetResults('foo'); The problem is that $Search->results will be equal to NULL until the variable is updated in the function GetResults. Hope that makes sense, am I going about this wrong? Hi dear community i want to run a Curl to get the contents of a remote web page into a PHP variable <?php // // The PHP curl module supports the received page to be returned in a variable // if told. // $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://www.myurl.com/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $result=curl_exec ($ch); curl_close ($ch); ?> I declare this variable:($ch) Well - can i work with this variable - eg. to parse this with a parser!? look forward to hear from you $result=curl_exec ($ch); gretings Code: [Select] <form action='test.php' method='post'> <input id="Username" type="hidden" name="date2" /> <input type="submit" name="action" value="Submit"></form> Hi I want to pass a Username javascript variable to test.php as hidden, anyone can help? When code this Code: [Select] <input id="Username" type="input" name="date2" />Data can pass to test.php When code this Code: [Select] <input id="Username" type="hidden" name="date2" />Data fail to pass over 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()); } ?> |