PHP - Include Inside Of Sql Data Being Echoed In
Ok I am not sure if this is possible but I hope someone out there can show me a way. I have a webpage with left content boxes that are looped in depending on the sql info. In one of the boxes the content of the box is going to be another page being pulled in. Now normally I would just put in the include ("page"); but its inside of an echo so you would end the echo do the include and then start the echo back up, however in this case its pulling in the coding from a variable so im a bit lost as to what to do now.
The page would have something like... Code: [Select] echo ' '.html_entity_decode(stripslashes($info[content])).' '; and the info content part is Code: [Select] include("pages/paypalbox.php") I've tried making the variable Code: [Select] '; include("pages/paypalbox.php"); echo' Hoping that would fix it but I should of known better, the variable is being pulled in so its not processing it as part of the first step coding and it isn't going to do anything other then print it out like text. So is there a way to make this work? Thanks. Similar TutorialsCanI put one INCLUDE statement INSIDE of another INCLUDE statement? Hi Still a new comer when it comes to PHP. I have a situation where I want to use an include within an include and I am having trouble with my file paths. My main header include, includes everything for each page of my site, beyond the opening of the body to incorporate my navigation etc conditionally loading in css, and loading in titles and meta data etc depending on the page in question. This header needs to reference another include called the-pod.php which is required for every page, the only trouble is I want to use / to reference the root of the server and this is breaking my code. I can't use ../../ etc as its a different path depending on where the master file is located. So my question is how do I get around this? Can the root of the server or path to the root be stored in a variable? and if so how would I write this. Any tips / advice will be greatly appreciated. Hi Guys.. Merry Christmas Im kinda new to this fantastic world of PHP and i have a little problem i hope you can help me with. Im trying to build a website where I use include() to genereate my content. On my index.php i have a menu which includes content in a content div from external .php pages, my structure kinda goes like this.. (simplified) site/ index.php content/ fronpage.php products.php contact.php The HTML looks like this. <div id="menu"> <ul> <li><a href="index.php?page=frontpage">frontpage</a></li> <li><a href="index.php?page=products">frontpage</a></li> <li><a href="index.php?page=contact">frontpage</a></li> </ul> </div <div id="main"> <?php include('/content/'.$_GET['page'].'.php'); ?> </div> This all works very fine, but my problem is, can I have a include inside an already included page? I would like to have a menu on my products.php site, but that page is already included from above, and i would like the menu on the products.php site to stay as the content from the nested include changes with input from the /products folder. my idea was something like this. site/ index.php content/ frontpage.php products.php contact.php products/ product1.php product2.php the HTML on the index.php is the same as above and then i would add the include() on the products.php page, so its kinda the same thing, but one inside the other. HTML inside the products.php folder <div id="sub_menu"> <ul> <li><a href="#">frontpage</a></li> <li><a href="#">frontpage</a></li> <li><a href="#">frontpage</a></li> </ul> </div <div id="sub_main"> <?php include('/content/products'.$_GET['#'].'.php'); ?> </div> I dont know how to link to the new files so they will be included while the first include still stays on the page. Any of you know how and if this can be done? Or maybe at better way to do it? Hope this made sense, my first PHP question Thanks Is there any way to do this? My image is not appearing below. The text, "we are sorry..." is appearing... Code: [Select] if(!isset($_POST['comments'])) { died('<img src="images/head/head_error.gif"/><br>We are sorry, but there appears to be a problem with the form you submitted.'); } I am trying to pass a variable from inside of a function in a file that is included eg include.php Code: [Select] <? function noms(){ $foobar = "apples"; } ?> main.php Code: [Select] <? include("include.php"); noms(); echo "these ". $foobar. " are most delicious... OM NOM NOM"; ?> I am essentially using a include file for a mysql connection and based on the connection outcome i am either setting a value to true or false. It prints "Connected succesfully" and what not just fine, but, after that it wont pass on the variables data. I know its the function because, it passes the data if i put the variable before the function... i just dont get it.. any help would be great. Thanks. Ansel So I'm kind of new to PHP, and have been having lots of success, but I have no idea why this is occuring. It's probably a super easy answer...
I have a form that has checkboxes. Essentially I am echoing out the results of which ever checkboxes the user checks. Here's my code...
if(!empty($_POST[$i])){ foreach($_POST[$i] as $check){ $answer .= $check; } echo $answer;And the result that is echoed out says this.. ArraySF6Nitrogen (SF6 is one of the checkboxes that was selected, and Nitrogen is the other checkbox that was selected) I would be incredibly happy if the echoed out result just said SF6Nitrogen My question is why does it say "Array" first? Edited by trevzilla, 05 November 2014 - 01:26 PM. I echoed the query once and it came up as UPDATE `fields` SET `enabled` = 'True' WHERE `ID` = ''good Not sure why. Code: [Select] <?php // Include the database page include ('../inc/dbconfig.php'); $styleID = $_GET['id']; $query = "SELECT fields.ID, fields.fullName, fields.enabled FROM fields INNER JOIN styles ON styles.ID = fields.styleID WHERE styles.ID = '" . $styleID . "'"; $result = mysqli_query ( $dbc, $query ); // Run The Query ?> <script> $(document).ready(function() { $('div.message-error').hide(); $('div.message-success').hide(); $("#bioConfigForm").submit(function() { $('div.message-error').hide(); var data = $(this).serialize() + "&submitBioFields=True"; $.ajax({ type: "POST", url: "processes/bioconfig.php", data: data, success: function() { $('div.message-error').hide(); $("div.message-success").html("<h6>Operation successful</h6><p>Bio fields saved successfully.</p>"); $("div.message-success").show().delay(10000).hide("slow", function() { $('#content').load('mods/bioconfiguration.php'); }); } }); return false; }); }); </script> <!-- Title --> <div id="title" class="b2"> <h2>Bio Configuration</h2> <!-- TitleActions --> <div id="titleActions"> <!-- ListSearch --> <div class="listSearch actionBlock"> <div class="search"> <label for="search">Recherche</label> <input type="text" name="search" id="search" class="text" /> </div> <div class="submit"> <button type="submit" id="search-button" class="button"><strong><img src="img/icons/search_48.png" alt="comments" class="icon "/></strong></button> </div> </div> <!-- /ListSearch --> </div> <!-- /TitleActions --> </div> <!-- Title --> <!-- Inner Content --> <div id="innerContent"> <!-- Form --> <form action="#" id="bioConfigForm" > <fieldset> <legend>Bio Config</legend> <?php while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { ?> <div class="field"> <label for="<?php '' . $row['ID'] . '' ?>"><?php echo '' . $row['fullName'] . ''?></label> <input type="radio" value="0" name="<?php echo $row['ID']; ?>" class="status" <?php if($row['enabled'] == 0) echo ' checked="checked"'; ?> />Enabled <input type="radio" value="1" name="<?php echo $row['ID']; ?>" class="status" <?php if($row['enabled'] == 1) echo ' checked="checked"'; ?> />Disabled </div> <?php } ?> <input type="submit" class="submit" name="submitBioFields" id="SubmitBioFields" title="Submit Bio Fields" value="Submit Bio Fields"/> </fieldset> </form> <!-- /Form --> Code: [Select] <?php // Include the database page require ('../inc/dbconfig.php'); if (isset($_POST['submitBioFields'])) { foreach($_POST as $bioFieldID => $value) { $query = "UPDATE `fields` SET `enabled` = '".$value."' WHERE `ID` = '".$biofieldID."'"; } mysqli_query($dbc,$query); $result = "good"; } else { $result = "bad"; } //Output the result echo $result; ?> Ok, here's what I'm trying to do. In Zend, you can modify a template title for a page within the actual template file even though the title has already been set. So, say I have this in a common header file: Code: [Select] <?php echo $title; ?> ..but I then want to maybe change that within my main template page, say my 'about' page. How would I go about that? Currently I do this: include($commonheader); include($content); include($footer); It's in the content where I want to be able to change the title in the header, should I need to. You can do this with Zend but it's beyond me how they do it. Should note, the above is for simplicity sake. I am doing this using OOP methods. Any help appreciated. Maybe ob_flush? Hey there I've adapted the search code from the tutorial on this site here http://www.phpfreaks.com/tutorial/simple-sql-search for a project I've been working on but have an error. The search works just fine but if either of the messages I've included are tripped (zero search characters or nothing found) then I get a blank screen and the error message is not echoed. (The vanilla code works fine - the error has arisen through the changes I needed to make). I don't know why this is happening and would appreciate some help please. Thanks in advance for any help. Code: [Select] session_start(); // check session variable if (isset($_SESSION['first_name'])) { include ('includes/header_loggedin.html'); //db connection info deleted $error = array(); //get search term, strip it if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 1) { $error[] = 'Search terms must be longer than 1 character.'; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } //formulate query if (count($error) < 1) { $query = "SELECT * FROM table WHERE row LIKE '%{$searchTermDB}%'"; //make the query $result = mysql_query($query) or die(mysql_error()); //display the results if (mysql_num_rows($result) < 1) { $error[] = "Your search term yielded no results."; } else { while ($endresult = mysql_fetch_array($result)) { echo '<br />'; echo 'This is what we found'; echo '<br />'; echo '<a href="newpage.php?w=' . $endresult['row'] . '">' . $endresult['row'] . '</a>'; } } } } } This has been bothering me for a while, how do I do this? echo (" <form method = 'get' action = 'member.php?action=Search&option=faction&name=NAME'> Faction's Name: <input type='text' name='member' /><br /><br /> <input type='submit' value='Search' /> </form> "); name='member' is supposed to be sent with he member.php?action=Search&option=faction&name=NAME. Obviously replacing NAME with the input. I thought this would be fairly straightforward but for some reason isn't working. I have an array built from some MySQL data: - Code: [Select] $all_products[1] = array( "title"=>"widget", "product_code"=>"wid-123", "colour"=>"blue"); $all_products[2] = array( "title"=>"thingy", "product_code"=>"thi-345", "colour"=>"red"); This works fine when used like: - echo 'Product #1 is a ' . $all_products[1]['colour'] . $all_products[1]['title'] . ', code: ' . $all_products[1]['code']; Gives: "Product #1 is a blue widget, code: wid-123" However, if I do this: - function showproductinfo($thisproduct) { echo 'Product #' . $thisproduct . ' is a ' . $all_products[$thisproduct]['colour'] . $all_products[$thisproduct]['title'] . ', code: ' . $all_products[$thisproduct]['code']; } showproductinfo(1); It gives nothing Can I use a variable passed via a function as the array key in this way? If so, how? And if not, what's the best way to do what I, trying to do? Hey there guys, small problem here that I can't seem to figure out. I am in the process of programming a database with user-access control. I have the log-in system working great, but the logout link, which is located next to the logged-in username seems to not be echoing correctly. It is loading the 'Logout' text in text-form only, not link-form.... Any ideas on what may be causing this small glitch?? Thanks!! I have attached relevant code for said part for reference. <img src="images/username.png" height="20" width="20"> <b>Welcome</b> <?php echo ("<font color=#9e0219>$username</font>");?>, <?php echo '<a href="logout.php">Logout</a>';?> So I filled out my edit form and I had it echo the query and it said exactly what it was supposed to but it didn't update it. Here's what the echo query looked like. UPDATE `efed_list_menu_items` SET `content_id`='0', `newscat`='0', `application_id`='1', `itemname`='Testing 3', `itemurl`='testing3.php', `sortorder`='3' WHERE `id` = '3' Hi, I have a (probably quite simple) question about passing form data to a php script that contains an iframe with another php script that also needs some of this form data. Basically, my problem is as follows: I have the following code in a file called example1.php: Code: [Select] <html> //some html stuff <?php if(isset($_POST['from'])) {$from1 = $_POST['from'];} else {$from1 = 'English';} $langList = array('English', 'French', 'German', 'Dutch'); print('<select id="from" name="from">'); foreach ($langList as $lang) {printf('<option %s>%s</option>', ($from1 == $lang ? 'selected="selected"' : ''), $lang); } echo '</select>'; ?> //some more html stuff </html> As you can see, it retrieves a variable via POST and selects its value from a list. The variable is posted from an html file (example0.htm) containing the following: Code: [Select] <form method="post" action="example1.php"> This worked fine, until I put example1.php inside an iframe in example2.php as follows: Code: [Select] <html> //some html here <?php //some php here ?> <iframe src ='example1.php' id='something' name='something' > </iframe> </html> and changed: "post" action="example2.php" in my html form. My question is: how do I pass form data from example0.htm to example2.php to example1.php, so that example2.php gets loaded when the submit button on my form gets pressed, but so that example1.php (which gets loaded from the iframe in example2.php) can also access the form data? Thanks! Hi there im having trouble with my code and was hoping someone may be able to help me? I think the trouble i am having is because i am echoing the form elements (form, hidden) and the value in those elements. This part is fine i think: Code: [Select] $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")){ $insertSQL = sprintf("INSERT INTO ships (ShipName, FleetID, PlayerName, Image1, Image2, Credits, HealthA, HealthB, MaxHealthA, MaxHealthB, Class, Hyperspace, PlanetID, Building, Maintenance) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['shipname1'], "text"), GetSQLValueString($_POST['fleetid1'], "int"), GetSQLValueString($_POST['playername1'], "text"), GetSQLValueString($_POST['image11'], "text"), GetSQLValueString($_POST['image21'], "text"), GetSQLValueString($_POST['credits1'], "int"), GetSQLValueString($_POST['healtha1'], "int"), GetSQLValueString($_POST['healthb1'], "int"), GetSQLValueString($_POST['maxhealtha1'], "int"), GetSQLValueString($_POST['maxhealthb1'], "int"), GetSQLValueString($_POST['class1'], "int"), GetSQLValueString($_POST['hyperspace1'], "int"), GetSQLValueString($_POST['planetid1'], "int"), GetSQLValueString($_POST['building1'], "int"), GetSQLValueString($_POST['maintenance1'], "int")); mysql_select_db($database_swb, $swb); $Result1 = mysql_query($insertSQL, $swb) or die(mysql_error()); $insertGoTo = "planet.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } The problem may lay he Code: [Select] <?php echo'<form id="form1" name="form1" method="post" action="">';echo'<table width="400" border="0" align="top">'; do { echo '<tr> <td width="200" align="center">'; echo '<span class="arial12">'; echo "<img src=".$row_Ships["Image1"]." height =\"250\" width=\"400\">"; echo'| Maintenance: '; echo $row_Ships['Maintenance'];echo ' | '; echo'<input type="submit" name="Submit" value="Build" />'; echo' | Construction Time: '; echo $row_Ships['Building']; echo' | ';echo '</td></tr>'; echo" <input name='fleetid1' type='hidden' id='fleetid1' value='".$totalRows_Fleet." + '1''/>"; echo" <input name='fleetname1' type='hidden' id='fleetname1' value='Fleet ".$totalRows_Fleet." + '1''/>"; echo" <input name='shipname1' type='hidden' id='shipname1' value='".$row_Ships['ShipName']."'/>"; echo" <input name='playername1' type='hidden' id='playername1' value='".$_SESSION['MM_Username']."'/>"; echo" <input name='credits1' type='hidden' id='credits1' value='".$row_Ships['Credits']."'/>"; echo" <input name='image11' type='hidden' id='image11' value='".$row_Ships['Image1']."'/>"; echo" <input name='image21' type='hidden' id='image21' value='".$row_Ships['Image2']."'/>"; echo" <input name='healtha1' type='hidden' id='healtha1' value='".$row_Ships['HealthA']."'/>"; echo" <input name='healthb1' type='hidden' id='healthb1' value='".$row_Ships['HealthB']."'/>"; echo" <input name='maxhealtha1' type='hidden' id='maxhealtha1' value='".$row_Ships['MaxHealthA']."'/>"; echo" <input name='maxhealthb1' type='hidden' id='maxhealthb1' value='".$row_Ships['MaxHealthB']."'/>"; echo" <input name='class1' type='hidden' id='class1' value='".$row_Ships['Class']."'/>"; echo" <input name='hyperspace1' type='hidden' id='hyperspace1' value='".$row_Ships['Hyperspace']."'/>"; echo" <input name='maintenance1' type='hidden' id='maintenance1' value='".$row_Ships['Maintenance']."'/>"; echo" <input name='Planetid1' type='hidden' id='planetid1' value='".$row_Credits['PlanetID']."'/>"; echo" <input name='building1' type='hidden' id='building1' value='".$row_Ships['Building']."'/>"; } while ($row_Ships = mysql_fetch_assoc($Ships)); echo '</table></form>';?> No records are insterted at all?? The page redirection after insert is not happening either. If anybody coould help that would be brilliant... Thank You Hello all, What I'm trying to do is insert dynamic data supplied by the user into an array, but for some reason, the loop only builds arrays inside of arrays (or so it seems) and doesn't create an array with unique indexes and associated data. I was hoping someone could point me in the right path? I've searched numerous forums, threads and google but cannot find an answer. Here is the code snippet I'm working on. What it's supposed to do is collect a user's input, which is a Quantity amount and a high number, and based on that amount, create an array of random integers. This is my latest attempt. Now, maybe I'm just losing it, but when I place print_r($output) inside the loop, I see how it's being created but no unique indexes, just nested arrays. When I place it outside of the loop, I only receive one array with one index and value even though a high quantity was sent to the script. Code: [Select] $i = 1; while ($i <= $Quantity){ $output = array(rand($RandLow, $RandHigh)); $i++; } print_r($output); Here is another attempt, which again proved to be unsuccessful, at least to my tire brain. Code: [Select] $i = 1; while ($i <= $Quantity){ $output = rand($RandLow, $RandHigh); $total = array($output); $i++; } print_r($total); I've tried the for() loop as well but I just can't seem to make heads or tails of this and I'm sure it's going to be something simple that I'm missing. Thanks in advance for any help and insight if you know a better way to do this. I have a php file that generates a string that I need to use in a .js (javascript)file. Being that php developers sometimes using javascript with php, Im hoping someone can help me with this, cause i dont know any javascript. Code: [Select] //This is the varible inside the .js file var suggestionText = "I need to be able to include my string generated by the php file here..."; when I send a post variable to another page for processing using cURL and then I echo the variable I am getting extra slashes and periods this is where I set the fields to send. Code: [Select] curl_setopt($ch, CURLOPT_POSTFIELDS,"name='. $name .'&email='. $email .'&serial='. $serialnumber .'"); this is what happens when I echo $serial on the processing page. Code: [Select] \'. SLNM7IV6ZM98YJRXO8D5 .\' it should look like Code: [Select] SLNM7IV6ZM98YJRXO8D5 Hi, I have a connection set up to an API using a PHP script - the API sends back data in JSON format, and if I capture it and echo it, it displays in extremely unfriendly format on the screen. I've tried to find a way to convert this data into readable format, ideally in a HTML table, but although there are articles on converting manually inputted JSON data into a HTML table using Javascript, I can't find a way to do it from a PHP variable. This is what I have so far: if ($_POST['getcompany']) { $companyname = $_POST['_Name']; $ch = curl_init(); $data_array2 = array( 'token' => $token ); $make_call2 = json_encode($data_array2); //echo 'Token is '.$token; $token2 = substr($token, 14); $token3 = substr($token2, 0, -3); //echo 'Token 2 is '.$token3; //echo 'Company Name is '.$companyname; //curl_setopt($ch, CURLOPT_GET, 1); //curl_setopt($ch, CURLOPT_POSTFIELDS, $make_call2); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Authorization: '.$token3.'')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, 'https://connectionurl?countries=GB&name='.$companyname); //Execute the request $result = curl_exec($ch); echo 'Companies: '.$result; //This displays the data provided by the search, but is in JSON format
So I need a way to get the data held in $result, into a HTML table. Any idea how I can do this? 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? |