PHP - Variable In Url Doesn't Show Up On Next Page
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! Similar Tutorialshey guys, I'm in the process of transforming my static html website into "something" more dynamic. I came across an article on bilingual website (http://www.jacksonengineering.net/proj_phplanguage.php) and I basically used the same idea for my project. Everything works fine except for one thing - links to different language web pages are generated correctly page.php?lang=pl but when I click on the link, the url loses the variable and looks like page.pl.php What to do? Code: [Select] language.php <?php //the url ? language declaration should have preference over the page name $pagename = basename($_SERVER['PHP_SELF'],".php"); $pagenamearray = explode(".",$pagename); if (count($pagenamearray) == 2){ //there is currently a bi-lingual site page loaded $_SESSION['language'] = $pagenamearray[1]; $urllang = $pagenamearray[1]; }else{ //this page must be a non bi-lingual page $urllang = 'en'; } //check for a language selection on the url if(isset($_GET["lang"])){//language has been passed via url $_SESSION['language'] = htmlspecialchars($_GET["lang"]); //set it what was found } ///if there still is no language set, go with english for a default if(!isset($_SESSION['language'])){ $_SESSION['language'] = 'en'; } //now we think we have the session language figured out // //now check for a version of the current page in the desired language //lets make some things clear first //the current page url is either en or pl from $urllang if($urllang != $_SESSION['language']){ //if the url isn't the same as the $_SESSION if($_SESSION['language'] == 'en'){//if it should be english then load the english header("Location: $pagenamearray[0].php"); exit; } if($_SESSION['language'] == 'pl'){ //construct the name of the file if it existed filename.pl.php $plVersion = $pagenamearray[0] . ".pl.php"; //we have to check if a pl version actually exists of this page if(file_exists($plVersion)){//redirect if it exists header("Location: $plVersion"); exit;//stop executing things }else{$pagelangnotfound = true;} } } ?> Code: [Select] header.php <?php if ($_SESSION['language'] != 'en'){ echo 'Select Language: <a href="'. $_SERVER['PHP_SELF'] . '?lang=en"><img src="img/gb.gif" alt="English" class="off" /></a>'; }else{echo 'Wybierz J&#281;zyk: <img src="img/gb.gif" alt="English" />';} ?> <?php if ($_SESSION['language'] != 'pl'){ echo '<a href="'. $_SERVER['PHP_SELF'] . '?lang=pl"><img src="img/pl.gif" alt="Polish" class="off" /></a>'; }else{ echo '<img src="img/pl.gif" alt="Polish" />'; } ?> Code: [Select] menu.php <?php if($pageOn == 'index.php'){?> id="selected"<?php }?>> <a href="index.php">Main Page</a> Code: [Select] page.php <?php session_start(); include "language.php"; $pageOn = basename($_SERVER['PHP_SELF']); $mItem = $pageOn; ?> <?php include("header.php"); ?> <?php include("menu.php"); ?> English content Code: [Select] page.pl.php <?php session_start(); include "language.php"; $pageOn = basename($_SERVER['PHP_SELF']); $mItem = $pageOn; ?> <?php include("header.php"); ?> <?php include("menu.php"); ?> Polish content I have a page that shows entries in a guestbook I'm making, and below the entries there is supposed to be a form to write an entry. Except, none of the HTML after the script to show the entries shows up on the page. I have no clue what's wrong. Here is the script to show the entries. $n is name, $d is date, $s is site (optional), and $m is message. $file = fopen("posts.txt", 'rb'); flock($file, LOCK_SH); while(!feof($file)){ $entry = fgetcsv($file, 0, '|'); if(empty($entry)){exit;} $d = $entry[1]; $n = $entry[2]; $s = $entry[3]; $m = $entry[4]; echo ' <table style="border: #3399AA 1px solid;"><tr style="background: #3399AA; font: bold 10px verdana,sans-serif; color: #FFFFFF;"> <td width="170">'.$n.'</td> <td align="right" width="170">'.$d.'</td> </tr> '; if($s != 'none'){ echo ' <tr><td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;"> <b>Site: </b><a href="'.$s.'">'.$s.'</a> <center><div style="width: 250; height: 1px; background: #3399AA; margin: 10px;"></div></center></td></tr> '; } echo ' <tr> <td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;">'.$m.'</td> </tr></table><br> '; } flock($file, LOCK_UN); fclose($file); The file it is reading looks like this: Code: [Select] |11:51 am, 3rd Nov 2010|Memoria|none|Hello. :) |11:51 am, 3rd Nov 2010|Memoria|http://sitehere|Hello again. |11:51 am, 3rd Nov 2010|Memoria|none|How are you doing? Thanks! I'm trying to do a simple PHP form with Securimage Captcha and whenever I add this variable "$securimage = new Securimage();" the page displays nothing. Could someone please help me with this? My php file is already in the securimage directory so that's why I'm pointing directly to the file. I'm trying to expand my knowledge on some more str type functions, and I've always wanted to learn implode and explode, but I was just too lazy. Anyways, for some reason, if I type in: salad,pizza,apples - the first value in the array, salad, doesn't show up. o.O <?php $favorite_food = $_POST['favorite_food']; if(!$favorite_food) { ?> <form action="words.php" method="POST"> <input type="text" name="favorite_food"> <input type="submit"> </form> <?php } else { $ex = explode(",", $favorite_food); $amount = count($ex) + 1; while($i < $amount) { echo $ex[$i]."<br/>"; ++$i; } } ?> I know arrays start at 0, so thats why I added 1 to the count. I need to copy a table from one code to another. But I couldn't figure out how to do it properly. Just tried to copy code from one file to another but it doesn't work the same. I need to find where to change the code to show right columns.
https://easyupload.io/maoa9h - zipped cart.php (original code with right table) and review.php (the one that doesn't show right table)
We need to copy the table from cart.php: But it doesn't work. The quantity column doesn't show in review.php - as you can see here https://ibb.co/brP0yy1 Quesion: Show each movie in the database on its own page, and give the user links in a "page 1, Page 2, Page 3" - type navigation system. Hint: Use LIMIT to control which movie is on which page. I have provided 3 files: 1st: configure DB, 2nd: insert data, 3rd: my code for the question. I would appreciate the help. I am a noob by the way. First set up everything for DB: <?php //connect to MySQL $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); //create the main database if it doesn't already exist $query = 'CREATE DATABASE IF NOT EXISTS moviesite'; mysql_query($query, $db) or die(mysql_error($db)); //make sure our recently created database is the active one mysql_select_db('moviesite', $db) or die(mysql_error($db)); //create the movie table $query = 'CREATE TABLE movie ( movie_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, movie_name VARCHAR(255) NOT NULL, movie_type TINYINT NOT NULL DEFAULT 0, movie_year SMALLINT UNSIGNED NOT NULL DEFAULT 0, movie_leadactor INTEGER UNSIGNED NOT NULL DEFAULT 0, movie_director INTEGER UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (movie_id), KEY movie_type (movie_type, movie_year) ) ENGINE=MyISAM'; mysql_query($query, $db) or die (mysql_error($db)); //create the movietype table $query = 'CREATE TABLE movietype ( movietype_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, movietype_label VARCHAR(100) NOT NULL, PRIMARY KEY (movietype_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); //create the people table $query = 'CREATE TABLE people ( people_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, people_fullname VARCHAR(255) NOT NULL, people_isactor TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, people_isdirector TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (people_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); echo 'Movie database successfully created!'; ?> ******************************************************************** *********************************************************************** second file to load info into DB: <?php // connect to MySQL $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); //make sure you're using the correct database mysql_select_db('moviesite', $db) or die(mysql_error($db)); // insert data into the movie table $query = 'INSERT INTO movie (movie_id, movie_name, movie_type, movie_year, movie_leadactor, movie_director) VALUES (1, "Bruce Almighty", 5, 2003, 1, 2), (2, "Office Space", 5, 1999, 5, 6), (3, "Grand Canyon", 2, 1991, 4, 3)'; mysql_query($query, $db) or die(mysql_error($db)); // insert data into the movietype table $query = 'INSERT INTO movietype (movietype_id, movietype_label) VALUES (1,"Sci Fi"), (2, "Drama"), (3, "Adventure"), (4, "War"), (5, "Comedy"), (6, "Horror"), (7, "Action"), (8, "Kids")'; mysql_query($query, $db) or die(mysql_error($db)); // insert data into the people table $query = 'INSERT INTO people (people_id, people_fullname, people_isactor, people_isdirector) VALUES (1, "Jim Carrey", 1, 0), (2, "Tom Shadyac", 0, 1), (3, "Lawrence Kasdan", 0, 1), (4, "Kevin Kline", 1, 0), (5, "Ron Livingston", 1, 0), (6, "Mike Judge", 0, 1)'; mysql_query($query, $db) or die(mysql_error($db)); echo 'Data inserted successfully!'; ?> ************************************************************** **************************************************************** MY CODE FOR THE QUESTION: <?php $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); mysql_select_db('moviesite', $db) or die(mysql_error($db)); //get our starting point for the query from the URL if (isset($_GET['offset'])) { $offset = $_GET['offset']; } else { $offset = 0; } //get the movie $query = 'SELECT movie_name, movie_year FROM movie ORDER BY movie_name LIMIT ' . $offset . ' , 1'; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_assoc($result); ?> <html> <head> <title><?php echo $row['movie_name']; ?></title> </head> <body> <table border = "1"> <tr> <th>Movie Name</th> <th>Year</th> </tr><tr> <td><?php echo $row['movie_name']; ?></td> <td><?php echo $row['movie_year']; ?></td> </tr> </table> <p> <a href="page.php?offset=0">Page 1</a>, <a href="page.php?offset=1">Page 2</a>, <a href="page.php?offset=2">Page 3</a> </p> </body> </html> I want to show a cookie of a referral's username on a sign up page. The link is like this, www.mysite.com/signup?ref=johnsmith. The cookie doesn't show if I go to that url page. But it does show up once I reload the page. So I'm wondering if it's possible to show the cookie the first time around, instead of reloading the page? Here is my code. // This is in the header $url_ref_name = (!empty($_GET['ref']) ? $_GET['ref'] : null); if(!empty($url_ref_name)) { $number_of_days = 365; $date_of_expiry = time() + 60 * 60 * 24 * $number_of_days; setcookie( "ref", $url_ref_name, $date_of_expiry,"/"); } else if(empty($url_ref_name)) { if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; } } else {} // This is for the sign up form if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; ?> <fieldset> <label>Referred By</label> <div id="ref-one"><span><?php if(!empty($user_cookie)){echo $user_cookie;} ?></span></div> <input type="hidden" name="ref" value="<?php if(!empty($user_cookie)){echo $user_cookie;} ?>" maxlength="20" placeholder="Referrer's username" readonly onfocus="this.removeAttribute('readonly');" /> </fieldset> <?php }
How would I write this in php?: Code: [Select] If $url does not begin with 'http://' $url = '' I want to assign nothing to the variable if it doesn't begin with http:// Thanks! Hello all, I can't get the data store in the $ART_ID variable to pass into the database. The original $Artisan variable is set up like this: 1. Artisan Name. So the explode is taking just the number. If I put an echo after the explode and the $ART_ID variable it outputs the correct information but it doesn't store in the database as that data. The query is in correct order too. Thanks in advance. $CType_Type = $_REQUEST["CTYPE_Type"]; $Artisan = $_REQUEST['Artisan']; $Quantity = $_POST['Quantity']; $HAnswer1 = $_POST["HAnswer1"]; $HAnswer2 = $_POST["HAnswer2"]; $HAnswer3 = $_POST["HAnswer3"]; $HAnswer4 = $_POST["HAnswer4"]; $break = explode(".", $Artisan); $ART_ID = $break[0]; if(!$Quantity) { die('Quantity field is empty. Please enter the quantity of handicrafts made.'); } else { $ctypeQuery = mysql_query("SELECT CTYPE_ID FROM CraftType WHERE CTYPE_Type = '".$CType_Type."'"); while($row = mysql_fetch_array($ctypeQuery)) { $CTYPE_ID = $row["CTYPE_ID"]; $sql = ("INSERT INTO Handicraft VALUES (`HANDI_ID`, '".$Quantity."', 'NULL', '".$CTYPE_ID."', '".$ART_ID."', 'NULL', '1')"); if(!mysql_query($sql)) { die('Error inserting Handicraft Type into table: ' . mysql_error()); } else { -----data in this section doesn't affect the rest of the code---- } } }
When I echo out my variable in the php file it works fine but when I put the variable in a table cell it doesn't echo out. Hi, I would like to do the following but not sure how. If the you/user is on index.php of http://www.domain.com/ show one page If not show another How would I do this? Thanks ONE of my SESSION values isn't remaining after login while others do. This works fine on my localhost, it's on the live site that there is a problem and it just started yesterday. Before that it worked great. Out of the four SESSIONs made I can only echo three values on other pages, member id the most important doesn't transfered to other pages Notes: all these files are in the same folder, there is a SESSION started for the member id on the login page, you can see that it is used in the redirect below and the redirect works fine with the redirect going to the correct page " $home/member/index.php?user=$id_mem " Here is the login page // Here's the basic login page info <?php # login.php session_start(); ob_start() ...connect to db & header called... ...Form validation..... if ($e && $p) { // If everything's OK. // Query the database: $q = "SELECT id_mem, display_name, mem_group FROM sn_members WHERE (email='$e' AND password=SHA1('$p')) AND active IS NULL"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); // or die("Error: ".mysqli_error($dbc)); if (@mysqli_num_rows($r) == 1) { // If a match was made. // Register the values & redirect: // Give SELECTED elements a session $_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); $_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']); mysqli_free_result($r); // Update db for last login $id_mem = $_SESSION['id_mem']; // <<< SESSION member id has a value here because it's used in the redirect below $ip = $_SERVER['REMOTE_ADDR']; // Get ip address of person logging in $q = "UPDATE sn_members SET last_login = Now(), ip = '$ip' WHERE id_mem = '$id_mem' LIMIT 1"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); header("Location: $home/member/index.php?user=$id_mem"); exit(); // Quit the script. } ?> Here is the main page that a user would be redirect to above <?php // /member/ all member info is through this folder session_start(); ob_start(); if (isset($_GET['user']) && is_numeric($_GET['user'])) { $user = $_GET['user']; $user = $user; if ($user < 0) { header("Location: $home/index.php"); exit(); } } if ((!isset($_SESSION['id_mem'])) && (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT'])))){ // If not a logged in member redirect header("Location: $home/index.php"); exit(); // Quit the script. } ?> Thanks in advance for the help SJ Hello, I am writing my first php script (of course) and it works except it only shows 4 variables. Example I have it to send me: mail($myemail, $fullname, $email, $message, $phone); But it will only send me the first four no matter what order they are in. It's driving me crazy. I can't think or find any reason why it would do this. If I change it to mail($myemail, $fullname, $email, $phone, $message); It will send me everything but $message if I change it to mail($myemail, $fullname, $message, $email, $phone ); It will send me everything but $phone Does anyone know why or what I need to change? I apologize if this sounds like a dumb question. I am very very new to php. Thank you for any guidance you can give. Here is the code: HTML: <form action="Contact.php" method="post" id="contact" name="contact" style="margin:0px";> <h2>Contact Form:</h2> <p>Fields marked (<span style="color:#F00;">*</span>) are required.</p> <p> <label for="text_fullname">Full Name<span style="color:#F00;">*</span>:</label> <input name="fullname" type="text" class="input" id="fullname" tabindex="1" /> <label for="text_email">Email<span style="color:#F00;">*</span>:</label> <input name="email" type="text" class="input" id="email" tabindex="2" /> <label for="text_phone">Phone:</label> <input name="phone" type="text" class="input" id="phone" tabindex="3" /> <label for="text_comments">Message/Comment:</label> <textarea name="message" cols="23" rows="3" class="input" id="message" tabindex="4"></textarea> <br> <div style="padding-left:200px;"> <button type="submit" id="send" name="send">Send!</button> <button type="reset">Reset</button> </div> </form> --------------------------------------- PHP: <?php /* Set e-mail recipient */ $myemail = "tkowebworks@gmail.com"; $fullname = $_POST['fullname'] ; $email = $_POST['email'] ; $phone = $_POST['phone'] ; $message = $_POST['message'] ; mail($myemail, $fullname, $email, $message, $phone); header( "Location: http://www.ppm-oc.com/thankyou.html" ); ?> ---------------------------------- Thank you Some 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 ? hi im having trouble with my login script i keep getting the errors Deprecated: Function session_register() is deprecated in C:\wamp\www\login.php on line 53 Deprecated: Function session_register() is deprecated in C:\wamp\www\login.php on line 57 Deprecated: Function session_register() is deprecated in C:\wamp\www\login.php on line 61 i just wanted to knw wot they mean the page styll runs ok, is there any way i can make it work Code: [Select] $sql = mysql_query("SELECT * FROM myMembers WHERE email='$email' AND password='$pass' AND email_activated='1'"); $login_check = mysql_num_rows($sql); if($login_check > 0){ while ($row = mysql_fetch_array($sql)){ $id = $row["id"]; session_register('id'); $_SESSION['id'] = $id; $firstname = $row["firstname"]; session_register('firstname'); $_SESSION['firstname'] = $firstname; $email = $row["email"]; session_register('email'); $_SESSION['email'] = $email; mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$id'"); $my_msg="Hello $firstname, you have succesfully logged in"; //print "return_msg=$my_msg&id=$id&firstname=$firstname"; } // close while } else{ $my_msg="Error Your Password Or Email Did Not Match"; // print "return_msg=$my_msg"; exit(); } } also im having trouble with my my_msg variable it does not seem to show up i keep gettin error Please delete. Hi All, I want to be able to show selected pages of my website as PDF using a 'PDF' button much like this site does: http://www.westmeon.org.uk/index.php?option=com_content&task=blogsection&id=8&Itemid=35 I presume that I will need to install some sort of software on my server (which runs the latest PHP, MySQL etc.) but after hours of searching online I cannot find a simple way of doing this. Does anyone have any suggestions or pointers for how I can do this? FYI my website is written in PHP drawing data from a MySQL database. Regards, Neil Hi, This may be something for JavaScript but I would like to know if and how it's possible to show who is currently active/viewing the page. Users are logged into the system with their own account. The purpose of this is for a CRM where more than one person may be editing the same record, so undesired overwrites might occur which is what I'd like to avoid with this "other user editing this record" notification. Hi I want to make something like this - My Sites index.php will be avail avail to user after he has clicked in a link that will come after every 24 Hour in my site. Means when a user first enters the site it will come and clicking in there the site will be avail avail. again after 24 Hour it will come again. But i am not getting how to do it. So need help SaKIB |