PHP - Transferring Additional Data Through $_post And $_get
Hi,
I am a curious fellow just beginning to use PHP. I understand the basics of what the $_GET and $_POST superglobals do, and how we can use them to retrieve data after form submission. I also know that since $_GET and $_POST are just associate arrays, we can create our own values in both $_GET and $_POST by writing statements like $_POST['variable'] = "value". I am wondering if it is at all possible to send data beyond form data by adding new key/value pairs into $_GET and $_POST. So for example, if I had a form that transferred username/password through Post, would it be possible for me to include further data by just saying $_POST['formtype'] = "house_insurance_form"? Basically what I'm getting at is trying to physically add your own data to $_POST or $_GET that you could pull from the next page where the form redirects to. In other words, can I send data beyond form data using these superglobals? I know I can do this with $_SESSION, but could I do it through $_POST or $_GET? I haven't been able to accomplish this, and I was just wondering if someone could give me an in-depth explanation of how this might work or how this is not possible. I would really really really appreciate it. Best Regards, -Sky Similar TutorialsI recently had a customer say that one of my forms isn't working. For some reason the ID number is getting lost when she submits the form. The form code looks like: ... print "<form method='post' name='form' action='update.php'>"; ... print "<input type='hidden' name='id' value=\"$id\" />"; print "<input type='submit' name='submit' value=\"Save Session\" />"; print "</form>"; ... And the PHP code that gets executed looks like: ... //GET SESSION ID if(isset($_GET['id'])) { //ID from HTML link, before updates have been made $id = $_GET['id']; } elseif(isset($_POST['id'])) { //ID from form, after updates have been made $id = $_POST['id']; } else { $id = ''; } //IF SESSION ID IS VALID if(preg_match("/^\d+$/", $id)) { ... //ELSE, INVALID ID } else { $msg = "<span class='errorText'>Session ID not found or invalid.</span>"; } ... For some reason she usually gets the "Session ID not found..." error when submitting the form. Do you see any problems with the above code? Note that she has been able to sucessfully use the form before (in the same day); we have nearly 1,800 records submitted using these forms; and I am unable to duplicate the issue. So I'm at a loss on what to do next. Also, she talked with her IT person about the form. The IT person was able to submit data on his computer. So he reset her Internet options which seemed to fix the problem on her end temporarily. Note that she is using IE 7. She also said that she doesn't have access to any other browsers. I'm tempted to chalk this up as a personal computer issue, but wanted to get your input first. Well, i have got this code: Code: [Select] <?php header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); ?> <form action="signature.php?user=" .$user. "&img=". $img" method="post"> <input name="user" type="text" /> <select name="img"> <option value="blue">Blue</option> <option value="red">Red</option> <option value="purple">Purple</option> <option value="pink">Pink</option> </select> <?php $user = $_POST['user']; $img = $_POST['img']; ?> <input type="submit" value="Submit" /> <?php //Skill Grabs $order = array("Overall", "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction", "Summoning", "Dungeoneering"); $user = $_GET['user']; //Change this to the variable (Or a string literal) that contains the username $get = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=$user"); $get = explode("\n", $get); $i = 0; foreach ($order as $key => $value) { $value = strtolower($value); $temp = explode(",", $get[$i]); $temp = array("rank" => $temp[0], "level" => $temp[1], "exp" => $temp[2]); $stats[$value] = $temp; $eval = "\$$value = array(\$temp[\"rank\"], \$temp[\"level\"], \$temp[\"exp\"]);"; eval($eval); $i++; } //End Skill Grabs // specify the file name - you can use a full path, or "../../" type stuff here // if the image is not in the same directory as this code file $image = imagecreatefrompng("http://slay2day.x10.mx/highscores/signatures/".$_GET['img'].".png"); // specify the font size // in this case, the color is white, but you can replace the numbers with the RGB values // of any color you want $color = imagecolorallocate($image, 255,255,255); // and now we do the overlay - the layers of text start top to bottom, so // the drop shadow comes first // $image - the base image file we specified above // $font_size - Well duh. Its the size of the font // 0 - the angle of the text - we don't want an angle, so we leave it at 0 // 55 - pixels to the right from the leftmost part of the image // 35 - pixels down from the top of the image // $black - the color we defined above // "../fonts/ARIALBD.TTF" - the location on the server that the font can be found // "Test Text" - the text we're overlaying - you can also use a variable here ImageTTFText ($image, "7", 0, 280, 10, $color, "arial.ttf","Slay2day"); ImageTTFText ($image, "12", 0, 240, 55, $color, "biblio.ttf",$user); if($overall[0]==-1){ImageTTFText($image, "11", 0, 230, 105, $color, "biblio.ttf","NOT RANKED");}else{ImageTTFText($image, "11", 0, 240, 105, $color, "biblio.ttf",$overall[0]);} ImageTTFText ($image, "10", 0, 27, 20, $color, "arial.ttf",$attack[1]); ImageTTFText ($image, "10", 0, 27, 42, $color, "arial.ttf",$strength[1]); ImageTTFText ($image, "10", 0, 27, 64, $color, "arial.ttf",$defence[1]); ImageTTFText ($image, "10", 0, 27, 88, $color, "arial.ttf",$hitpoints[1]); ImageTTFText ($image, "10", 0, 27, 114, $color, "arial.ttf",$ranged[1]); ImageTTFText ($image, "10", 0, 70, 20, $color, "arial.ttf",$prayer[1]); ImageTTFText ($image, "10", 0, 70, 42, $color, "arial.ttf",$magic[1]); ImageTTFText ($image, "10", 0, 70, 64, $color, "arial.ttf",$cooking[1]); ImageTTFText ($image, "10", 0, 70, 88, $color, "arial.ttf",$woodcutting[1]); ImageTTFText ($image, "10", 0, 70, 114, $color, "arial.ttf",$fletching[1]); ImageTTFText ($image, "10", 0, 117, 20, $color, "arial.ttf",$fishing[1]); ImageTTFText ($image, "10", 0, 117, 42, $color, "arial.ttf",$firemaking[1]); ImageTTFText ($image, "10", 0, 117, 64, $color, "arial.ttf",$crafting[1]); ImageTTFText ($image, "10", 0, 117, 88, $color, "arial.ttf",$smithing[1]); ImageTTFText ($image, "10", 0, 117, 114, $color, "arial.ttf",$mining[1]); ImageTTFText ($image, "10", 0, 162, 20, $color, "arial.ttf",$herblore[1]); ImageTTFText ($image, "10", 0, 162, 42, $color, "arial.ttf",$agility[1]); ImageTTFText ($image, "10", 0, 162, 64, $color, "arial.ttf",$thieving[1]); ImageTTFText ($image, "10", 0, 162, 88, $color, "arial.ttf",$slayer[1]); ImageTTFText ($image, "10", 0, 162, 114, $color, "arial.ttf",$farming[1]); ImageTTFText ($image, "10", 0, 212, 20, $color, "arial.ttf",$runecraft[1]); ImageTTFText ($image, "10", 0, 212, 42, $color, "arial.ttf",$construction[1]); ImageTTFText ($image, "10", 0, 212, 64, $color, "arial.ttf",$hunter[1]); ImageTTFText ($image, "10", 0, 212, 88, $color, "arial.ttf",$summoning[1]); ImageTTFText ($image, "10", 0, 212, 114, $color, "arial.ttf",$dungeoneering[1]); // Now add the actual white text "on top" header("Content-type: image/png"); imagepng($image); imagedestroy($image); ?> It generates a image and gets data from the name thats in the url. I am wanting to make a form where they fill out their name and what color they use. What is wrong? Hello guys. I'm trying to improve my control panel system. I have this page where you input a player's name and when you hit "Search" it will display that user's information. Ok. This is the code: Code: [Select] <form action="ShowStats.php" method="post"> <li><font color="#FF9933"><b>User's Name:</b></font> <input type="text" name="User" /></li> <p> </p> <p> </p> <input type="submit" value="Search" /></form>That's when you input the player's name and the Search button. Once you hit that button, I want the Address bar to display something like this: "www.test.com/ShowStats.php?User=SEARCHED_USER" Here's the $_POST ( and "fetch" user's info ) function inside "ShowStats.php" include("database.php"); if(!$con) { die('Could not connect: ' . mysql_error()); } $user = $_POST["User"]; $escuser = mysql_real_escape_string($user); $result = mysql_query("SELECT * FROM playerinfo WHERE user = '$escuser'"); $username_exist = mysql_num_rows($result); if($username_exist == 0) { echo('<b><font color="#C41F1F">That username does not exist</b></font>'); echo('<p><center><font face="Arial" color="#000080" size="2"><b><a href="http://yu-ki-ko.com/fsns/Stats.php">Go back</a></b></center></font></p>'); die; } $row = mysql_fetch_row($result); All I want is that when a user searches for the player, the address bar will be displayed like: "www.test.com/ShowStats.php?User=SEARCHED_USER" Thanks! If any more info is needed, let me know. Hi guys i am a PHP newbie trying to learn from the beginning. I am reading a php book and i can't get past a particular example because $_GET and $_POST just won't work. Below is the code i am working with: HTML File <form action="welcome1.php" method="get"> <div> <label for="firstname">First name: <input type="text" name"firstname" id="firstname"/></label> </div> <div> <label for="lastname"> Last name: <input type="text" name="lastname" id="lastname"/> </label> </div> <div> <input type="submit" value="GO" /> </div> PHP file <?php $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; print 'Welcome to our website, ' . htmlspecialchars($firstname, ENT_QUOTES, 'UTF-8') . ' ' . htmlspecialchars($lastname, ENT_QUOTES, 'UTF-8') . '!'; ?> I am working on a windows pc with Vista home edition installed. I run a localhost server installed via XAMMP. Please this has been a recurring problem for me. Each time i get to this stage in the past i always get stuck. $_GET and $_POST just does not work for me. Please heeeelp! Hi, I do not have a problem with specific code but rather code design/technique. I am not able to articulate the problem very well but here goes. I am building a [mostly] object oriented PHP store as a personal project to improve my PHP skills. However I'm running into some problems concerning my sorting, pagination and filtering facilities. I've tried to use $_GET to store the following: Page being viewed by the user Category (e.g. fruit or vegetables) Sort method (e.g price ascending, descending etc.) When the user clicks on a link to another page for example, I must append the page number to the URL, something like "index.php?page=2" but the other $_GET parameters are lost unless I do something like: Code: [Select] <a href=\"index.php?cat=".$_GET['cat']."&sort=".$_GET['sort']."&page=".($this->pageNum+1)."\">Next-> </a> This means whenever there is a link or form submission I must find a way to carry over all those parameters to ensure the page and category are remembered, otherwise the user is returned to page 1 and the main category. It's a mess and has become too confusing with the introduction of other pages. Clearly, I'm doing it all wrong. $_GET parameters alone are not a good solution here, at least how I'm using them. So I ask of you, what's the correct way to store information such as page number, sorting method and category? Must I use $_SESSIONS and if so how? Thanks. My form values are not posting on my thankyou.php page. I'm sure it's a simple fix. Here's some code from reservation.php . form action="CGI/gdform.php" method="post" enctype="application/x-www-form-urlencoded" name="formres" id="formres"> <input type="hidden" name=" redirect" value="ThankYou.php"> <label><span class="style12">Your Name: <input type="text" name="txtName" id="Name" /> </span></label> ... <p class="style12"><span id="sprytextfield10"> <label>Date of Special Event: <input type="text" name="DateReq" id="DateReq" /> </label> <?php $txtName = $_GET[txtName]; ... $DateReq = $_GET[DateReq]; ?> </form> On my thankyou.php: <body> <?php $txtName = $_POST[txtName]; ... $DateReq = $_POST[DateReq]; ?> and a little lower down... <?php echo $txtName ?> ... <?php echo $DateReq ?> Any reason why the thank you page isn't calling the values? I exhaustively checked it against a working form I have on another site, and the code seems to be, well, identical. Not getting an error, just get empty space where the values should be.
So maybe this is normal, or maybe there is a "better way." The only simple solution appears to be to always save $_POST data to $_SESSION["post"] on the off-chance some visitor some day ever decides to do a $_GET request from a referral link.
3 weeks of my life has been lost to correcting the neverending 'illegal string offset' and 'undefined index' errors etc. by making sure every last variable is declared... Anyway, blah blah blah, that's my rant. Is there a better way? Or is this "how everybody does it?" It seems stupid to have to do all of this.
hey guys basically i have a form which searches my news <form action="" method="GET"> <label for="search">Search: </label><input name="search" id="search" type="text" /> <input value="Search" type="submit" /> </form> and im not sure the best way around this or if im going around this the right way but when i access http://localhost/news/seach (search form) and press submit after entering a query i want the action to be http://localhost/news/seach/search query value here i hope ive explained well enough and someone could help me with this...thank you I have a php search page that takes form data to create its queries, then reload the original search page. The form is long, so there are numerous $_POST's to convert to variables for use in the query. I've looked at "extract" and a few other code snippets. But it's a form and I don't want any security issues. I'm hoping there's a "foreach" solution, but I'm a beginner. What's a proper way to to simplify this: $s1 = $_POST["s1"]; $s2 = $_POST["s2"]; $s3 = $_POST["s3"]; $s4 = $_POST["s4"]; $s5 = $_POST["s5"]; $s6 = $_POST["s6"]; $s7 = $_POST["s7"]; $s8 = $_POST["s8"]; $s9 = $_POST["s9"]; $s10 = $_POST["s10"]; $s11 = $_POST["s11"]; $s12 = $_POST["s12"]; Is this an effective way of accessing the $_GET and $_POST properties? I can see that the native $_GET function has been looped through so that $varName would be for example "username" and $value would be "Jeremy". Then they are both stored into an array called $getVars? Is this the best way of doing it, if not then why? foreach($_GET as $varName=>$value) $getVars[$varName]=trim(clean($value, 100)); foreach($_POST as $varName=>$value) $postVars[$varName]=trim(clean($value, 100));[/php] Kind regards, laanes hi, I have a webpage that is driven by a database mostly. it has a catalog of dog treats and most will transfer to the checkout page but 2 two won't. I have checked the database and everything looks fine if it would help, here 's the webpage. http://auntievics.com/treats.php. it's the Cara The Flirt's K9 Canoli Stuffed and the Cara The Flirt's K9 Canoli Unstuffed that won't transfer. Any help would be appreciated. User clicks on a url, ie: example.com/AEQ438J When I perform this in the code below: Code: [Select] $referrer = $_GET['_url']; // echo $referrer displays the referrer ID contents correctly as "AEQ438J" if ( ! empty($referrer)) { $mysqli->query("UPDATE coming_soon_emails SET clicks = clicks + 1 WHERE code='" . $referrer ."'"); } // this also updates the database correctly as it should if (!empty($_POST['email'])){ // echo $referrer displays the referrer ID contents as BLANK. It should display "AEQ438J"! ..... $referrer displays correctly BEFORE if($_POST['form']), however during the if($_POST['form']) $referrer is empty. How can I fix my code so that $referrer is not empty during the time the user posts their email address in the form? Thank you! Complete PHP and HTML Code: [Select] <?php require "includes/connect.php"; //var_dump($_GET);die; function gen_code($codeLen = 7) { $code = ''; for ($i=0; $i<$codeLen; $i++) { $d=rand(1,30)%2; $code .= $d ? chr(rand(65,90)) : chr(rand(48,57)); } return $code; } function add_code($email_id) { global $mysqli; $code = gen_code(7); $mysqli->query("UPDATE coming_soon_emails SET code='" . $code ."' WHERE email_id='" . $email_id . "'"); if($mysqli->affected_rows != 1) { add_code($email_id); } else return $code; } $msg = ''; $referrer = $_GET['_url']; // echo $referrer displays the referrer ID contents correctly if ( ! empty($referrer)) { $mysqli->query("UPDATE coming_soon_emails SET clicks = clicks + 1 WHERE code='" . $referrer ."'"); } if (!empty($_POST['email'])){ // echo $referrer displays the referrer ID contents as BLANK // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $mysqli->query("INSERT INTO coming_soon_emails SET email='".$mysqli->real_escape_string($_POST['email'])."'"); if($mysqli->affected_rows != 1){ throw new Exception('This email already exists in the database.'); } else { $email_code = add_code($mysqli->insert_id); } $msg = "http://www.example.com/" . $email_code; //the following doesn't work as referrer is now empty :( if ( ! empty($referrer)) { $mysqli->query("UPDATE coming_soon_emails SET signup = signup + 1 WHERE code='" . $referrer ."'"); } if($ajax){ die(json_encode(array('msg' => $msg))); } } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="css/styles.css" /> </head> <body> <div id="launch"> <form id="form" method="post" action=""> <input type="text" id="email" name="email" value="<?php echo $msg;?>" /> <input type="submit" value="Submit" id="submitButton" /> </form> <div id="invite"> <p style="margin-top:20px;">The ID of who referred you: <?php echo $referrer; //this displays correctly?>)</p> <p style="margin-top:20px;"><span id="code" style="font-weight:bold;"> </span></p> </div> </div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script src="js/script.js"></script> </body> </html> script.js Code: [Select] $(document).ready(function(){ // Binding event listeners for the form on document ready $('#email').defaultText('Your Email Address'); // 'working' prevents multiple submissions var working = false; $('#form').submit(function(){ if(working){ return false; } working = true; $.post("./index.php",{email:$('#email').val()},function(r){ if(r.error){ $('#email').val(r.error); } else { $('#email').val(r.msg); // not needed but gets hidden anyways... $('#launch form').hide(); $("#code").html(r.msg); $("#invite").fadeIn('slow'); } working = false; },'json'); return false; }); }); // A custom jQuery method for placeholder text: $.fn.defaultText = function(value){ var element = this.eq(0); element.data('defaultText',value); element.focus(function(){ if(element.val() == value){ element.val('').removeClass('defaultText'); } }).blur(function(){ if(element.val() == '' || element.val() == value){ element.addClass('defaultText').val(value); } }); return element.blur(); } htaccess Code: [Select] RewriteEngine on RewriteCond %{HTTP_HOST} ^my-url.com RewriteRule (.*) http://www.my-url.com/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z0-9]+)$ /index.php?_url=$1 [NC,L,QSA] table.sql Code: [Select] CREATE TABLE IF NOT EXISTS `coming_soon_emails` ( `email_id` int(11) NOT NULL auto_increment, `email` varchar(64) collate utf8_unicode_ci NOT NULL, `code` char(7) collate utf8_unicode_ci DEFAULT NULL, `clicks` int(64) collate utf8_unicode_ci DEFAULT 0, `signup` int(64) collate utf8_unicode_ci DEFAULT 0, `ts` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`email_id`), UNIQUE KEY `email` (`email`), UNIQUE KEY `code` (`code`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; Sorry, I initially posted this in the Ajax Help Thread, but thinking about it, I suspect this is a php query.
I am trying to write a basic Private Messaging script.
I have my main page which lists all messages that have been received. I then want to click on an href link to run an ajax query to bring information in from another .php file which shows the content of the selected message.
But I can't fathom out how to do this with an href. First off, is it possible? If so, can anyone tell me what I am doing wrong?
The relevant script is:
privatemessage.php:
<?php $query2 = DB::getInstance()->query("SELECT c.id as cid, c.title, c.time, m.id as membersid, m.username, m.member_first_name, m.member_last_name FROM conversation as c, members as m WHERE ((c.member1='{$memberid}' and c.read1='Yes' and c.removed1='No' and m.id=c.member2) OR (c.member2='{$memberid}' and c.read2='Yes' and c.removed2='No' and m.id=c.member1)) GROUP BY m.id ORDER BY m.id DESC"); ?> <table> <tr> <td align="left"> <?php echo htmlentities($result2->member_first_name); ?> <?php echo htmlentities($result2->member_last_name); ?> <?php echo "("; echo htmlentities($result2->username); echo ")"; ?> </td> <td align="right"> <?php echo timeAgo(strtotime($result2->time)); ?> </td> </tr> <tr> <td colspan="2" align="left"> <form action="" method="post"> <?php echo "Subject: "; ?> <?php echo "<input type='hidden' name='id' id='id' value='{$result2->cid}'>"; ?> <a href="#$result2->cid" onClick="showMessages(this.value)"><?php echo htmlentities($result2->title); ?> </form> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="js/readmessage.js"></script> </td> </tr> </table> <div id="txtMessage"></div>My readmessage.js code is: function showMessages(str) { if (str=="") { document.getElementById("txtMessage").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtMessage").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","readmessage.php?q="+str,true); xmlhttp.send(); }And my readmessage.php code is: ?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); $req1 = DB::getInstance()->query("SELECT title, member1, member2 FROM conversation WHERE id='{$q}' AND id2='1'"); foreach ($req1->results() as $dn1) if($req1->count()==1) { if(($dn1->member1=='{$memberid}') or ($dn->member2=='{$memberid}')) { if($dn1->member1=='{$memberid}') { DB::getInstance()->query("UPDATE conversation SET read1='Yes' where id='{$q}' and id2='1'"); $user_partic = 2; } else { DB::getInstance()->query("UPDATE conversation SET read2='Yes' where id='{$q}' and id2='1'"); $user_partic = "1"; } $req2 = DB::getInstance()->query("SELECT conversation.time, conversation.message, members.id as userid, members.username, members.member_first_name, members.member_last_name FROM conversation, members WHERE conversation.id='{$id}' AND members.id=conversation.member1 ORDER BY conversation.id2"); if(isset($_POST['message']) and $_POST['message']!='') { $message = $_POST['message']; if(get_magic_quotes_gpc()) { $message = stripslashes($message); } $message = $string(nl2br(htmlentities($message, ENT_QUOTES, 'UTF-8'))); if( DB::getInstance()->query("INSERT into conversation (id, id2, title, member1, member2, message, time, read1, read2) VALUES('{$q}', '{(intval($req2->id2)+1)}', '', '{$memberid}', '', '{$message}', '.time().', '', '')") and DB::getInstance()->query("UPDATE conversation SET read'{$user_partic}'='Yes' WHERE id='{$q}' AND id2='1'")); } echo "<h4>"; echo $dn1->title; echo "</h4><br><br>"; echo "<table><col width='150px'><col width='50px'><col width='150px'>"; echo "<tr><th>Member</th><th> </th><th>Message</th></tr>"; foreach ($req2->results() as $dn2) { echo "<tr><td>"; echo $dn2->members.member_first_name; echo $dn2->members.member_last_name; echo " ("; echo $dn2->members.username; echo ") </td><td></td><td>"; echo timeAgo(strtotime($dn2->time)); echo "<br>"; echo $dn2->message; echo "</td></tr>"; } echo "</table>"; } } } ?>However, just to try and find where the error lies, I have tried the following code for my readmessage.php file: <?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = intval($_GET['q']); echo $q; } ?>Which always returns a "0" reply - which says to me that my files are talking, but that the id isn't being carried across. Anybody got any suggestions? Many thanks for any help offered. I have the following code Code: [Select] while($player = mysql_fetch_array($players)) { #Lets loop through all the players echo "<BR><input type=submit onclick=this.form.action='points.php?points=".$_GET['points']."&player=".$player['playerID']."&playerName=".$player['name']."' value='".$player['name']."'>"; }but the problem is that $player['name'] is always two words and it doesn't work. So I have removed '&playerName=".$player['name']."' but now don't know how to transfer that info. Is there a way of having the player name in the header or another way of sending this data to the next page? Another way of doing it is to check for the players name via there playerID number but this involves another call to the database which I am trying to avoid. Hey there, I was wondering if this is possible with mysql, my goal is to transfer the users id from the users table to the id field in my status table, thanks in advance. NOTE: Not manually, through a script. I have a page that reads from a database to list employees from different states. Under each name is a link that pulls up a new window with a contact form. My goal is to get the name from that link to appear on that new window. (Which I will then use to ultimately add the name into the email that was generated so the recipient can know who the email was intended for.) I've tried using the GET and POST methods but nothing seems to work. Any help would be appreciated greatly. I will name my firstborn after anything you desire. I've included my code below. (The last line is what I've been primarily working with) Code: [Select] //Open Database Connection $db = open_db_connection(); $sql = "SELECT DISTINCT 1 from users where active = 'Y' and show_on_contactus = 'Y'"; $results = mysql_query($sql, $db); $emaillink = "<a target='main' onclick=window.open('contactform/contactCentral.php?name=$state_row[state]','popup','width=380,height=400,scrollbars=no,resizable=no,toolbar=yes,directories=no,location=no,menubar=yes,status=no,left=0,top=0'); return false>"; if(!mysql_num_rows($results) == FALSE) while($row = mysql_fetch_array($results, MYSQL_BOTH)) { echo "<ul id=\"directors\">\n"; $state_sql = "SELECT * from users where active = 'Y' and show_on_contactus = 'Y' and state_full = 'indiana' order by last_name"; $state_results = mysql_query($state_sql, $db); if(!mysql_num_rows($results) == FALSE) { while($state_row = mysql_fetch_array($state_results, MYSQL_BOTH)) { echo "<li>\n"; echo " <div class=\"fl dirimg\">\n"; if($state_row[photo] == "") { echo "<img border=\"0\" width=\"61\" height=\"85\" src=\"images/exe_placeholder.jpg\" alt=\"$state_row[first_name] $state_row[last_name]\" />\n"; } else { echo "<img border=\"0\" width=\"61\" height=\"85\" src=\"n2team/pictures/$state_row[photo]\" alt=\"$state_row[firstname] $state_row[last_name]\" />\n"; } echo " </div>\n"; echo " <span class=\"fr\">$state_row[first_name] $state_row[last_name]<br />\n"; echo " $state_row[title]<br />\n"; echo " $state_row[city], $state_row[state]<br />\n"; echo " $emaillink Contact $state_row[first_name] </a></span></li>\n"; } Hi guys,
I am having a problem transferring data between pages, using PHP sessions. I have a HTML SELECT drop-down to let user set the number of posts per page to display. <form method="POST" style="margin:auto;position:relative;width:35%;padding:17px;top:47px;"> <span>select posts-per-page:</span> <select name="ppp"> <option selected disabled>--select ppp--</option> <option value=10>10</option> <option value=15>15</option> <option value=20>20</option> <option value=50>50</option> <option value=100>100</option> </select> <input type="submit" name="submit" value="OK"/> </form> I want to transfer the value selected by user to a session so that I can load the value in other pages. The value of posts per page is carried by variable $ppp; so, file1 contains the code $_SESSION['ppp'] = $ppp; That seems to work great; the system updates correctly the session's value as user submits different numbers of posts-per-page.
The problem is in page2.php: it doesn't update to the new user's selection; I already have a session active in that page so I don't need session_start(). To call the session, I use the line $ppp=$_SESSION['ppp']; When user changes the selection from 50 to 100 posts per age, for example, the value of page1.php changes as expected, but the value transferred to page2.php doesn't change, appears to remain with the default value the page loads with. I don't know if the problem is that I already have a session going. Can you have more than one session running simultaneously in a page? Can anybody help? Thanks in advance!
Sept Transferring data from sub-domain.site.com Reading sub-domain.site.com What is this all about? I'm going to put all .. images into a separate sub-domain eg: images.site.com. This would create a folder inside my public_HTML called "images" Now when sites have that Transferring data, and Reading... is this .. something relating to what I want. Facebook also does it, and they get their images for the site from a sub domain, how is it all done? I'm not sure if its entirely PHP, but I hope someone can help. Thanks I'm trying to add voucher codes to my shopping basket. When someone submits a voucher code it adds ?vouchercode=WHATEVERTHECODE to the URL. I then $_GET this data and store is as $_SESSION['vouchercode']. The problem is, on the next page it $_GET's the ?vouchercode again, which is this time blank, and sets the session to blank as well. Any help? Here's my code: Code: [Select] $vouchercode = $_GET['vouchercode']; $_SESSION['vouchercode'] = $vouchercode; if ($rows['brand'] == 'Dank' AND $_SESSION['vouchercode'] == 'DANKINT') { echo 'Voucher Code DANKINT Used'; } After several attempts, I now have data displayed on my index.php page, but the data is from all rows. Luckily I have two rows. The page also has a menu - with two links. What I would like help with is: How to display index.php with just the data for it - i.e. home page data. How to display data if either the ‘home’ or ‘copyright’ links are clicked. I understand you can use $_GET[‘id’], and isset(), but I don’t know how to do that. I include the full html page code: <?php // database connection require_once('admin/databasecon.php'); ?> <!DOCTYPE html> <html> <?php include 'includes/headsection.php'; ?> <body> <?php // displaying data $table = "pages"; // table $sqli = "SELECT * FROM $table ORDER BY id ASC"; $result = $conn->query($sqli); ?> <!-- topMenu --> <table id="topMenu"> <tr> <td><h1 class="siteName">Scarab Beetle</h1></td> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo "<td class='navItem'>" . "<a href=index.php>" . $row["menuheader"] . "</a>" . "</td>"; } } ?> </tr> </table> <!-- topMenu end --> <!-- timeline menu --> Menu goes here <!-- timeline menu end --> <!-- page title --> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo "<h1 class='centered'>" . $row["pageheader"] . "</h1>"; } } ?> <hr> <!-- page content --> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo $row["pagetext"]; } } ?> <hr> <div class="clear"></div> <!-- footer content --> <?php include 'includes/footersection.php'; ?> <!-- footer content end --> </body> </html> Any help to achieve what I want will be appreciated. Thank you. |