PHP - Embeding Php Inside A Html Attribute
How can this be written in PHP?
Code: [Select] echo '<IMG alt="" src=".$row['id']/thumb.png">'; Similar TutorialsI 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']"; ?>""> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=316454.0 Hi All,
I have a form with a jquery autocomplete input field. Once the user has entered 2 characters, there is a list of values (people names) containing this string that appears. This works good.
The values come from a database table with two fields (names and ids). The query that extracts the names also retreives the values in the id field.
What would be the syntax to set the "value" attribut of the input tag to the id of a name when the user clicks on that name in the list?
The PHP part that builds the json is :
$data[] = array( 'label' => $row['name'], 'value' => $row['name'], 'id' => $row['id'] ); echo json_encode($data);The JS begins as follows : jQuery(document).ready(function(){ $('#input_id').autocomplete({source:'my_jquery_suggest.php', select: function(event, ui) { $(event.target).val(ui.item.value); $('#form_id').submit(); return false; }, minLength:2,delay: 1000}).focus(function () { window.pageIndex = 0; $(this).autocomplete("search"); }); ...Thanks for your help. I placed car-dealer-website, a web application from car-dealer-website.org , in a subdirectory on my host mysite.com/car. Wordpress is public_html (mysite.com). What I am trying to do is embed mysite.com/car in Wordpress. I tried iframe and it is ugly. I looked for a php css options,using a code I found online, it didnt work but I saw hope and think php and css is the solution. What I am asking for is direction on using php and css to embed in Wordpress. I want to write code no plugins. I hope to learn some php coding. Thank you in advance for your suggestions, tutorials, different methods. How can i embed variables into an email message. Eg. If i want to add the result of mysql query, would i do somthing similiar to this; mail( "email@domain.co.uk", "Header","$message $result" ); ? Obviously this doesn't work. In fact i get the message from my html form, followed by 'Resource id #2'. Im learning php at the moment. If anyone could help me with this, or point me in the right direction this would be great. Iv'e looked at w3schools but I cant find anything specific like this. mysql_connect("db.hostedresource.com","treesurgery","password here"); mysql_select_db("treesurgery") or die("Unable to select database"); $code = $_GET['postcode']; $message = $_GET['message']; $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode LIKE '%$code%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; while ($row = mysql_fetch_array( $result )) { echo " ".$row['email'] . "<br>"; } echo "<br>"; echo $message; mail( "email@domain.co.uk", "Header","$message" ); echo "Thank you for using our mail form."; I think I finally figured out what my problem is! I have this huge login system that I got and I think it's designed so that in order to login it has a popup window come up. Well I want embed this page so the user can login right their on the page. Before I was using include but that screws up all the submit buttons. Anyone know of a simple code to embed a page? 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.? 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 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? 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. 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 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=316889.0 The Script:
$desired_width = 110; if (isset($_POST['submit'])) { $j = 0; //Variable for indexing uploaded image for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array $target_path = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/uploads/"; //Declaring Path for uploaded images $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) $file_extension = end($ext); //store extensions in the variable $new_image_name = md5(uniqid()) . "." . $ext[count($ext) - 1]; $target_path = $target_path . $new_image_name;//set the target path with a new name of image $j = $j + 1;//increment the number of uploaded images according to the files in array if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded. && in_array($file_extension, $validextensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>'; $tqs = "INSERT INTO images (`original_image_name`, `image_file`, `date_created`) VALUES ('" . $_FILES['file']['name'][$i] . "', '" . $new_image_name . "', now())"; $tqr = mysqli_query($dbc, $tqs); // Select the ID numbers of the last inserted images and store them inside an array. // Use the implode() function on the array to have a string of the ID numbers separated by commas. // Store the ID numbers in the "image_file_id" column of the "thread" table. $tqs = "SELECT `id` FROM `images` WHERE `image_file` IN ('$new_image_name')"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $fetch_array = array(); $row = mysqli_fetch_array($tqr); $fetch_array[] = $row['id']; /* * This prints e.g.: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 ) */ print_r($fetch_array); // Goes over to create the thumbnail images. $src = $target_path; $dest = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/thumbs/" . $new_image_name; make_thumb($src, $dest, $desired_width); } else {//if file was not moved. echo $j. ').<span id="error">please try again!.</span><br/><br/>'; } } else {//if file size and file type was incorrect. echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>'; } } }Hey, sorry that I am posting this darn image upload script again, I have this almost finished and I am not looking to ask more questions when it comes to this script specifically. With the script above I have that part where the script should store the ID numbers (the auto_increment column of the table) of the image files inside of one array and then the "implode()" function would get used on the array and then the ID numbers would get inserted into the "image_file_id" column of the "thread" table. As you can see at the above part the script prints the following: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 )And I am looking to insert into the column of the table the following: 542, 543, 544I thought of re-writing the whole image upload script since this happens inside the for loop, though I thought maybe I could be having this done with the script as it is right now. Any suggestions on how to do this? I have the following code in html: <html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "http://VARIABLEVALUE.mysite.com" } //--> </script> <title>Redirecting ...</title> </head> <body onLoad="setTimeout('delayer()', 1000)"> <script type="text/javascript"> var sc_project=71304545; var sc_invisible=1; var sc_security="9c433fretre"; </script> <script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript> <div class="statcounter"><a title="vBulletin statistics" href="http://statcounter.com/vbulletin/" target="_blank"><img class="statcounter" src="http://c.statcounter.com/71304545/0/9c433fretre/1/" alt="vBulletin statistics" ></a></div></noscript> </body> </html> Is a basic html webpage with a timer redirect script and a stascounter code. I know a bit about html and javascript, but almost nothing about php. My question is: How a can convert this html code into a php file, in order to send a variable value using GET Method and display this variable value inside the javascript code where says VARIABLEVALUE. Thanks in adavance for your help. I'm trying to pull results from a database (using php) to populate a javascript "top news rotation" script I found. The problem is that I'm getting the "java is disabled" message that is in the code...instead of the results I'm expecting. Here's the code: Code: [Select] <!-- create a element in your HTML like the following --> <div id="quotetext" > Text will go here. Be sure to add initial text here for users with JavaScript disabled. </div> <!-- The easiest way is to place the below JavaScript code after the above HTML. The better way would be to add in the <head> section of the document and call the rotatequote() function through the window.onload event. However this can cause problems if you have other scripts that use the window onLoad settings --> <script type="text/javascript" > var myquotes = new Array( <?php $link = mysql_pconnect($host, $username, $password); mysql_select_db('briansch_brn',$link); $sql = "SELECT * FROM story WHERE ORDER BY date DESC LIMIT 4"; $rs = mysql_query($sql,$link); $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; echo "'<strong>$row[headline]</strong><br />(posted $row[date]) - $row[short_story]<br /><a href='/pages/$row[keyword]'>READ MORE</a>'"; if($matches < 4) { echo ','; } if($matches == 4) { echo ''; } } if (! $matches) { echo (""); } echo ""; ?> ); function rotatequote() { thequote = myquotes.shift(); //Pull the top one myquotes.push(thequote); //And add it back to the end document.getElementById('quotetext').innerHTML = thequote; // This rotates the quote every 10 seconds. // Replace 10000 with (the number of seconds you want) * 1000 t=setTimeout("rotatequote()",10000); } // Start the first rotation. rotatequote(); </script> I know that javascript inside php is hard to make work...and I know that php inside javascript is hard to make work. Any ideas? Thanks! I want to get the url in the [@attributes] Atm i get the title like this Code: [Select] foreach ($xmlTree->channel->item as $item) { echo '<p>'.$item->title.'</p>'; } i tried this Code: [Select] $imageUrl = $item->enclosure->@attributes->url; print_r2($imageUrl); but then i get this error: Quote Parse error: syntax error, unexpected '@', expecting T_STRING or T_VARIABLE or '{' or '$' in / this is the XML: Quote => SimpleXMLElement Object ( [title] => #3315: Woord van het jaar: weigerambtenaar, Arabische lente tweede, plaszak derde [link] => http://www.nrc.nl/nieuws/2011/11/26/woord-van-het-jaar-weigerambtenaar/?utm_campaign=rss&utm_source=syndication [pubDate] => Sat, 26 Nov 2011 17:00:55 +0100 [guid] => nieuws_153690 [description] => SimpleXMLElement Object ( ) [enclosure] => SimpleXMLElement Object ( [@attributes] => Array ( [url] => http://www.nrc.nl/wp-content/uploads/2011/11/vmBruidstaart5501_63103-586x4801-300x245.jpg [length] => [type] => image/jpeg ) ) ) I want to remove the current attribute of the tag and add the new one. I wrote the php program but it gives me no output. Can someone help me please??? Here is my code!!! <?php $xml = new DOMDocument(); $xml->load('test.xml'); $node = $xml->getElementsByTagName('*'); $nodename = ""; $node_name = ""; $att = ""; $attr_name = ""; $attr_value = ""; foreach($node as $value) { echo "Node Name is :".$value->nodeName; $nodename = $value->nodeName; $node_name = $xml->getElementsByTagName('$nodename')->item(0); echo $nodename; foreach($nod_name as $value1) { $att = $node_name->getAttributeNode('$value1'); echo "Node Name is :".$att->name; echo "<BR>Attribute Value is :".$att->value; $attr_name = $att->name; $attr_value = '"' . $att->value . '"'; $nodename->removeAttributeNode('$attr_name'); $nodename->setAttributeNode(new DOMAttr('$attr_name', '$attr_value')); } $xml->save('temp1.xml'); } ?> |