PHP - Simple Syntaxing Issue With $_get[variable]
The code below works
echo '<script language="javascript">'; echo 'top.location.href = "/breaking-news/bsnewsstorygoeshere/";'; echo '</script>'; this also works echo '<script language="javascript">'; echo 'top.location.href = "http://anywebsite.com";'; echo '</script>'; the problem, is I have a URL listed in a url variable that can be retreived via $_GET['url'] my question is how to get that variable into the above code? I've tried echo '<script language="javascript">'; echo "top.location.href = \"$_GET['url']\";"; echo '</script>'; but that doesnt seem to work, can anyone advise? Similar TutorialsHey all, I'm working on a Market script for my game site but I've came across an Error.. Market.php: <?php session_start(); include ("includes/config.php"); include ("includes/functions.php"); logincheck(); // Grab the Users information. $userinfo = "SELECT * FROM users WHERE username = '$username' LIMIT 1"; $userinfos = mysql_query($userinfo) or die ("Error in Query: Line 11" . mysql_error()); $fetchuser = mysql_fetch_object($userinfos); // Grab the users Garage so they can add Cars onto the Market.. $usergarage = "SELECT * FROM garage WHERE owner = '$username' LIMIT 1"; $usergarages = mysql_query($usergarage) or die ("Error in Query: Line 17" . mysql_error()); $garageuser = mysql_fetch_object($usergarages); // If they want to view the Cars stats: if (strip_tags($_GET['vcstats'])){ $vcstats = strip_tags($_GET['vcstats']); $marketqu = "SELECT * FROM market WHERE type = 'car'"; $doqut = mysql_query($marketqu) or die ("Error in Query: Line 186: " . mysql_error()); $objmarket = mysql_fetch_object($doqut); $caridfrommarket = $objmarket->carid; $getthecar = "SELECT * FROM garage WHERE id='$caridfrommarket' LIMIT 1"; $carinfo = mysql_query($getthecar) or die ("Error in Query: Line 192 " . mysql_error()); $carstats = mysql_fetch_object($carinfo); $cid = $carstats->id; $mph = $carstats->mph; $fuel = $carstats->fuel; $value = $carstats->value; $currentowner = $carstats->owner; $nameofcar = $carstats->car; $miles = $carstats->miles; $pic = $carstats->pic; // Lets show the Stats $nos = $carstats->nos; $engine = $carstats->engine; $transmission = $carstats->transmission; $exhaust = $carstats->exhaust; $breaks = $carstats->brakes; $suspension = $carstats->suspension; // Accessiours side $body = $carstats->body; $interior = $carstats->interior; $amp = $carstats->amp; $alloys = $carstats->alloys; $neons = $carstats->neons; $taillights = $carstats->taillights; // Showing the Table in which it will display the Car Information on. echo ("<table width='50%' cellpadding='0' cellspacing='0' border='1' align='center' class='table'> <tr> <td class='header' align='center' colspan='4'>".$nameofcar." (".$cid.")</td> </tr> <tr> <td colspan='4' align='center'><img src='".$pic."'></img> </td> </tr> <tr> <td class='omg' colspan='4'>Performance</td> </tr> <tr> <td>Nos:</td><td>".$nos."</td><td>Engine:</td><td>".$engine."</td> </tr> <tr> <td>Transmission:</td><td>".$transmission."</td><td>Exhaust:</td><td>".$exhaust."</td> </tr> <td>Breaks:</td><td>".$breaks."</td><td>Suspension:</td><td>".$suspension."</td> </tr> <tr> <td colspan='4' class='omg'>Accessorys:</td> </tr> <tr> <td>Body:</td><td>".$body."</td><td>Interior:</td><td>".$interior."</td> </tr> <tr> <td>Amp:</td><td>".$amp."</td><td>Alloys:</td><td>".$alloys."</td> </tr> <tr> <td>Neons:</td><td>".$neons."</td><td>Taillights:</td><td>".$taillights."</td> </tr> <tr> <td>Miles:</td><td>".number_format($miles)."</td><td>Value:</td><td>".$value."</td> </tr> <tr> <td>Fuel:</td><td>".$fuel."</td><td>MPH:</td><td>".$mph."</td> </tr> <tr> <td class='omg'>Owner:</td><td class='omg'><a href='profile.php?viewuser=".$currentowner."'>".$currentowner."</a></td><td class='omg'>Worth:</td><td class='omg'>£".number_format($value)."</td> </tr> </table> <br />"); // Continue soon, lets get the things showing like the Table first! } ?> <form action="" method="GET" name="TheForm"> <table width="50%" cellpadding="0" cellspacing="0" border="1" align="center" class="table"> <tr> <td class="header" align="center" colspan="5">Cars For Sale</td> </tr> <tr> <td>Car Name:</td><td>View Stats:</td><td>Price:</td><td>Buy It Now:</td><td>Cancle</td> <tr> <?php $carsforsale = mysql_query ("SELECT * FROM market WHERE type = 'car'") or trigger_error ("Error in Query: 329 Line " . mysql_error()); while ($cfs = mysql_fetch_object($carsforsale)){ $number = mysql_num_rows($carsforsale); $priceofauc = $cfs->startingprice; // An seller of the car: if ($username == $cfs->owner){ $calowner = "<a href='?cauction=$cfs->id'>Cancle Auction</a>"; } $newid = $cfs->carid; // Lets attempt to get the Cars name rather than the ID. $carnameis = "SELECT * FROM garage WHERE id = '$newid'"; $namecar = mysql_query($carnameis) or die ("Error in Query: Line 255 " . mysql_error()); $aye = mysql_fetch_object($namecar); $Testingthis = $cfs->carid; echo ('<td>'.$aye->car.'</td><td><a href="?vcstats='.$aye->id.'">View Stats</a></td><td>£'.number_format($priceofauc).'</td><td><a href="?buyitnow='.$cfs->id.'">Buy It Now</a></td><td>'.$calowner.'</td></tr><tr>'); } ?> </td> </tr> </table> </form> <br /> In that part of the code, I've tried coding it so when the click the link displaying the Car for sale it will show them the car stats , although... When they do click on the "View Stats" link it only displays the car stats which is on top of the list. For Example: Car Name: || View Stats: || Buy it now: || ID: || Cancle ---------------------------------------------------------------- Evo : || ViewStats || Buy it now || 1 || Cancle Mini : || ViewStats || Buy it now || 2 || Cancle So on that example with my code working how it is now it would only show the Stats for the Evo which has the ID of 1 even if the Mini (ID 2) is clicked. Is there something I've done wrong in my code which is making it only show the top cars stats? Thanks for any help given Hello all, I am terribly confused about the following code, for some reason $tourn keeps going back to 0 for no reason! This code: <?php include 'header.php'; $tourn = $_GET['extourn']; echo "first ".$tourn."<br />"; if($tourn=0){ echo "tourn1 is ".$tourn."<br />"; } else{ echo "tourn2 is ".$tourn."<br />"; } ?> returns this: Quote first 4 tourn2 is 0 While tourn2 should return 4 as well. I have tried a million different versions, including switches and everything and just can't understand it. Please help! Hi I have written a simple bit of code, i used to code php a little and have just decided to start coding php again but for the life of me can't work out why this isn't working, so if someone could help this would be great. address www.mysite.co.uk/index.php?vid=video2 <php if (isset($_GET['vid'])){ $video=$_GET['vid']; }else{ $video="video1"; } when i echo $video i only get video=1 having a problem using get variables to include certain pages. I have a management script for a news feed that uses get variables to display certain parts of the script. here is the template/ main part of the script <?php session_start(); require_once("vars.php"); $username = $_SESSION['username']; $is_admin = $_SESSION['is_admin']; $referer = $_SERVER['HTTP_REFERER']; //check to see if user is logged in and is an administrator if((isset($_SESSION['username'])) && ($_SESSION['is_admin'] == 1)){ //if all session variables are set, display admin panel ?> <html> <head> <title>Administration</title> <link rel="stylesheet" type="text/css" href="/cameo/css/admin.css" media="screen" /> </head> <body> <table cellspacing="0" cellpadding="3" class="layout"> <tr> <td colspan="2"><h3>Administration</h3></td> </tr> <tr> <td valign="top"> <a href="index.php?pg=news">Manage News Feed</a> </td> <td> <?php $id = $_GET['pg']; switch($id){ case news: include("manage_news.php"); case editpost: include('edit_post.php'); break; } ?> </td> </tr> </table> </body> </html> <?php } else { echo("You do not have permission to view this page. <br />"); echo("<a href=\"".$referer."\">Go Back</a>"); } ?> and heres the edit post page that the script refers to <?php require_once("vars.php"); $id = $_GET['id']; $query = "SELECT * FROM news_feed WHERE id=".$id; $result = mysqli_query($dbc,$query); $row = mysqli_fetch_array($result); ?> <form method="post" action="update.php"> <textarea><?php echo $row['post_body']; ?></textarea> </form> now, for some reason, the edit post form is showing up under the main news feed listing, even though the get id does not match the one in the switch statement. thanks in advance for any help Hello! I was wondering if this could be done... I want to take a variable, and insert it into a URL for a $_GET on a different page? Basically Its a member website, and I want the admin to be able to "accept" or "deny" the application... So i have a page that displays all the applications, and I want it to take him to a different page with all the user's information in detail. Right now it only displays their name, but when the admin presses the link, it takes them to a more detailed page about the applicant, where they can then "accept" or "deny" the application.... Here is what i got so far... Code: [Select] $character_name = "Nightmareinhell"; <a href="admin_evaluate.php?name=$character_name">$character_name</a> Here is the error I get from the code above Quote Parse error: syntax error, unexpected T_STRING in C:\wamp\www\admin_acceptapply.php Thanks to any help!!!! Hi, I'm using $_GET to pass form data to a URL - http://localhost/projects/phpget/test.php?Q7=Dave&Q8=Smith&Q9=123+Road&Q10=ls11sl&Q2=dave%40hotmail.com&Q4=71&day=19&month=01&year=1995&Q263=3127&Q262=3126&x=99&y=24 All the form fields are named Qx and all are ok apart from dob. I've been trying to get the dob to be passed as dd-mm-yyyy with name of Q5, so in above example would be: http://localhost/projects/phpget/test.php?Q7=Dave&Q8=Smith&Q9=123+Road&Q10=ls11sl&Q2=dave%40hotmail.com&Q4=71&Q5=19-01-1995&Q263=3127&Q262=3126&x=99&y=24 I cannot name all 3 fields (date, month, year) as Q5 si i'm guessing that the 3 values need to be assinged to Q5 before the form is submitted?? Any help on this would be much appreciated as hours of trawling through google has not helped. Many thanks. I have coded a database and I dont like how the user can edit the titles through the get variable. Is there anyway I could stop that? Wouldnt getting each request from the database slow down the site? <?php include "config.php"; include "functions.php"; $SITEURL = addSlash($SITEURL); $action = $_GET['action']; $state = $_GET['state']; $city = $_GET['city']; $id = $_GET['id']; echo $SITEURL; switch($action) { case 'cities': include 'templates/cities.php'; break; case 'place': include 'templates/place.php'; break; case 'places': include 'templates/places.php'; break; default: include 'templates/home.php'; break; } ?> #places.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $siteTitle; ?></title> </head> <body> <h2><?php echo $SITETOPIC." in ".$city.",".getStateName($state); ?></h2> <?php $query = "SELECT DISTINCT biz_name, biz_id FROM animalshelter WHERE city = '".$city."'"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo "<a href=http://".$SITEURL."place/".$state."/".urlencode($city)."/".$row['biz_id'].">".$row['biz_name']."</a><br />"; } ?> </body> </html> #.htaccess # .htaccess mod_rewrite # demo.com Options +FollowSymlinks Options +Indexes RewriteEngine On RewriteBase /databaseSite/ ErrorDocument 404 /templates/404.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)$ index.php?action=$1&state=$2 [QSA,NC] RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z\+\_\-]+)$ index.php?action=$1&state=$2&city=$3 [QSA,NC] RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z\+\_\-]+)/([0-9]+)$ index.php?action=$1&state=$2&city=$3&id=$4 [QSA,NC] 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; A few months ago, and a good amount of time before that, I had people telling me to use isset() instead of performing to see if the variable is empty, such as: !$_GET[''] I know the differences in the function and what they do, but when could isset() be used in a situation where it's better/more efficient then: !$_GET[''] I do use isset(), though. Okay, So I have a dropdown box: Code: [Select] <select name="imgsize"> <option value="small">480 x 360</option> <option value="medium">720 x 540</option> <option value="big">1200 x 900</option> <option value="large">1440 x 1080</option> </select> and I have code that gets the size: Code: [Select] $resizeimg = $_REQUEST["imgsize"]; But I cannot get it to work with an if statement: Code: [Select] if ($resizeimg == "large") { } It just comes up with about 50 lines of gibberish. I have used error_reporting(-1); but that is not coming up with any errors. Could anyone help please. Its probably so simple, but my mind is drawing a blank When i execute the following code, it works and retrieves the record info i am looking for for the appropriate record, 2155015898: $adgrouppass = 2155015898; $selector->adGroupIds = array($adgrouppass); However, when i try to get the adgroup variable from my url, which is where it is located, it doesn't work: $adgroup = trim($_GET['adgroup']); $adgrouppass = $adgroup; $selector->adGroupIds = array($adgrouppass); yet, in trying to fix it, if i echo the above variable, it says it is correct, which is 2155015898. Not sure if the $adgrouppass needs to be a string or variable to get it to pass it correctly. Can anyone help? <?php $foo = 5; $too = 7; ${"foo"}++; ${"too"}++; echo $foo; echo '<br />' . $too; $my_var_name = "foo"; ${$my_var_name}++; echo $foo; ?> I understand the part that $my_var_name is going to increment $foo. But I don't understand that when we used ${"foo"} we did not add the $ sign with it. But when we use ${$my_var_name} we have to add another $ sign. why is that? Hey, <a href="edit.php?id='.$row['id'].'">edit</a> I am learning PHP and I am wondering what I put after my SQL connection info so that I can create a variable $id $id = <what goes here> How do I make $id to store the unique number in this variable.. For example edit.php?id=100 how does it store this number...thanks... Hi there, I am working on a php web form. I have a variable named $isFruit having value of 1 When I do a: print_r($isFruit) It gives me value as 1, which is good. Now I need to pass this php variable into a jquery function: $('document').ready(function() { //I need to get the value of $isFruit variable here } How can pass the php variable into this function. Kindly reply. All comments and feedbacks are always welcomed. Thank you! Hello, I don't have any php knowledge and am having a hard time trying to implement the following: - a drupal node is getting a numeric parameter with the URL in the following form "http://the.url/?X=123" - what I want is for the script to check if the value has been passed with the URL, then use it in a form... if the entered URL was "http://the.url" without the X variable, then use a default value of 321. <?php $_GET['X']; if (isset($X)) { print $X ; } else print "321" ?> Thanks in advance for your help. I am trying to recursively pull records from a database to write to a csv. There are three test rows of data in my table (and no not including the table headers). The only issue is i can’t seem to get my for loop to display all the records – it only displays the last 2 rows so i’m very confused. Anyone suggest why this isn’t working? Code: [Select] $num_rows = mysql_num_rows($export); for ($i=0; $i <= $num_rows; $i++ ) { $row = mysql_fetch_row($export); echo $row[1] . $row[2] . $row[3] . $row[4] . $row[5] . $row[6] ."<br/>"; echo $i; } Incidentally the query is just a fetch all from datasbase. Anyone see where i'm going wrong? Thanks, drongo I have this simple piece of code. I am using GET[] to retrieve the catID from URL, then match it and set a backgorund image, some backgorund images can change per catID variable. When selected or clicked on. It is not working, it is producing the catId in ech $_Get[], but not matching it with $filename to set correct Image. Ex. Browser catID may == 1, it code displays catid = 1, file name = deals_2.jpg. This is worng. should be catid = 1 , filename = 1. PLEASE HELP, missing something. Code: [Select] <?php $imgpath = '/shushmedeals/templates/shushme_deals/images/'; //$bgimgID = $item->id; $bgimgID = isset($_GET['categoryId']); $bgimgID = $_GET['categoryId']; echo $bgimgID; //echo 'shoot her eman'; //echo $imgpath; if($bgimgID){ $bgimgID = 1; $filename = '/shushmedeals/templates/shushme_deals/images/bg_home.jpg'; } if($bgimgID = 2){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img1.jpg'; } if($bgimgID = 3){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img2.jpg'; } else { $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img3.jpg'; } if($filename){ echo '<br>'.$filename; // SET COOKIE //setcookie('bgimg', $filename); //echo $_COOKIE['bgimg']; } else { echo "There is no Background for this category"; // DO NOT SET COOKIE } // Print an individual cookie echo $_COOKIE["location"]; ?> Hi, I'm trying to make an error message appear when a user misses a text field, or fills in an error. All the errors are sent to a form.php, this then sends the error message back to the current page. Here is the code I am using to retrieve the error message: if($form->error = ("user")){ echo $form->error("user"); } if($form->error = ("pass")){ echo $form->error("pass"); } Which works fine, but I only want ONE error message to be displayed at a time. This IS what I want: There are two fields, user, and password. If the user fails to enter anything into both, only one error message will appear "Please enter your username" (which is what the form.php does). When the user fills in the username, but fails to fill in the password then it works, only one error message appears (as there is only one error to send) When the user fills in the password, but fails to fill in the username it also works, only one error message appears. Its just when the user fails to fill in either, it prints both error messages when I only want it to print the 'user' error message. Please help, Thanks I am stuck on trying to get the form to repopulate after a failed validation. The real form involves REST calls and such but I trimmed the code back to this issue. I think I need to declare the variables differently. I also tried to use the variables in the PHP script to refill the form with the original form entries. I have tried numerous ways of getting the variables to repopulate but could never get it to work consistently (such as declaring global variables. Here is the form code: Code: [Select] <div> <a name="error_field"></a> <?php if($_GET['error']): ?> <div style="padding:10px;border:1px solid;color:#C70C0C;"><?php echo $_GET['error'] ?></div> <?php endif; ?> <div> <form method="post" action="process2.php"> <fieldset name="Group1"> <legend>Account Registration</legend> <div id="field"><label id="Firstname">First Name:</label></div> <div id="input"><input name="Firstname" id="Firstname" type="text" value="<?php $_POST['Firstname']?>"/></div> <div id="field"><label id="Lastname">Last Name:</label></div> <div id="input"><input name="Lastname" id="Lastname" type="text" value="<?php $_POST['Lastname']?>"/></div> <div id="field"><label id="Username">E-Mail Username):</label></div> <div id="input"><input name="Username" type="text" value="<?= $_POST['Username']?>"/></div> <div id="field"><label id="Password">Password:</label></div> <div id="input"><input name="Password" type="password" /></div> <div class="center" style="margin-top:15px;margin-bottom:15px"> <input name="Submitx" type="submit" value="submit" /> <input name="Reset1" type="reset" value="reset" /> </div> </fieldset></form> </div> </div> and here is the PHP which I have on a different page Code: [Select] <?php $new_user_username = check_input($_POST['Username'], "Enter your e-mail"); $new_user_password = check_input($_POST['Password'], "Enter your password"); $new_user_first_name = check_input($_POST['Firstname'], "Enter your first name"); $new_user_last_name = check_input($_POST['Lastname'], "Enter your last name"); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $new_user_username)) { show_error("E-mail address not valid"); } else{ header('Location: TY.php'); } function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { header('Location: tp1.php?error=' . $myError); exit(); } ?> Thanks in advance for any help. Hi there, I am working on a PHP web form and I have a very simple situation I guess, I have a variable named: $MyVal When I do print_r($MyVal); To see whats inside, I get: SimpleXMLElement Object ( [0] => 8.23 ) Now I am assigning this variable into a session variable so that I can do calculations with it. So I assign: $_SESSION['MySesVal'] = $MyVal; But after assigning to session variable, when I do my calculations: $finalValue = $_SESSION['MySesVal'] * 4; I get 0. So is it because the actual $MyVal variable has some XML stuff as: SimpleXMLElement Object ( [0] => 8.23 ) So what is the right way to properly assign $MyVal variable to a session variable to do calculations. Please reply. All comments and feedbacks are always welcome. Thank you! |