PHP - Please Someone Help Me Im About To Go Insane.... Php Is Doing My Head In
first i have a standard html page. Just a form that submits data to upload.php
http://pixel.imgboard.co.uk here is upload.php - note i know i have some weird echo's but ive been trying for 2 hours to get upload.php to display something... but nothing happens.. i cant even get it to output html. It just goes to upload.php and has a blank page. When i view source there is nothing there. Its literally a blank page. I can't work it out. someone please help. I'm going to crack up. <?php ini_set("display_errors", "1"); error_reporting(E_ALL); session_start(); include 'http://www.imgboard.co.uk/includes/functions.php'; $start = " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html> <head> <link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.imgboard.co.uk/style/pixel.css\" /> <title> Pixel - Image Hosting Beta</title> </head> <body> <div id =\"wrapper\"> <div class = 'titlebar'> <div class = 'titlebarlinkbox'> <a href = 'http://www.imgboard.co.uk'>Forum</a> <a href = 'http://www.imgboard.co.uk/Wiki.php'>Wikis</a> <a href = 'http://www.imgboard.co.uk/bulletins/0'>Bulletins</a> <a href = 'http://www.imgboard.co.uk/faq/0'>Faq's</a> </div> </div> <div class = \"logo\"></div> "; $end = " <div class = 'footerLinks'> Pixel @ 2010 - 2015 ! <br /> <a href = 'http://www.imgboard.co.uk'>Forum</a> | <a href = 'http://www.imgboard.co.uk/Wiki.php'>Wikis</a> | <a href = 'http://www.imgboard.co.uk/bulletins/0'>Bulletins</a> | <a href = 'http://www.imgboard.co.uk/faq/0'>Faq's</a> | <a href = 'http://www.imgboard.co.uk/pixel/report.php'>Report Image</a> </div> <div class = 'TnC'>Pixel is a Trademark of imgboard.co.uk. Please ensure all content uploaded is decent. No Taboo, cp, gore allowed. Porn / memes / misc themes all welcome. Any offensive content will be removed and deleted. Any misuse of the service and result in banning and in seviere cases prosecution.</div> </div> </body> </html> "; if(isset($_GET['uploadfile'])){ echo $start; echo $end; $validExtensions = array("png", "gif", "jpeg", "jpg", "bmp"); $ext = end(explode(".",$_FILES["image"]["name"])); $ext2= strtolower($ext); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/bmp") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 10000000)) && in_array($ext2,$validExtensions)) { //create a unique name. $newname = date(dmYhis); $newname .= rand(1111,9999); //preg replace non alpha numeric characters $fname = $_FILES['file']['name']; $newname = $newname . "." .$ext2; $location = "http://www.imgboard.co.uk/images/".$newname; //copy the file. if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){ //file uploaded create display Page. $t = $_POST['tags']; add_uploaded_image($location,$t); file_upload_display_page($location); } else{ die("Error Occured Moving File"); } } else{ die("wrong mime type"); } } function add_uploaded_image($link, $tags){ $c = protect($_COOKIE['supercookie']); $ip = $_SERVER['REMOTE_ADDR']; $t = protect($tags); mysql_query("INSERT INTO pixel (filename,tags,date,ip,cookie) VALUES ('$link','$t',NOW(),'$ip','$c')") or die(mysql_error()); } function file_upload_display_page($location){ echo " <table class = 'uploadTable' cellspacing = '0'> <tr> <td class = \"label\"> Image Uploaded: </td><td><img src = '$location' HEIGHT = '150'/> </td> </tr> <tr> <td class = \"label\"> Direct Link: </td><td><input type = 'text' name = 'file' id = 'file' value = '$location'/> </td> </tr> <tr> <td class = \"label\"> Html Code </td><td><input type = 'text' name = 'tags' value = \"<img src = '$location' ALT = 'Hosted On http://Pixel.imgboard.co.uk'/>\"/> </td> </tr> <tr> <td> <td class = \"label\"> BB Code: </td><td><input type = 'text' name = 'file' id = 'file' value = '[img]http://$location[/img]'/> </td> </td> </tr> </table> "; } Similar TutorialsThis topic has been moved to PHP Regex, where it should have been posted in the first place. http://www.phpfreaks.com/forums/index.php?topic=355176.0 Hi guys, I am going nuts with this! It HAS to be something dead simple but I can't seem to see what is staring me in the face. Basically I have made a registration form and when complete you are emailed a link to click on. When you click on the link you go to a new page. The page takes the email address and the verification code from the URL via _GET. The database is then queried for a match of the email address AND the verification code, if there is a relevant record then success is displayed otherwise unsuccessful is displayed. Code: Code: [Select] $email = strip_tags(htmlentities($_GET['email'])); $code = strip_tags(htmlentities($_GET['code'])); // confirm the variables hold the correct data echo "email: $email and code: $code"; $query = "SELECT * from userdb WHERE email='$email' AND code ='$code'"; if (mysql_query($query)) { echo "success"; } else { echo "unsuccessful"; } My problem is this query is always returning 'success'... even when the code and/or email does not match what is in my database? What am i missing? Thanks I'm writing a very simple clean login session as a demonstration to friends. I've been over this code a lot of times and can't fault it, but obviously I am wrong.. or maybe xampp is just having one of those days. Undefined Index: username on line 30, login.php all files involved are attached. Thanks in advance. Code: [Select] <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect("localhost","root","") or die("couldn't connect"); mysql_select_db("login") or die("couldn't find db"); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { //login code while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } //check is pass & user match if ($username==$dbusername&&$password==$dbpassword) { echo "you're in click here to enter the <a href='member.php'>member page</a> haha"; $_SESSION['username']==$dbusername; } else echo "incorrect password"; } else die("that user doesn't exist"); } else die("failed to connect") ?> I want to have a form with a drop down menu that decides who gets the email. But I ALSO want the email to go to me. Can anyone tell me the simplest way to go about this? This is my form page: Code: [Select] <form method="post" action="sendorderform.php"> Email: <input name="email" type="text" /><br /> Message:<br /> <textarea name="message" rows="15" cols="40"> </textarea><br /> <select name='emailto' id='emailto'> <option value='me@yahoo.com'>man1@website.com</option> <option value='man2@website.com'>man2@website.com</option> <option value='man3@website.com'>man3@website.com</option> <option value='man4@website.com'>man4@website.com</option> </select><br> <input type="submit" /> </form> This is my php page: Code: [Select] <?php $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $email_to = $_POST['emailto'] ; mail( $email_to, "Feedback Form Results", $message, "From: $email" ); ?> I actually got this to send per the drop down. But, where do I put MY (fixed) email address to make it send TWO emails? Thanks for any help!!! I'm very new at this stuff. I don't know who did this or why this was implemented, but it was the worst decision PHP made as it causes nothing but problems. Not having to define variables was one of the reasons I liked PHP. This is just my opinion so no roasts. Question is, what is the proper way to do this so I don't get this message 'cause I am hit and miss, even when I think I have them defined this stupid message pops up. This is the 3rd line on the on script that is causing me grief at the moment: $submit = $populate = $record = $row[] = $hid = $uid = $asset_tag = $type = $manufacturer = $model = $serial_number = $status = $location = $firstname = $lastname = $go = ""; Not sure why I need to have $row[] as it is the result of a SELECT and values are being given to it. Also not sure why I need it for $submit or $_POST as they already have values when they are passed to this page, so how can they be undefined when they have values. Just not getting it. Any help with this would really be appreciated. Thanks Ok, so I've read a few tutorials of OOP and have a basic understanding of how it works but where is it generally handy? I have a basic site created with PHP that consists of a form that submits data to MySQL and then lists the data from the MySQL database on another page. Kind of like a little online planner. I don't see how me converting my site to use OOP would help here. Maybe it's best for more complex situations such as a shopping cart where data needs to be shared across multiple pages? Hi All, I am trying to use headers at the end of functions to put the user where they need to be. header("location: register.php?user_may_exist"); I understand how they work and their qwuirks. My issue is, in my head file, i am outputting which causes issues for the headers which come after. I have the following in head.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> <?php if(isset($currentPageTitle)){ echo $currentPageTitle; }else{ echo 'Cricket Club'; }; ?> </title> <?php if(isset($currentPageMeta)){ echo "<meta name='description' content='$currentPageMeta'>"; }else{ echo "<meta name='description' content='All the latest from CC'>"; }; ?> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> Is there a better way for me to achieve this? hey guys how you doing? I've been having a little bit of problem with php, in fact I'm frustrated, so please if you can help me in any tight of way, please do, I've been trying to make this php code work, but it won't, i don't know what I'm doing wrong, I'm new to php and mysql every time i try it, it saids one thing Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\siteN\approvescore.php:3) in C:\xampp\htdocs\siteN\authorize.php on line 17 <?php require_once ('authorize.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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Guitar Wars - Approve a High Score</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2>Guitar Wars - Approve a High Score</h2> <?php require_once('appvars.php'); require_once('connectvars.php'); if (isset($_GET['id']) && isset($_GET['date']) && isset($_GET['name']) && isset($_GET['score'])) { // Grab the score data from the GET $id = $_GET['id']; $date = $_GET['date']; $name = $_GET['name']; $score = $_GET['score']; $screenshot = $_GET['screenshot']; } else if (isset($_POST['id']) && isset($_POST['name']) && isset($_POST['score'])) { // Grab the score data from the POST $id = $_POST['id']; $name = $_POST['name']; $score = $_POST['score']; } else { echo '<p class="error">Sorry, no high score was specified for approval.</p>'; } if (isset($_POST['submit'])) { if ($_POST['confirm'] == 'Yes') { // Connect to the database $dbc = mysqli_connect('localhost', '999', 'adsd', 'guitarwars3'); // Approve the score by setting the approved column in the database $query = "UPDATE gtwars1 SET approved = 1 WHERE id = $id"; mysqli_query($dbc, $query); mysqli_close($dbc); // Confirm success with the user echo '<p>The high score of ' . $score . ' for ' . $name . ' was successfully approved.'; } else { echo '<p class="error">Sorry, there was a problem approving the high score.</p>'; } } else if (isset($id) && isset($name) && isset($date) && isset($score)) { echo '<p>Are you sure you want to approve the following high score?</p>'; echo '<p><strong>Name: </strong>' . $name . '<br /><strong>Date: </strong>' . $date . '<br /><strong>Sco </strong>' . $score . '</p>'; echo '<form method="post" action="approvescore.php">'; echo '<img src="' . GW_UPLOADPATH . $screenshot . '" width="160" alt="Score image" /><br />'; echo '<input type="radio" name="confirm" value="Yes" /> Yes '; echo '<input type="radio" name="confirm" value="No" checked="checked" /> No <br />'; echo '<input type="submit" value="Submit" name="submit" />'; echo '<input type="hidden" name="id" value="' . $id . '" />'; echo '<input type="hidden" name="name" value="' . $name . '" />'; echo '<input type="hidden" name="score" value="' . $score . '" />'; echo '</form>'; } echo '<p><a href="admin.php"><< Back to admin page</a></p>'; ?> how you doing guys. I'm having a little bit of a problem right now, with this thing call view-profile.php, i hope you guys know what it is, I'm new to php, so please try to help. it says the same thing everytime. Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\siteS\viewprofile.php on line 26 There was a problem accessing your profile <h3>Mismatch - View Profile</h3> <?php require_once('appvars.php'); require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect('localhost', '***', '*****', '*****'); // Grab the profile data from the database if (!isset($_GET['user_id'])) { $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture FROM mismatch_user WHERE user_id = '$user_id'"; } else { $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture FROM mismatch_user WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query); line26-----------> if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo '<table>'; if (!empty($row['username'])) { echo '<tr><td class="label">Username:</td><td>' . $row['username'] . '</td></tr>'; } if (!empty($row['first_name'])) { echo '<tr><td class="label">First name:</td><td>' . $row['first_name'] . '</td></tr>'; } if (!empty($row['last_name'])) { echo '<tr><td class="label">Last name:</td><td>' . $row['last_name'] . '</td></tr>'; } if (!empty($row['gender'])) { echo '<tr><td class="label">Gender:</td><td>'; if ($row['gender'] == 'M') { echo 'Male'; } else if ($row['gender'] == 'F') { echo 'Female'; } else { echo '?'; } echo '</td></tr>'; } if (!empty($row['birthdate'])) { if (!isset($_GET['user_id']) || ($user_id == $_GET['user_id'])) { // Show the user their own birthdate echo '<tr><td class="label">Birthdate:</td><td>' . $row['birthdate'] . '</td></tr>'; } else { // Show only the birth year for everyone else list($year, $month, $day) = explode('-', $row['birthdate']); echo '<tr><td class="label">Year born:</td><td>' . $year . '</td></tr>'; } } if (!empty($row['city']) || !empty($row['state'])) { echo '<tr><td class="label">Location:</td><td>' . $row['city'] . ', ' . $row['state'] . '</td></tr>'; } if (!empty($row['picture'])) { echo '<tr><td class="label">Pictu </td><td><img src="' . MM_UPLOADPATH . $row['picture'] . '" alt="Profile Picture" /></td></tr>'; } echo '</table>'; if (!isset($_GET['user_id']) || ($user_id == $_GET['user_id'])) { echo '<p>Would you like to <a href="editprofile.php">edit your profile</a>?</p>'; } } // End of check for a single row of user results else { echo '<p class="error">There was a problem accessing your profile.</p>'; } mysqli_close($dbc); ?> It's not usual I ask questions on here - I usually help rather than be helped but alas, this is really confusing ! Short Story (You can skip this to "Your Mission") Without going into unnecessary detail i'll try to explain what i'm trying to do; Take an array (example provided...) Array( // These must be here, they are initially read by the template parser to get a starting point. "data"=>Array( "template"=>"main", // Template to start from (base template) "content"=>"%custom_topmenu% <Br/>Table<Br/> %bigtablecustom1%", // replace %content% tag,Shows 2 Examples, A Custom Menu, and Main Table with Smaller Tables inside ), // Below is numerically indexed arrays of content that will replace tags in the above "content" item 0=>Array( "data"=>Array( "rkey"=>"%bigtablecustom1%", // MUST have this item "template"=>"bigtable_single", // MUST have this item 0=>Array( "%title%"=>"Some Table Heading", "%footer%"=>"Some Table Footer Message (author?)", "%content%"=>"Some Content for the table with another rkey: %smalltablecustom1% --- %smalltablecustom2%", "%title_note%"=>"Some Time and Date" ) ), 0=>Array( "data"=>Array( "rkey"=>"%smalltablecustom1%", "template"=>"smalltable_single", 0=>Array( "%title%"=>"Small Title", "%content%"=>"Some Small Content or Note" ) ) ), 1=>Array( "data"=>Array( "rkey"=>"%smalltablecustom2%", "template"=>"smalltable_single", 0=>Array( "%title%"=>"Small Title 2", "%content%"=>"Some Small Content or Note" ) ) ) ) 1=>Array( // The menu is dynamically created by the module using it's inherited protected methods. "data"=>Array( "rkey"=>"%custom_topmenu%", "template"=>"custom_topmenu", 0=>Array( "%item1_name%"=>"Sub-Link 1", "%item1_link%"=>"#", "%item2_name%"=>"Sub-Link 2", "%item2_link%"=>"#", "%item3_name%"=>"Sub-Link 3", "%item3_link%"=>"#", "%item4_name%"=>"Sub-Link 4", "%item4_link%"=>"#" ) ) ) ) Turn this array into a single document, basically collpase all items with their children in the parent code. The Problem (You can skip this to "Your Mission") Now to make it easier and to (try) to prevent cross-tag contamination (so templates dont replace content that is supposed to be there from other template files...) I have wrote a recursion function that fills out all the content and removes the content sub-array from the data arrays (half the job). So now I have a multi-dimensional array that needs collapsing into a single document (variable), I am getting confused with how to go through this array (below - not above) so that all the template items are "inserted" inside their parent array items. The Function I made // Recursive, goes through an array and converts any "data" into actual templates. (Puts the content into a template) private function parse_template_data_array($array){ // First let's count how many items are in the array that was passed to us $item_count = count($array); // This should never happen, each array should have at least a "data" array inside. if($item_count < 1){ // Template Parser Fatal Object Syntax Error exit("FATAL PARSER ERROR1"); // If there is only one item, we don't need to recurse (There are no "child" elements) and so we skip the recursive section. }else if($item_count == 1){ // No items to parse, move on // So there are some child elements we must recurse through. }else{ // So this loops each "Child" element and passes that array to this function (recurse), Once it's finished it saves the array (result). for($i=0;$i<($item_count-1);$i++){ // -1 from the count, 1 to get rid of the data array. $array[$i] = $this->parse_template_data_array($array[$i]); } } // This part does the initial "template expansion", it finds the template needed for this item and saves it with the content to this item. // So we count how many data items we have $dcount = count($array['data']); // Count Data Items (minimum of 2 - Each data array must have "rkey" and "template") // If there isn't at least two items then someone made a booboo. if($dcount < 2){ // Template Parser Fatal Object Syntax Error exit("FATAL PARSER ERROR2"); // Otherwise let's sort this content out (We don't check if we only have the 2 minimum items since templates might not have Tags to replace). }else{ // Load Template file using the "template" item in the data array. $template = $this->get_file($array['data']['template']); // Count the amount of data items (content) to replace tags inside the loaded template (If there is no content sub-array then put to 0 to skip the below part). $dstrcount = (isset($array['data'][0]))? count($array['data'][0]) : 0; // No template content, maybe no tags, just give the template content back. if($dstrcount < 1){ // No items to parse // We have some content to replace. }else{ // We need the keys of the content sub-array so we can use (a neat feature of) the str_replace function. $akeys = array_keys($array['data'][0]); $template = str_replace($akeys ,$array['data'][0],$template); } // Save the result into this array item so we can pass the whole item back (This is also what happens when it recurses above) $array['data']['content'] = $template; } // Return the result array. return $array; } The Array returned by the above function Array ( [data] => Array ( [rkey] => %cdb_res_tpl_blk% [template] => main [content] => <html><head></head><body>%custom_topmenu%<br />%bigtablecustom1%</body></html> ) [0] => Array ( [data] => Array ( [rkey] => %bigtablecustom1% [template] => bigtable_single [content] => "Some Table Heading"=>"Some Table Heading", "Some Table Footer Message (author?)"=>"Some Table Footer Message (author?)", "Some Content for the table with another rkey: %smalltablecustom1% --- %smalltablecustom2%"=>"Some Content for the table with another rkey: %smalltablecustom1% --- %smalltablecustom2%", "Some Time and Date"=>"Some Time and Date" ) [0] => Array ( [data] => Array ( [rkey] => %smalltablecustom1% [template] => smalltable_single [content] => "Small Title"=>"Small Title", "Some Small Content or Note"=>"Some Small Content or Note" ) ) [1] => Array ( [data] => Array ( [rkey] => %smalltablecustom2% [template] => smalltable_single [content] => "Small Title 2"=>"Small Title", "Some Small Content or Note"=>"Some Small Content or Note" ) ) ) [1] => Array ( [data] => Array ( [rkey] => %custom_topmenu% [template] => custom_topmenu [content] => "Sub-Link 1"=>"Sub-Link 1", "#"=>"#", "Sub-Link 2"=>"Sub-Link 2", "#"=>"#", "Sub-Link 3"=>"Sub-Link 3", "#"=>"#", "Sub-Link 4"=>"Sub-Link 4", "#"=>"#" ) ) ) Your mission (Should you choose to accept ofc ), is to take the above array and turn it into a single html variable, with all the child elements inside their parent templates by replacing the tags in the array. All the data required is in the array, all that is needed is to "collapse" the array. Things to bear in mind: %cdb_res_tpl_blk% - This is in the original template file, so the result of a successfull collapse will replace this tag with the result. Dont worry about this one [rkey] - This is the "Tag" to replace in the "parent" content. [template] - This is the template file. [content] - This is the content that needs to go inside the parent item. Expected Result <html><head></head><body>"Sub-Link 1"=>"Sub-Link 1", "#"=>"#", "Sub-Link 2"=>"Sub-Link 2", "#"=>"#", "Sub-Link 3"=>"Sub-Link 3", "#"=>"#", "Sub-Link 4"=>"Sub-Link 4", "#"=>"#"<br />"Some Table Heading"=>"Some Table Heading", "Some Table Footer Message (author?)"=>"Some Table Footer Message (author?)", "Some Content for the table with another rkey: "Small Title"=>"Small Title","Some Small Content or Note"=>"Some Small Content or Note" --- "Small Title 2"=>"Small Title","Some Small Content or Note"=>"Some Small Content or Note""=>"Some Content for the table with another rkey: %smalltablecustom1% --- %smalltablecustom2%", "Some Time and Date"=>"Some Time and Date"</body></html> I will be working on this myself and if I find a solution I will post here. It is just that the way I code is I put my idea in my head, then try to code it in my head categorically, but when I think I find a solution it seems there is a bug, such as it will only collpase the main element, the bigtable, and the first small table, it wont do the other small table and not the menu either so basically it doesnt recurse items in the same array, only those underneath it. I'm so close but yet...so far... THANK YOU for ANY light you can shed on this situation it's been bugging me for a few days now (admittely have not coded since my first attempt - so tired.) My Code I won't provide the code I've done for it now since it just flat-out doesn't work, I've lost the code that I mentioned earlier that was bugged I modified and to be perfectly honest can't be bothered to reproduce it (it won't get me anywhere). My website www.staceyxsolomon.com is only loading the header of my index.PHP page The full page is there i had double checke in the FTP It happened after my host put me onto another server, all settings carried over, please can somebody advise help if this is PHP related? Are there any problems with calling an include file from within the <header> tags? The reason I'm asking is that I'm trying to load a speficied Style sheet based on a user's location and so I'm running a short script to determine which Style sheet needs to be displayed ... and that script is called from within the header tag. I haven't heard of any problems with doing this in the past, but the script seems to be generating an extra set of <HTML> tags in my source code and I can't figure out why this might be! Thanks, Hi all i provided a little code to someone in the misc thread to block users based on the user agent language as an alternative to ipaddresses. I used switch for this but the each line is executed even if my language code is different. Anyone have an idea why the switch code below is messing with me? <?php if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) ){ $languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ); // $languages = ' fr-ch;q=0.3, da, en-us;q=0.8, en;q=0.5, fr;q=0.3'; // need to remove spaces from strings to avoid error $languages = str_replace( ' ', '', $languages ); $languages = explode( ",", $languages ); // do something when you don't like the language switch ($languages[0]) { // first array item case 'ko': // korea echo "do something or set a variable"; break; case 'ru-md'||'ru': // russia echo "do something or set a variable"; break; case 'zh-cn'||'zh-hk'||'zh-mo'||'zh-sg'||'zh-tw'||'zh': // china echo "do something or set a variable"; break; case 'ne': // india echo "do something or set a variable"; break; default: echo "good"; } } ?> I changed it to a different code that uses in_array() which works, but i really would love to know why the above is not working as intended, i looked at php.net, but didn't found something nice in the comments. Maybe a guru out here that knows? <?php if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) ){ $languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ); // $languages = ' fr-ch;q=0.3, da, en-us;q=0.8, en;q=0.5, fr;q=0.3'; // need to remove spaces from strings to avoid error $languages = str_replace( ' ', '', $languages ); $languages = explode( ",", $languages ); // do something when you don't like the language $lang_array = array('ko','ru-md','ru','zh-cn','zh-hk','zh-mo','zh-sg','zh-tw','zh','ne'); if (in_array($languages[0], $lang_array)){ echo 'bad stuff'; }else{ echo 'good stuff'; } } ?> Thanks guys!! I am working on a temporary mobile site while I try and fix my main site. As I do this, I am trying to look at better ways to code. Is there any problem/danger to including the HTML Head? Since this block of code repeats - except for the < title > - I figure why code it multiple times. I was thinking of using an INCLUDE on this...
<head> <!-- METADATA --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width", height="device-height", initial-scale=1> <!-- TITLE --> <title>$title</title> <!-- STYLES --> <link type="text/css" rel="stylesheet" href="css/styles.css" /> </head>
Thoughts?
include "header.php"; if(isset($_GET['post_id'])) { $select=mysqli_query($con,"select...."); while($data=mysqli_fetch_array($select)) { echo "bla bla bla"; to_head("<title>asd</title><meta itemprop="name" content="asdfasdf">..."); } } include "footer.php";This is samthing what i want... I have header.php and footer.php and any script ex news.php where how news and read SEO stuff from database and put in HEAD of the document. I tried with jquery like $("head").append(str); and it works but then i read google don't run jquery when vist website. This is done with drupal, wordpress and php-fusion Drupal: https://api.drupal.o...add_html_head/7 php-fusion: https://www.php-fusi...thread_id=30959 so it is possible but i don't know how. Any idea? I'm trying to create a web ' order form ' basically i've been trying to miss match different guides online and im very confused! Can someone fix it so it would e-mail me the data I have a PHP enabled web host / server... all this is very new to me and its a complex form i need Thanks In advance! this is the code I have : </head> <body> <form> <form method="POST" action="thanks.php"> <table border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#3E55A7" bgcolor="#C7CFE9"> <tr> <td colspan="10" bgcolor="3e55a7" class="style9"><div align="center">CUSTOMER ORDER FORM </div> <div align="center"></div></td> </tr> <tr bordercolor="#F5F4FD" bgcolor="#C7CFE9"> <td colspan="10" bgcolor="#C7CFE9"><div align="center"></div></td> </tr> <tr bordercolor="#F5F4FD" bgcolor="#C7CFE9"> <td colspan="4" class="style17"><strong>NAME <input name="custname" type="text" class="style17" tabindex="1" size="53"> </strong></td> <td width="86"> </td> <tr bordercolor="#F5F4FD" bgcolor="#C7CFE9"> <td colspan="4" class="style17"><strong>ADDRESS<span class="style15"> <textarea name="custadd" cols="50" class="style17" tabindex="2"></textarea> </span></strong></td> <td class="style15"> </td> </tr> <tr bordercolor="#F5F4FD" bgcolor="#C7CFE9"> <td height="24" colspan="4" class="style17">TOWN<span class="style15"> <input name="custtown" type="text" class="style17" id="custtown" tabindex="3" size="53"> </span></td> <td class="style15"> </td> </tr> <tr bordercolor="#F5F4FD" bgcolor="#C7CFE9"> <td height="24" colspan="4" class="style17"><strong>POSTCODE<span class="style15"> <input name="custcode" type="text" class="style17" id="custcode" tabindex="3.5" size="53"> </span></strong></td> <td class="style15"> </td> </tr> <tr bordercolor="#F5F4FD" bgcolor="#C7CFE9"> <td height="27" colspan="4" class="style17"><strong>PHONE<span class="style15"> <input name="custphone" type="text" class="style17" id="custphone" tabindex="4" size="53"> </span></strong></td> <td class="style15"> </td> </tr> <tr bordercolor="#F5F4FD" bgcolor="#C7CFE9"> <td height="42" colspan="4" class="style17"><strong>EMAIL<span class="style15"> <input name="re_Email" type="text" class="style17" id="re_Email" tabindex="5" size="53"> </span></strong></td> <td class="style15"> </td> </tr> <tr bgcolor="#F5F4FD"> <td width="94">Item Number </td> <td width="86">Page Number </td> <td width="84">Product Code </td> <td width="215">Description</td> <td>Price</td> <td width="62">QTY</td> <td width="57">Total</td> </tr> <tr bgcolor="#F5F4FD"> <td>1</td> <td><input name="pg2" type="text" class="style17" id="pg2" tabindex="13" size="8"></td> <td><input name="pg2" type="text" class="style17" id="pg2" tabindex="13" size="8"></td> <td><input name="cd2" type="text" class="style17" id="cd2" tabindex="14" size="9"></td> <td><input name="desc2" type="text" class="style17" id="desc2" tabindex="15" size="12"></td> <td bordercolor="#3E55A7"><input name="price2" type="text" class="style17" id="price2" tabindex="16" size="6"></td> <td><input name="qty2" type="text" class="style17" id="qty2" tabindex="17" size="3"></td> </tr> <tr bgcolor="#F5F4FD"> <td>2</td> <td><input name="pg3" type="text" class="style17" id="pg3" tabindex="18" size="8"></td> <td><input name="pg3" type="text" class="style17" id="pg3" tabindex="18" size="8"></td> <td><input name="cd3" type="text" class="style17" id="cd3" tabindex="19" size="9"></td> <td><input name="desc3" type="text" class="style17" id="desc32" tabindex="20" size="12"></td> <td><input name="price3" type="text" class="style17" id="price3" tabindex="21" size="6"></td> <td><input name="qty3" type="text" class="style17" id="qty3" tabindex="22" size="3"></td> </tr> <tr bgcolor="#F5F4FD"> <td>3</td> <td><input name="pg4" type="text" class="style17" id="pg4" tabindex="23" size="8"></td> <td><input name="pg4" type="text" class="style17" id="pg4" tabindex="23" size="8"></td> <td><input name="cd4" type="text" class="style17" id="cd4" tabindex="24" size="9"></td> <td><input name="desc4" type="text" class="style17" id="desc42" tabindex="25" size="12"></td> <td><input name="price4" type="text" class="style17" id="price4" tabindex="26" size="6"></td> <td><input name="qty4" type="text" class="style17" id="qty42" tabindex="27" size="3"></td> </tr> <tr bgcolor="#F5F4FD"> <td>4</td> <td><input name="pg5" type="text" class="style17" id="pg5" tabindex="28" size="8"></td> <td><input name="pg5" type="text" class="style17" id="pg5" tabindex="28" size="8"></td> <td><input name="cd5" type="text" class="style17" id="cd5" tabindex="29" size="9"></td> <td><input name="desc5" type="text" class="style17" id="desc5" tabindex="30" size="12"></td> <td><input name="price5" type="text" class="style17" id="price5" tabindex="31" size="6"></td> <td><input name="qty5" type="text" class="style17" id="qty5" tabindex="32" size="3"></td> </tr> <tr bgcolor="#F5F4FD"> <td>5</td> <td><input name="pg6" type="text" class="style17" id="pg6" tabindex="33" size="8"></td> <td><input name="pg6" type="text" class="style17" id="pg6" tabindex="33" size="8"></td> <td><input name="cd6" type="text" class="style17" id="cd6" tabindex="34" size="9"></td> <td><input name="desc6" type="text" class="style17" id="desc6" tabindex="35" size="12"></td> <td><input name="price6" type="text" class="style17" id="price6" tabindex="36" size="6"></td> <td><input name="qty6" type="text" class="style17" id="qty6" tabindex="37" size="3"></td> </tr> <tr bgcolor="#F5F4FD"> <td>6</td> <td><input name="pg7" type="text" class="style17" id="pg7" tabindex="38" size="8"></td> <td><input name="pg7" type="text" class="style17" id="pg7" tabindex="38" size="8"></td> <td><input name="cd7" type="text" class="style17" id="cd7" tabindex="39" size="9"></td> <td><input name="desc7" type="text" class="style17" id="desc7" tabindex="40" size="12"></td> <td><input name="price7" type="text" class="style17" id="price172" tabindex="41" size="6"></td> <td><input name="qty7" type="text" class="style17" id="qty7" tabindex="42" size="3"></td> </tr> <tr bgcolor="#F5F4FD"> <td>7</td> <td><input name="pg8" type="text" class="style17" id="pg8" tabindex="43" size="8"></td> <td><input name="pg8" type="text" class="style17" id="pg8" tabindex="43" size="8"></td> <td><input name="cd8" type="text" class="style17" id="cd8" tabindex="44" size="9"></td> <td><input name="desc8" type="text" class="style17" id="desc8" tabindex="45" size="12"></td> <td><input name="price8" type="text" class="style17" id="price8" tabindex="46" size="6"></td> <td><input name="qty8" type="text" class="style17" id="qty8" tabindex="47" size="3"></td> </tr> <tr bgcolor="#F5F4FD"> <td>8</td> <td><input name="pg9" type="text" class="style17" id="pg9" tabindex="48" size="8"></td> <td><input name="pg9" type="text" class="style17" id="pg9" tabindex="48" size="8"></td> <td><input name="cd9" type="text" class="style17" id="cd9" tabindex="49" size="9"></td> <td><input name="desc9" type="text" class="style17" id="desc9" tabindex="50" size="12"></td> <td><input name="price9" type="text" class="style17" id="price9" tabindex="51" size="6"></td> <td><input name="qty9" type="text" class="style17" id="qty9" tabindex="52" size="3"></td> </tr> <tr bgcolor="#F5F4FD"> <td>9</td> <td><input name="pga" type="text" class="style17" id="pga" tabindex="53" size="8"></td> <td><input name="pga" type="text" class="style17" id="pga" tabindex="53" size="8"></td> <td><input name="cda" type="text" class="style17" id="cda" tabindex="54" size="9"></td> <td><input name="desca" type="text" class="style17" id="desca" tabindex="55" size="12"></td> <td><input name="pricea" type="text" class="style17" id="pricea" tabindex="56" size="6"></td> <td><input name="qtya" type="text" class="style17" id="qtya" tabindex="57" size="3"></td> </tr> <tr bgcolor="#F5F4FD"> <td>10</td> <td><input name="pgb" type="text" class="style17" id="pgb" tabindex="58" size="8"></td> <td><input name="pgb" type="text" class="style17" id="pgb" tabindex="58" size="8"></td> <td><input name="cdb" type="text" class="style17" id="cdb" tabindex="59" size="9"></td> <td><input name="descb" type="text" class="style17" id="descb" tabindex="60" size="12"></td> <td><input name="priceb" type="text" class="style17" id="priceb" tabindex="61" size="6"></td> <td><input name="qtyb" type="text" class="style17" id="qtyb" tabindex="62" size="3"></td> </tr> <tr bgcolor="#F5F4FD"> <td> </td> <td> </td> <td> </td> <td> </td> <td><div align="right">Total</div></td> <td><input name="pricec" type="text" class="style17" id="pricec" tabindex="66" size="6"></td> <td><input name="qtyc" type="text" class="style17" id="qtyc" tabindex="67" size="3"></td> </tr> <tr bgcolor="#3E55A7"> <td colspan="10" class="style9"> </td> </tr> <tr align="left" valign="top" bordercolor="#FFFFFF" bgcolor="#C7CFE9"> <td colspan="10" class="style10"><span class="style17">COMMENTS / DELIVERY INSTRUCTIONS: </span><br> <textarea name="comments" cols="30" rows="3" class="style17" id="comments"></textarea> <br></td> </tr> <tr bgcolor="#3E55A7"> <td colspan="10" class="style13"> </td> </tr> <tr bgcolor="#3E55A7"> <td colspan="10" class="style13"> </td> </tr> </table> <table width="80%" border="0"> <tr> <th scope="col"> </th> </tr> </table> <input type="SUBMIT" name="Submit" value="Submit Order"> I've been trying to wrap my head around this for about two hours now. The file uploads just fine, the entry goes into the database just fine, EXCEPT for the file name like it's supposed to do. I wrote the code from scratch... it worked fine, then it broke (that's the way it's supposed to work, right?) Anyways, if anyone could take a look-see and point out what I'm missing? I've tried throwing errors on all the queries, I've made sure the filename is passed from the upload form, the form does have the proper enctype. require 'dbconfig.php'; $title = escape($_POST['title']); $content= escape($_POST['content']); $time = time(); //Check the file. if (!empty($_FILES['attachment'])) { //$filename = the name as saved on user's the computer. //$filename = $_FILES['attachment']['name']; if($_FILES['attachment']['type'] === 'image/jpeg' || $_FILES['attachment']['type'] === 'image/jpg' || $_FILES['attachment']['type'] === 'application/pdf') { //Move the file only if it's uploaded. if (is_uploaded_file($_FILES['attachment']['tmp_name'])) { //Whoops, an error. if (!move_uploaded_file($_FILES['attachment']['tmp_name'], './attachments/' . $_FILES['attachment']['name'])) { die('Error: File not uploaded. Please make sure it is a JPEG image or a PDF document.'); } else { $filename = $_FILES['attachment']['name']; } } } } if( $filename = '' || empty($_FILES['attachment'] )) { die('No attachment found. Please <a href="javascript: history.go(-1)">Go back</a>'); } if ($title === '') { die('News title is empty. Please <a href="javascript: history.go(-1)">Go back</a>'); } if ($content === '') { die('News content is empty. Please <a href="javascript: history.go(-1)">Go back</a>'); } else { if (mysql_query("INSERT INTO news (news_title, news_content, news_posted, news_edited, news_attach_path) VALUES ('$title', '$content', '$time', '0', '$filename')") or die(mysql_error())) { $posted = true; } else { $posted = false; } } ?> For eg. I would prefer to have a link like this in the head section.
<head> <script src="js/code.js"></script> </head>as oppose to like this. <head> <script> var _debug = false; var _placeholderSupport = function() { var t = document.createElement("input"); t.type = "text"; return (typeof t.placeholder !== "undefined"); }(); window.onload = function() { var arrInputs = document.getElementsByTagName("input"); var arrTextareas = document.getElementsByTagName("textarea"); var combinedArray = []; for (var i = 0; i < arrInputs.length; i++) combinedArray.push(arrInputs[i]); for (var i = 0; i < arrTextareas.length; i++) combinedArray.push(arrTextareas[i]); for (var i = 0; i < combinedArray.length; i++) { var curInput = combinedArray[i]; if (!curInput.type || curInput.type == "" || curInput.type == "text" || curInput.type == "textarea") HandlePlaceholder(curInput); else if (curInput.type == "password") ReplaceWithText(curInput); } if (!_placeholderSupport) { for (var i = 0; i < document.forms.length; i++) { var oForm = document.forms[i]; if (oForm.attachEvent) { oForm.attachEvent("onsubmit", function() { PlaceholderFormSubmit(oForm); }); } else if (oForm.addEventListener) oForm.addEventListener("submit", function() { PlaceholderFormSubmit(oForm); }, false); } } }; function PlaceholderFormSubmit(oForm) { for (var i = 0; i < oForm.elements.length; i++) { var curElement = oForm.elements[i]; HandlePlaceholderItemSubmit(curElement); } } function HandlePlaceholderItemSubmit(element) { if (element.name) { var curPlaceholder = element.getAttribute("placeholder"); if (curPlaceholder && curPlaceholder.length > 0 && element.value === curPlaceholder) { element.value = ""; window.setTimeout(function() { element.value = curPlaceholder; }, 100); } } } function ReplaceWithText(oPasswordTextbox) { if (_placeholderSupport) return; var oTextbox = document.createElement("input"); oTextbox.type = "text"; oTextbox.id = oPasswordTextbox.id; oTextbox.name = oPasswordTextbox.name; //oTextbox.style = oPasswordTextbox.style; oTextbox.className = oPasswordTextbox.className; for (var i = 0; i < oPasswordTextbox.attributes.length; i++) { var curName = oPasswordTextbox.attributes.item(i).nodeName; var curValue = oPasswordTextbox.attributes.item(i).nodeValue; if (curName !== "type" && curName !== "name") { oTextbox.setAttribute(curName, curValue); } } oTextbox.originalTextbox = oPasswordTextbox; oPasswordTextbox.parentNode.replaceChild(oTextbox, oPasswordTextbox); HandlePlaceholder(oTextbox); if (!_placeholderSupport) { oPasswordTextbox.onblur = function() { if (this.dummyTextbox && this.value.length === 0) { this.parentNode.replaceChild(this.dummyTextbox, this); } }; } } function HandlePlaceholder(oTextbox) { if (!_placeholderSupport) { var curPlaceholder = oTextbox.getAttribute("placeholder"); if (curPlaceholder && curPlaceholder.length > 0) { Debug("Placeholder found for input box '" + oTextbox.name + "': " + curPlaceholder); oTextbox.value = curPlaceholder; oTextbox.setAttribute("old_color", oTextbox.style.color); oTextbox.style.color = "#c0c0c0"; oTextbox.onfocus = function() { var _this = this; if (this.originalTextbox) { _this = this.originalTextbox; _this.dummyTextbox = this; this.parentNode.replaceChild(this.originalTextbox, this); _this.focus(); } Debug("input box '" + _this.name + "' focus"); _this.style.color = _this.getAttribute("old_color"); if (_this.value === curPlaceholder) _this.value = ""; }; oTextbox.onblur = function() { var _this = this; Debug("input box '" + _this.name + "' blur"); if (_this.value === "") { _this.style.color = "#c0c0c0"; _this.value = curPlaceholder; } }; } else { Debug("input box '" + oTextbox.name + "' does not have placeholder attribute"); } } else { Debug("browser has native support for placeholder"); } } function Debug(msg) { if (typeof _debug !== "undefined" && _debug) { var oConsole = document.getElementById("Console"); if (!oConsole) { oConsole = document.createElement("div"); oConsole.id = "Console"; document.body.appendChild(oConsole); } oConsole.innerHTML += msg + "<br />"; } } </script> </head>How can I make that happen? I rather not show that awful long code in the head. Hello,
I've made a function that contains the html header (<head>). When I call that function in a other file, with the header file included, it puts the header function in the body. So all the meta tags are in the body, instead of the head.
Would it be possible to load this all in the head?
The head function does contain the html and head tags. However, without them, it still doesn't want to go to the head.
Hey everyone, have taken a bit of a break (a couple of years) from all things PHP and generally web related, but now a project has popped up that I am really interested in figuring out. I am so, so sorry if this ends up being a very long and confusing post, but I am really hoping somebody out there might have some experience in doing this sort of thing, or maybe it is just MUCH simpler than I have convinced myself of, and I am making things unnecessarily hard for myself. First of all, I am not sure if this is as much of a coding question, or if I am just not managing to sort out the logic of it all in my head, but for some reason I just cant figure out where to get started. I am not looking for someone to tell me what to write per say, but just any advice at all that can head me in the right direction. Anyhow, here goes.. I have an automatically generated roster file, created by sabre airline solutions, that is automatically emailed out to all employees of the airline. It is a 28 day roster, and I am wanting to write a script of some sort that will automatically convert it into an ICS or Ical file for further integration with things I am doing. I have done a lot of reading about the formats of ics files, and I understand how they work, it is just writing something that will interpret the initial roster correctly that is stumping me, once I get the information out of it in a logical way, I think I can easily turn it into an ics. I was heading down the array pathway before, but I just keep getting to dead ends and methods that just arent practical. Here is a snippit from the original roster format: "31 AKL7494 LO APW 1250 APW 1210* - APW 23:20 0450 0620 01 AKL7494 0630 0091 AKL 0730 APW 1220- 03:50 24:50 73P AKL7494 1210 0094 APW 1310 AKL 1615* 04:05 00:30 73P 02 AKL7494 RST AKL 1645 AKL 0445* - AKL 0405 0535 34:15 12:00 03 AKL7506 0500 GT AKL 0500 HLZ 0700 02:00 - AKL7506 0085 HLZ 0800 BNE 0840 03:40 00:30 73P AKL7506 LO BNE 0910 BNE 0830* - BNE 23:20 0340 0710 04 AKL7506 0830 0074 BNE 0930 DUD 1610 03:40 00:50 73P AKL7506 0075 DUD 1700 BNE 1745 03:45 00:30 73P AKL7506 LO BNE 1815 BNE 1430* - BNE 20:15 0725 0945 05 AKL7506 LO APW 0050 APW 1210 - APW 11:20 0725 0945 AKL7506 1210 0094 APW 1310 AKL 1615* 04:05 -21:-4573P AKL7506 1430 0097 BNE 1530 APW 0020 04:50 17:25 73P 06 AKL7506 RST AKL 1645 AKL 0445* - AKL 0450 0620 83:45 12:00 " if a little clarification is needed.. (i know I needed it when I first began recieving these rosters!) the 31, 01, 02 etc are the dates of the month, the 31 only comes up if the month before ends halfway through a trip where the person is still away for work when the month turns over. the AKL,APW,BNE etc are airport/location codes, LO is layover (eg spending the night there) the other various times are departure times, arrival times (all in local time to wherever the person happens to be at the time) and also flight times, total duty times. The airport codes with numbers (eg AKL7506) is the trip code, meaning for that whole period you will be with the same crew, and away from your home port/base. The first problem I have encountered, is it is not consistent, some days will have 1 line, but layovers will take up one or two or more lines, so I cannot just separate the entries via line, i guess it has to be started wherever a numerical/date value begins the line? Also how do i split the data, based on white space in between (if that makes sense) I hope maybe this makes a little sense to someone, I know somebody has managed to write exactly what I am trying to do, for the exact same roster system, but for a different purpose, but I have had no luck getting in touch with this person. Thanks so much to anyone who can shed any light on this situation, Anna |