PHP - How Do I Put Html Brackets Inside Php
hi silly little question but if I want to bracket something inside PHP how do I do it eg my code is
Code: [Select] <th class="alignright"><?php echo $ass_descrip; ?> (<?php echo $ass_accro ; ?>) <?php echo FindTypeName ($type_id); ?></th> printing out British Eventing (BE) But the brackets at the moment are outside the PHP I want to put a conditional on it and include the brackets inside my conditional statement.? Similar TutorialsThis topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=316454.0 function send_msg($sender , $message){ if(!empty($sender) && !empty($message)){ $sender = mysql_real_escape_string($sender); $message= mysql_real_escape_string($message); $query = "INSERT INTO `chat`.`chat` VALUES (null , '{$sender}' , '$message')"; // Difficulty on THIS LINE !!!! if($run = mysql_query($query)){ return true; }else{ return false; } } why is '{$sender}' given the curley brakets ????? and why is message not given the same brackets ? also why is this function used ? i.e. mysql_real_escape_string , i know what it does , but is it to prevent SQL injection. Hi Guys Quick noob question. I am still fairly new to oop and i'm trying to also build my first simple mvc to learn about that too. I came across some syntax use in a tutorial that works but i don't really understand why and don't know what this is called to search for it on google. I've instantiated the class and then i pull out and explode the url to make controller or function calls in the mvc. The noob bit i don't understand is this Code: [Select] $controller->{$url[1]}(); Why do the curly brackets allow you to place a variable name? And what is this type of syntax called so i can read about it. Any help would be massively appreciated! Drongo Hi Yes I start a new thread, this is probably the correct one. Hi there i was wondering how i would go about using html tags inside the php tags so i could put data from a database into a textarea / text input i had a go but had no such luck with this attempt: <?php echo "Title:<br>"; echo "<input type="text" name="title" value="$row['Title']">"; ?> the code above is to give you an idea of what i want to do, if you can point me to any guides or show me how it will be greatly appriciated Thanks, Blink359 Code: [Select] 30|24|17,5|4|20,15|13|33,15|22|33,9|20|22 Let's say my output is that, Realistically every 3numbers is 1 Ticket they are seperated by a "," (comma) I want to wrap parenthesis around them so the output would look like this Code: [Select] (30|24|17) (5|4|20) (15|13|33) (15|22|33) (9|20|22) Now would I have to use regex.. or not cuz regex is extremely difficult Thanks Hi Ive been trying to solve this problem for a few hours but am having no luck so would appreciate any help Im looking for a function/way of extracting info from a dropdown list when a form is submitted. The form field has a name and email address i.e John (john@smith.com) and i just need the email address part to submit into a mysql database. I tried using the explode() function but this didnt work. Any ideas? Cheers Andy For example. I have the following: Andrew (Age 19) How would I get the content between the brackets, Age 19 using preg_match_all or a similar function? Thanks very much I am having trouble implementing PHP inside a HTML attribute. Every time I try to fix it, I seem to make things worse. Can someone please help me: <INPUT name="id" type="text" value=""<?php echo "$row['id']"; ?>""> Hey guys! Im trying to setup an IF statement on my home page. Its purpose is to show EITHER a login form and state your not logged in if it cannot find a stored cookie OR if it does find a stored cookie it will NOT show the HTML form and state you are logged in. I have it mostly working apart from the fact Im not sure how to insert a HTML form into PHP IF statement and make it work. Since I dont want the user to see the login form when they are already logged in. Here is a link to the php script: http://pastebin.com/aenq4gbE Here is link to the live page: http://jfbsystems.co.uk/secure Any help or ideas would be much appreciated! JellyFishBoy I'm trying to create a Facebook fangate, and I want an imagemap to come up to fans, but a static image to come up for non-fans. Here's the code. Someone please tell me what I'm doing wrong. I've tried it 3 different ways. (I searched Google and this forum before posting...nothing I found worked for me). While I've removed identifying information, I have tested and made sure the bitmapped image works properly (can call it through facebook on its own) as well as the regular image. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <link rel="stylesheet" type="text/css" href="style.css" /> <style type="text/css"> body { width:520px; margin:0; padding:0; border:0; }</style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <? require 'facebook.php'; $app_id = "XXXXXXXXX"; $app_secret = "XXXXXXXXXXX"; $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true )); $signed_request = $facebook->getSignedRequest(); if ($like_status) { ?> <div><img src="http://xxxxxx.com/facebook/FBnavbar.png" alt="" usemap="#FB Nav Bar" style="border-style: none" /></div> <div> <map id="FB Nav Bar" name="FB Nav Bar"> <area shape="rect" alt="About xxxxxx Social Media" coords="6,21,80,42" href="http://www.facebook.com/xxxxxxx?sk=info" title="About xxxxxx Social Media" /> <area shape="rect" alt="xxxxxx Blog" coords="222,24,276,38" href="http://www.facebook.com/xxxxxxxsk=app_?????" title="xxxxxx Blog" /> <area shape="rect" alt="xxxxxx Social Media" coords="297,23,391,39" href="" title="xxxxxx Social Media" /> <area shape="rect" alt="Contact xxxxxx Social Media" coords="409,23,508,39" href="../../../contact/" title="Contactxxxxxx Social Media" /> <area shape="rect" alt="Subscribe to our RSS feed" coords="443,1,459,14" href="http://feedburner.com/xxxxx" title="Subscribe to our RSS feed" /> <area shape="rect" alt="Share us on delicious" coords="463,0,478,18" href="http://www.delicious.com/share?new=1&hash=e16eda577a70c83c0dfa2c8c29e52d24&key=tnNrKLSea55V6Tkd2ze9ujDWVOs-&title=xxxxxxx%2xxxxp%20Reputation%20Management&url=http%3A%2F%2Fxxxxxxx%2F&jump=%2Furl%2Fe16eda577a70c83c0dfa2c8c29e52d24" title="Share us on delicious" /> <area shape="rect" alt="Add us on LinkedIn" coords="485,3,499,18" href="http://www.linkedin.com/company/xxxxxx" title="Add us on LinkedIn" /> <area shape="rect" alt="Follow our Director on Twitter" coords="503,1,519,17" href="http://www.twitter.com/xxxxxxx" title="Follow our Director on Twitter" /> <area shape="rect" alt="Learn about xxxxxxxx's Services" coords="98,21,202,40" href="http://www.facebook.com/xxxxxx?sk=app_?????" title="Learn about xxxxxxx's Services" /> <area shape="default" nohref="nohref" alt="" /></map></div> <?php } else { ?> <img src="http://xxxxx.com/facebook/landing/SRfanpage3.png" /> <?php } ?> </body> </html> I'm very new at this (not a php coder, just grabbed some code from a tutorial and am trying to make it work), so please be gentle. Thanks for your help in advance. This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=351491.0 Hello, people!
I was watching some php tutorials in youtube and, in a video, the guy was showing how put php script inside html code. I would like to know why in the following code he didn't use only one php script?
1- Code used in the video:
<html> <body> <?php $color = $_GET['clr']; ?> <b><font color="<?php echo $color;?>">This is a test.</font></b> </body> </html>2- Modified code by me to test with one script: <html> <body> <?php $color = $_GET['clr']; echo "<b><font color=\"$color\"> This is a test. </font></b>"; ?> </body> </html>Is his code more correct(with two scripts)? Why? How can this be written in PHP? Code: [Select] echo '<IMG alt="" src=".$row['id']/thumb.png">'; 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 Hello all! I cannot seem to figure out a way to pass an object from one page to another. Now, my flow may be way off, and if it is, please do advise. I want to have a form for username/password log in. When the submit button is hit, it takes those values, finds the matching user in the database, and returns the user object. We'll call him user_object Now, I want to bring up another page, that allows user_object to enter in additional information (Event details). After it does this, it writes those Event Objects into the database. My problem is: I need the ID Object attached to user_object while inserting the Event Objects into the database. The user_object and Event Objects values are assigned from two separate forms and two separate submit buttons. How do I pass this information? I don't want to use session because I have a lot of objects and do not want to serialize and unserialize all the time. I also read that $_GET is a security risk. Thanks in advance for any help! This is the basic logic of the code I am trying: Code: [Select] <html form whatevs post> <php object_one if (creds_match) { build_object from db } else "Wrong info, dude" ?></endhtml stuffs> Code: [Select] <html form whatevs post> <php object_two if (post!empty) { object_two = poststuff } assign object_two object_one's _id insert object_two into db ?></endhtml stuff> How do I keep the values assigned in section one, and send them or be able to use that same variable in section 2? is there any way to POST array without brackets in name attribute? i.e. instead of "product[]" have "product" in the <input name="<NAME>"> Thanks in advance CSJakharia Is making a double elimination tournament style bracket system capable of being done in php? After dealing with numerous very well qualified programmers to only turn down the project due to difficulty or lack of a solution I am curious if anyone has figured this out. I have run across a few sites that have some programs but all turn up to have some issues with the pairing of teams. Please let me know! If you know the solution, we can work something out as far as payment. This is not a looking for work post, but merely a "can it be done" and if so and you are willing to share the info, it would be greatly helpful. Quote Hi Guys I'm trying to remove the brackets around a string with preg_replace I seem to able to remove the first bracket but not the last. Here are my attempts..... heres the string Code: [Select] $testemail = '(bobbyboo@sample.com.au)'; echo $testemail; $testemail2 = trim(preg_replace('/^[\(]/', '', $testemail)); echo $testemail2."<br />"; $testemail3 = trim(preg_replace('/$\)/','', $testemail2)); echo $testemail3."<br />"; I'm looking for a method to replace everything between brackets. The patterns that I'm looking for are defined: "/\[([2-9TJQKA][hdcs])\]/" The pattern inside the bracket could accur 2 or even 3 times inside the brackets. For example first occurance would be [Ac Kd], here I want to replace Ac into an imge and Kd too. Later in the text I will most of the time get 3 sets, instead of two: [Jc Td 9d]. The sets always consist of [2-9JQKA][hdcs] and also in this order. Another example: [2d 2s 2h], or [3s 4h 5c]. If I use the following function, it would not work optimally because some texts do contain some of those sets which should not be converted, ONLY the sets between the brackets: $haystack = setReplace($haystack); function setReplace($haystack) { $array = array("2s", "2h", "2d", "2c", "3s", "3h", "3d", "3c", "4s", "4h", "4d", "4c", "5s", "5h", "5d", "5c", "6s", "6h", "6d", "6c", "7s", "7h", "7d", "7c", "8s", "8h", "8d", "8c", "9s", "9h", "9d", "9c", "Ts", "Th", "Td", "Tc", "Js", "Jh", "Jd", "Jc", "Qs", "Qh", "Qd", "Qc", "Ks", "Kh", "Kd", "Kc", "As", "Ah", "Ad", "Ac"); for($i=0;$i < count($array);$i++) { $result = str_replace($array[$i], "<img src=\"/images/".$code[$i].".png\">",$haystack); } return $result; }Any ideas? Edited by dde, 20 January 2015 - 10:21 AM. |