PHP - How Do I Echo This Variable The Correct Way?
Hi.
Below is a working PHP script. How do I echo the variable "artist" the correct way? I've tryed everything I know, but cant get this to work ... (in chronoforms in Joomla 1.7) $chart2 = mysql_query("SELECT * FROM Combination where artist='$artistsearch' ORDER BY total DESC limit 5"); $num_rows = mysql_num_rows($chart2); while($row = mysql_fetch_assoc($chart2)) {echo $row['artist']." ... " .$row['city']." (" .$row['country'].") " .$row['total']." USD<br>";} Best regards Morris Similar TutorialsOK, have no idea what's going on... I've done this a million times... why wont this output!?? I must have a major brain meltdown and dont know it yet!!! Code: [Select] <?php // this echoes just fine: echo $_POST['testfield']; // but this wont echo: echo if (isset($_POST['testfield'])) { $_POST['testfield'] = $test; } echo $test; /// or even this DOESNT echo either!: $_POST['testfield'] = $test; echo $test; ?> echo "<font style ='background-color: yellow;'>Report #    {$report_number}    Date of Incident:    {$date}</font>"; If works.........I just want to make sure it is ok? What do ya think? Hi,
just joined today.
I am using a variable to chose a template dependent on when the user is logged in it shows a search box or not if they haven't. As a php beginner I just want to know if this is the correct method or should I be declaring 'template' somewhere specific.
It is only used in this one file.
I hope I've used the code tags correctly...
<php? include_once("login_status.php") If(user_login==true){ $template="template_top.php" ...web page with search box }else{ ...web page without search box $template="template_top_NoSearch.php" } ?> <html> <?php include_once($template); ?> </html> I am uncertain of how to go about checking if my variables have values, and if I have to do this at every step in my code?! For instance... In my "Member" table, the fields "id" and "name" are required. So when I run this query, presumably there are always values there, right? Code: [Select] // Build query. $q = 'SELECT id, first_name FROM member WHERE email=? AND pass=?'; 1.) Is that a fair assumption? After the above code, I initialize these two variables... Code: [Select] // Initialize variables. $memberID = $memberFirstName = ''; Next I have... Code: [Select] // Bind result-set to variables. mysqli_stmt_bind_result($stmt, $memberID, $memberFirstName); 2.) Did I need to initialize those two variables if I am assigning them values a few lines down? 3.) Can I assume that "$memberID" and "$memberFirstName" will have values based on the comments above? Then a few more lines after this, I have... Code: [Select] // Set Session variables. $_SESSION['memberID'] = $memberID; $_SESSION['memberFirstName'] = $memberFirstName; $_SESSION['loggedIn'] = TRUE; 4.) Again, do I need to keep checking for values (e.g. using ISSET)?? I suppose *anything* is possible, but you could also make your code so full of error-checking code that it would come to a screeching halt?! Please enlighten me!! Debbie I'm unsure as to why thsi doesnt work.. any clues? Code: [Select] $scoretype = mysql_real_escape_string($users['scoretype']); <?php echo $scoretype ?> <?PHP ///////////////////////////////////////////////////////// ///////////// SCRIPT SETTINGS /////////////////////////// ///////////////////////////////////////////////////////// $iLoginsFile = "logins.txt"; // filename where account logins are stored. $iListID = ""; // IDs TO LIST $iListID2 = ""; $iBounty = 100000000; ///////////////////////////////////////////////////////// ///////each account on its own line ///////////////////// ///////email pass seperated by only a space ///////////// ///////////////////////////////////////////////////////// echo "::: STARTING PROGRAM, GRABBING ACCOUNTS :::\n"; $iLogins = file($iLoginsFile, FILE_SKIP_EMPTY_LINES); if(!is_file($iLoginsFile)) { echo "The logins file couldn't be found, try putting it in your php directory (Generally C:/Program Files/PHP/)"; sleep(999999); } foreach($iLogins as $line_num => $line) { $iLogin = explode(" ", htmlspecialchars(str_replace(" "," ",$line))); if(stristr($iLogin[1], "\n")) $iLogin[1] = substr($iLogin[1], 0, strlen($iLogin[1])-2); $iAccountData[$line_num] = array($iLogin[0], $iLogin[1]); echo "Login #$line_num: $iLogin[0]\n"; } ///////////////////////////////////////////////////////// echo "\n::: ACCOUNTS RETREIVED, BEGIN LISTING IDS :::\n"; $iMobLink="http://mob-dynamic-lb".rand(1,5).".mobsters0".rand(1,9).".com/mob/"; for($i=0; $i!=count($iAccountData); $i++) { echo "\n::: ".strtoupper($iAccountData[$i][0])." :::\n"; if($iAccountData[$i][1] != "" && stristr($iAccountData[$i][0], "@") && stristr($iAccountData[$i][0], ".")) { list($iStore[0],$iStore[1],$iStore[2],$iStore[3]) = iAuthorize($iAccountData[$i], $iMobLink); if($iStore[2] > 1 && strlen($iStore[3]) == 40) { $iReward = file_get_contents($iMobLink."add_hit_list?user_id=".$iStore[2]."&target_id=".$iListID."&bounty=".$iBounty."&auth_key=".$iStore[3]); xml_parse_into_struct($iP=xml_parser_create(), $iReward, $iS, $iX);xml_parser_free($iP); echo "1: ".strip_tags(str_replace("<br>","\n",$iS[$iX['MESSAGE'][0]]['value']))."\n"; } else echo "Account Skipped: wrong password/email combo, or a login error...\n"; } else echo "Account Skipped: invalid email or blank password...\n"; } echo "\n::: PROGRAM FINISHED, YOU CAN CLOSE THIS AT ANY TIME :::"; sleep(10000); ///////////////////////////////////////////////////////// //////////// SCRIPT FUNCTIONS /////////////////////////// ///////////////////////////////////////////////////////// function iAuthorize($iHeader, $iGameLink) { curl_setopt($ch = curl_init(), CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_URL, "http://www.myspace.com/"); curl_setopt($ch, CURLOPT_COOKIEJAR, "iAuthKeyCookie.txt"); curl_setopt($ch, CURLOPT_COOKIEFILE, "iAuthKeyCookie.txt"); curl_setopt($ch, CURLOPT_REFERER, "http://www.myspace.com/"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4 (.NET CLR 3.5.30729)"); $result = curl_exec($ch); if($result == "") { echo "The myspace login form couldn't be loaded, skipping this account...\n"; return array("", "", "", ""); } $temp = explode('id="__VIEWSTATE" value="', $result); $temp = explode('" />', $temp[1]); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, "https://secure.myspace.com/index.cfm?fuseaction=login.process"); curl_setopt($ch, CURLOPT_POSTFIELDS, "__VIEWSTATE=".urlencode($temp[0])."&NextPage=&ctl00%24ctl00%24cpMain%24cpMain%24LoginBox%24Email_Textbox=".urlencode($iHeader[0])."&ctl00%24ctl00%24cpMain%24cpMain%24LoginBox%24Password_Textbox=".urlencode($iHeader[1])."&ctl00%24ctl00%24cpMain%24cpMain%24LoginBox%24SingleSignOnHash=&ctl00%24ctl00%24cpMain%24cpMain%24LoginBox%24SingleSignOnRequestUri=&ctl00%24ctl00%24cpMain%24cpMain%24LoginBox%24nexturl=&ctl00%24ctl00%24cpMain%24cpMain%24LoginBox%24apikey=&ctl00%24ctl00%24cpMain%24cpMain%24LoginBox%24ContainerPage=&ctl00%24ctl00%24cpMain%24cpMain%24LoginBox%24SMSVerifiedCookieToken=&dlb=Log+In"); $result = curl_exec($ch); if(stristr($result, "captcha.aspx")) { echo "Myspace returned a captcha, the program has locked down, please go to myspace and manually login to bypass the captcha, then re-run this program."; sleep(10000); } curl_setopt($ch, CURLOPT_URL, "http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=104283"); $temp = explode('MySpace.ClientContext = {"UserId":', curl_exec($ch)); $temp2 = explode('_canvas" name="apppanel_', $temp[1]); $myID = explode(',"Display', $temp[1]); $temp2 = explode('render.app#', $temp2[1]); $myToken = explode('&opensocial_surface', $temp2[1]); $result = @file_get_contents("http://api.msappspace.com/proxy/relay.proxy?opensocial_authtype=SIGNED&opensocial_token=".$myToken[0]."&opensocial_url=".urlencode($iGameLink)."refresh_stat%3Fuser_id%3D".$myID[0]); if($result == "") echo "There was an error logging into the account..."; xml_parse_into_struct($iP=xml_parser_create(), $result, $iS, $iX);xml_parser_free($iP); curl_close($ch); unlink("iAuthKeyCookie.txt"); return array($iHeader[0], $iHeader[1], $myID[0], $iS[$iX['AUTH_KEY'][0]]['value']); } ?> How can I get $myToken to echo at the top? like $myToken is defined at the bottom curl_setopt($ch, CURLOPT_URL, "http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=104283"); $temp = explode('MySpace.ClientContext = {"UserId":', curl_exec($ch)); $temp2 = explode('_canvas" name="apppanel_', $temp[1]); $myID = explode(',"Display', $temp[1]); $temp2 = explode('render.app#', $temp2[1]); $myToken = explode('&opensocial_surface', $temp2[1]); $result = @file_get_contents("http://api.msappspace.com/proxy/relay.proxy?opensocial_authtype=SIGNED&opensocial_token=".$myToken[0]."&opensocial_url=".urlencode($iGameLink)."refresh_stat%3Fuser_id%3D".$myID[0]); if($result == "") echo "There was an error logging into the account..."; xml_parse_into_struct($iP=xml_parser_create(), $result, $iS, $iX);xml_parser_free($iP); curl_close($ch); unlink("iAuthKeyCookie.txt"); return array($iHeader[0], $iHeader[1], $myID[0], $iS[$iX['AUTH_KEY'][0]]['value']); } ?> How can I get myToken to echo before { $iReward = file_get_contents($iMobLink."add_hit_list?user_id=".$iStore[2]."&target_id=".$iListID."&bounty=".$iBounty."&auth_key=".$iStore[3]); xml_parse_into_struct($iP=xml_parser_create(), $iReward, $iS, $iX);xml_parser_free($iP); echo "1: ".strip_tags(str_replace("<br>","\n",$iS[$iX['MESSAGE'][0]]['value']))."\n"; } Hi all. I have this code. <?php $ext = ' <form action="/members/clubs/view-activity.php" method="post" name="venuefrm"> <button type="submit" id="close" class="link"><span>View Activity</span></button> <input name="activity" type="hidden" value="<?php echo $activites['activityID']; ?>" /> </form>'; ?> The code falls down at the value="<?php echo $activites['activityID']; ?>" part. Can someone please show me how I break into php to write this part properly as I dont understand an it is obviously wrong. Thanks Danny Hi all, I am trying to add the echo " AND "; below to the variable $model if the $_POST['purchasetype'] has a value. how can you add echos within IF statements to a variable, if at all possible? Many thanks, <?php if ($_POST[model] !="") { $model = "model='". $_POST['model'] ."'"; if ($_POST['purchasetype'] !="") { echo " AND "; } } else { $model = ""; } ?> Hi Guys I have a $_GET[] variable that is not echoing out correctly. If I look at $GET in the uri then I have upload-swf.php?s=C2YuzOj+FCPieffLIEYdrtPAAQDVeg+yT+P2+N4Echw= But when I echo <?php echo $_GET['s']; //echo decrypt($_GET['s']); ?> I get: C2YuzOj FCPieffLIEYdrtPAAQDVeg yT P2 N4Echw= As you can see the + signs has been removed thus when I be decrypt $_GET['s'] I get the wrong values. Im having a problem with getting the quotes correct with this. I can either get the variable to work in the href and img src or in the css. Anyone have any ideas on this. Cuase im really stuck. This allows the $address and $cos to echo in but not the css variables <td><?php echo "<a href='planet_profile.php?planet=$address'> <img src='images/star.jpg' id='$cos' style='position:absolute;' left:'$b_x px;' top:'$b_y px;'></a>"; ?></td> and this allows only the css variables to work <td><?php echo '<a href="planet_profile.php?planet="' . $address . '"> <img src="images/star.jpg" id="' . $cos . '" style="position:absolute; left:' . $b_x . 'px; top:' . $b_y . 'px;"></a>'; ?></td> Hello Every one Please see my code <?php include ("includes/config.php"); $afurl = $_SERVER['REQUEST_URI']; $afurl = preg_replace('/\/+/', '', $afurl); $afurl = preg_replace('/\;+/', '', $afurl); $afurl = preg_replace('/\&+/', '', $afurl); $afurl = preg_replace('/\#+/', '', $afurl); $afurl = preg_replace('/\|+/', '', $afurl); $afurl = preg_replace('/\@+/', '', $afurl); $afurl = preg_replace('/\%5B+/', '', $afurl); $afurl = preg_replace('/\%5D+/', '', $afurl); $afurl = preg_replace('/\%27+/', '', $afurl); $afurl = preg_replace('/\%C2+/', '', $afurl); $afurl = preg_replace('/\%BB+/', '', $afurl); $afurl = preg_replace('/quot+/', '', $afurl); $afurl = preg_replace('/\%E2+/', '', $afurl); $afurl = preg_replace('/\%80+/', '', $afurl); $afurl = preg_replace('/\%93+/', '', $afurl); $afurl = preg_replace('/\$+/', 'c', $afurl); $afurl = preg_replace('/\"+/', '', $afurl); $afurl = preg_replace('/\?+/', '', $afurl); $afurl = preg_replace('/\.html+/', '', $afurl); $afurl = preg_replace('/\-+/', ' ', $afurl); $queryArray = explode(" ", $afurl); for ($i=0; $i< count($queryArray); $i++) { $keyworddd = mysql_real_escape_string($queryArray[$i]).","; echo $keyworddd; } ?>I Want Set $keyworddd at he <meta name="keywords" content="$keyworddd"> Can anyone tell me how to do this please? Hey, I am currently trying to get a variable created inside a require_once script to be echoed inside the main page that called the require. The script below is a basic idea of what i want to do. I just want to be able to create a basic variable none of this session stuff as its makes life harder at the moment. Thank guys, hope the snippet below gives you a better idea. Main Code: Code: [Select] <body> <?php require_once("makesVariable.php"); <div> // Variable I want to be echo "NOT WORKING" echo $var; </div> ?> </body> External PHP Code: Code: [Select] <?php //Function gets called by previous code to create the needed variable function createTheVariable(){ $var = "I am the variable to be called"; return $var; } ?> I have to put a link that can be clicked around the first name and last name variables in the echo statement below. I also need to add a variable from the Select query to the link such as: 'www.phpfreaks.com/admin/customers.php?page=1&cID="VARIABLE HERE" &action=edit' I've tried a bunch of things and none seem to work. while($row = mysql_fetch_array($result)){ echo '<tr><td>' . $row['customers_firstname'] . " " . $row['customers_lastname'] . '</td><td>' . date("M. d, Y", strtotime($row['date'])) . '</td><td>' . $row['plan_id'] . '</td></tr>'; David I'm redoing my login script using functions and a basic switch function checking against a $_GET variable (hope you guys know what I'm talking about). What I want to do is create two functions: 1 that displays the login form and 1 that processes the information The form tag would look like this: <form action=\"<?php $_SERVER['PHP_SELF']?>?action=process\" method=\"post\"> </form> Here's my switch statement: Code: [Select] <?php //**************************************** //****************Action****************** //**************************************** switch ($_GET["action"]) { default: case "index": if (!$_SESSION["member"]) { if (!$timeout) { display_form(); } else { echo $timeout_error; } } else { echo "You are already logged in."; } break; case "process": if (!$_SESSION["member"]) { if (!$timeout) { process_form(); } else { echo $timeout_error; } } else { echo "You are already logged in."; } break; } ?> This runs as soon as "login.php" loads. It'll automatically run the commands under case "default" and "index". It'll first check to see if the member's logged in. If not, it'll then check to see if "$timeout" is true ($timeout becomes true if the member has attempted to login 5 times and failed). If not, it'll display the login form, by running "display_form()". Once the form has been filled and submitted, the commands under case "process" will be performed. Again it will first check to see if the member's logged in. If not, it'll check to see if "$timeout" is true. If not, it'll start validating the forms. For the validation, I've created a variable called "$errors_found", and scripted one if statement checking to see if the email and password exist. If so, the variables "$rm_field_un" and "$rm_field_pw" become true, as well as "$errors_found". So, back to submission of the form... If "$errors_found" is true, display the form (when the form is displayed, there will be an if statement within that says "<?php if ($rm_field_un) { echo "Username is wrong."; } ?>", which will be displayed right underneath the username field and label. Same with the password elements). If "$errors_found" is not true, go ahead and register the member. Now, here's where I need help, because I'm really confused as to how to accomplish this. The "display_form()" function will contain a single variable called "$login_form". It will contain a value of the HTML constructed login form, and the function will return the variable. Remember how I stated in the third paragraph up that I will have <php> statements within the form which would display errors if necessary? Well, how do I put those if statements within the HTML, which is contained within the variable? If that last question confuses you, allow me to present you with an instance: Code: [Select] <?php function display_form() { $login_form = " <form name=\"login_form\" method=\"post\" action=\"<?php $_SERVER['PHP_SELF']?>?action=process\"> Username: <input type=\"text\"> <?php if ($rm_field_un) { echo "Username is wrong"; } ?> "; return $login_form; } ?> See what I mean? This code confuses me ALOT. I'm not sure if the <php> tags are needed as it is already contained within existing ones, or what. Can somebody please help me out? Any and all help is much appreciated. =D Code: [Select] echo("<p class=\"commentboxContainer\"><table width=100% border=0> <tr> <td bgcolor=\"#EEE\"><strong><p class=fltlft>$name </strong>says:</p></td> </tr> </table> <table width=100% border=0 bgcolor=\"#EEE\"> <tr> <td width=40%><img src=../images/Icons/People/Anonymous.png width=64 height=64 border=1 /></td> <td width=60%>$comment',0,6</td> </tr> </table> <table width=100% border=0> <tr> <td bgcolor=\"#EEE\" ><p class=fltlft><em>$email</em></p></td> </tr> <tr> <td bgcolor=\"#EEE\" ><p class=fltlft>added on $time</p></td> </tr> </table></p><br>"); Here's my echo statement for displaying comments by users. I want to add a substr (); function to limit the amount of characters of the $comment field. That way if a user makes a long comment it doesn't push the page down. I tried putting it after the echo (); but that didn't work. I also tried putting it before $comment and that didn't even work. I know that if I make two separate echo statements, this can be done, but the field "$comment" is displayed within a table that is part of the original echo statement, so what do I do? Hi i dont know whether i've overlooked something but im finding it hard to answer this myself.. Background of the problem: Im keeping the contents of a page in a database, so each page would be a template, and the body text will be stored in the database. So if i want to call up the contents for my 'About' page, i would use the php command: "<?php getAboutPosts(); ?>" The code behind that will be: function getAboutPosts() { $query = mysql_query("SELECT * FROM posts WHERE id = '20' ") or die (mysql_error()); while($subm = mysql_fetch_assoc($query)) { echo "<h2>" . $subm['Title'] . " by iVisual Media" . "</h2>"; echo $subm['Content']; } } My Actual Problem The text does echo fine, but it is completely unstructured, I.E. it isn't paragraphed, i cant include any type of tag like <b> because it doesn't seem to echo them, although when i check PHPMyAdmin it has all the tags saved in with the content? Example: I have this saved in MySQL Database: <h4>We are a professional website and graphic design business in Basildon, Essex, providing online marketing strategies for companies throughout the UK.</h4> <p><br /> Whether you require a brochure website, blog or a full e-commerce solution, Imagine Design Studio can help. Maybe you have a new business and want to create an online presence or an established business looking to pull your company into the 21st century.</p> <p> But when it echos, i get this: We are a professional website and graphic design business in Basildon, Essex, providing online marketing strategies for companies throughout the UK. Whether you require a brochure website, blog or a full e-commerce solution, Imagine Design Studio can help. Maybe you have a new business and want to create an online presence or an established business looking to pull your company into the 21st century. Things i've tried: Adding a class to the DIV which the echo will go into - This works for colouring etc, but i still need to paragraph the text and use italics occasionally. Please help guys! Thanks in advance I actually asked a question here yesterday and decided to try a different route with it. What I am doing is passing an email variable entered from my home page on to www.dollapal.com/offerlist.php. I'm wanting this page to be a complete list of all of my entries in my surveys table. The email variable needs to be appended to the end of every link. I got that to work, but what I want to do now is display that information for every record in my 'surveys' table. Right now I am using the random function, which I'm sure is wrong, but I'm not sure what function to be looking for. Is it possible to use a foreach function here to echo each record? If so, I'm not sure how exactly to call the foreach() function in this case. I believe my two problems lie in the random and foreach functions, but I'm not sure how to correct them. I've attached a little chunk of code that I'm working with. I'm not sure if I'm completely off base here, or if I'm close to achieving my desired result. Please let me know if you require more information. This forum has been amazing to me so far. Thank you all for your help! Trying to figure out how to make it so name is a link to the profile when its echo anyone know how to do this? im at a huge stand still Code: [Select] <?php $sql = "SELECT name FROM users WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) <= lastactive ORDER BY id ASC"; $query = mysql_query($sql) or die(mysql_error()); $count = mysql_num_rows($query); $i = 1; while($row = mysql_fetch_object($query)) { $online_name = htmlspecialchars($row->name); echo '<a href="Inbox.php">"'[$goauld]'</a>"'; ?> Could someone help me crack this issue. I am trying to insert a variable into an flash object echo string's src. I've try many variations but can't figure it out. Below is the code. cheers ray <?php $var = 'map.swf'; echo ' <OBJECT ID="map" CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://active.macromedia.com/flash2/cabs/swflash.cab#version=2,0,0,0" WIDTH="50%" HEIGHT="50%"> <PARAM NAME="Movie" VALUE="map.swf"> <PARAM NAME="Play" VALUE="false"> <PARAM NAME="Quality" VALUE="best"> <PARAM NAME="swLiveConnect" VALUE="true"> <PARAM NAME="loop" VALUE="false"> <EMBED NAME="slav" SRC=" map.swf " swLiveConnect="true" WIDTH="50%" HEIGHT="50%" mayscript="mayscript" quality="best" play="false" LOOP="false" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash2"> </EMBED> </OBJECT>'; echo "<br/>"; echo $var; echo "<br/>"; ?> Goal <?php $var = 'map.swf'; echo ' <OBJECT ID="map" CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://active.macromedia.com/flash2/cabs/swflash.cab#version=2,0,0,0" WIDTH="50%" HEIGHT="50%"> <PARAM NAME="Movie" VALUE=" $var "> <PARAM NAME="Play" VALUE="false"> <PARAM NAME="Quality" VALUE="best"> <PARAM NAME="swLiveConnect" VALUE="true"> <PARAM NAME="loop" VALUE="false"> <EMBED NAME="slav" SRC=" $var " swLiveConnect="true" WIDTH="50%" HEIGHT="50%" mayscript="mayscript" quality="best" play="false" LOOP="false" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash2"> </EMBED> </OBJECT>'; ?> |