PHP - Trouble Using If/else On A Single Index.php File
Hi everyone! Nice to meet/see/read you.
This is my first post and it will probably be a lame one so apologies. I'm a pretty good frontend designer and I've always struggled to learn PHP and my new job is forcing it on me so I'm happy in a "throw me in the deep end" kinda way. I am really stuck! I have a single page that is using jquery to scroll my content left and right via the menu (example attached). What I am trying to do is when on the homepage, don't show the "main logo". When on any other link, show it. I immediately thought of an if/else statement but realised I don't know what or how exactly to target since everything is on the same page and the URL doesn't change. Could I target the image title that is the only image on the homepage? So, something like: <?PHP $image_title = 'home'; if (XXXXX($image_title)) { echo "IMAGE"; } else { echo "NO IMAGE"; } ?> I know that's wrong, I put XXX where I feel like something possibly helpful should go. Heh. I'm not asking for someone to write code for me, I'm happy to learn but but I would be very grateful if someone could just guide me to what I need to do and off to Google I will go. I haven't been able to find anything that is like: "if image title equals". Hmm... I hope I can do this with PHP. Thanks again, Linda Similar TutorialsHi, learning as I go here, and I appreciate the help in advance .. I have some working php code that retrieves sql results using php. I assign the resutls to an array by doing this $bobreport = array(); while ($row=db2_fetch_array($querystmt)) { array_push($bobreport, $row); } i can then write the rows of returned data after some column headers using this... foreach ($bobreport as $value) { echo "<tr><td>$value[0]</td><td>$value[1] ..... } The particular report I'm working on now has a redundant date and time in every row that I omit in the foreach loop because I just want to show it once above the table somewhere. This doesn't seem to work in accomplishing that... echo "This data was updated ".$bobreport[0][9]." at ".$bobreport[0][10] ; All I seem to get in the report is "This data was updated at". Please help. Hello, all: been trying to convert this little single-file upload to multiple by naming each file form-field as "userfile[]" as it's supposed to automatically treat them as an array.. but no luck! Can you guide me as to what am I doing wrong?? appreciate the help! Code: [Select] <?php if (!isset($_REQUEST["seenform"])) { ?> <form enctype="multipart/form-data" action="#" method="post"> Upload file: <input name="userfile[]" type="file" id="userfile[]"> Upload file: <input name="userfile[]" type="file" id="userfile[]"> <input type="submit" value="Upload"> <input type="hidden" name="seenform"> </form> <?php } else { // upload begins $userfiles = array($_FILES['userfile']); foreach ($userfiles as $userfile) { // foreach begins $uploaded_dir = "uploads/"; $userfile = $_FILES['userfile']["name"]; $path = $uploaded_dir . $userfile; if (move_uploaded_file($_FILES['userfile']["tmp_name"], $path)) { print "$userfile file moved"; // do something with the file here } else { print "Move failed"; } } // foreach ends } // upload ends ?> How do I Upload Multiple Files using a PHP form and script? 10 files at one time would be great. Ultimately I need a photo upload and management script. Here is my current single file upload form: <form action="upload.php" method="post" enctype="multipart/form-data"> <label for="file">Upload a Photo:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> Here is the Php Script: <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 200000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); echo "Stored in: " . "uploads/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Hi. This is my first post, so feel free to lecture me on forum etiquette and conventions. I'm trying to create a form, several items of which are file upload <input>s. Here is the relevant code from the form. <label for="facefile">Filename:</label> <input type="file" name="facefile" id="facefile" /> This form has an action="validateform.php". In the file for validateform.php I can't seem to reference "facefile". I just try doing <?php echo($_FILES["facefile"]["name"]); ?> And I get Notice: Undefined index: facefile in validateform.php on line 1 I was talking to some friends, who are just as new as me in programming, and they think it would be better to use a single navigation file for every link in a web site. Something like this: Code: [Select] <a href="nav.php?id=home&otherparams" >Home</a> <a href="nav.php?id=products&otherparams" >Products</a> <a href="nav.php?id=contact&otherparams" >Contact</a> I told them I think this might be easier to maintain, but also might take up on loading time, as the site viewer will have to go through an extra node to get where he wants. Is this single navigation file a good practice or should it be avoided? Thanks for any comments... This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358810.0 Hello. I want to make a simple website, where I can upload a zip file and download it from a URL with just HTTP GET request. When I download the file, the file will then be deleted on the server. Can't find any examples. Maybe, I've searched wrong. Has somebody some written project links or some tips for me how can I achieve this?
I have created a css menu for the top of my site that is included on each page with a php include. What I am wanting to do now is create the side menu options for each page from the one file. Each page will have different links side links based on what section of the site you are in however I want to administer them all from one php file if that is possible. I'm quite new to php and am not sure if I can even do this. Any ideas on how this can be done? Hey all, I am building a simple cms. I have a posts table and I have an images table. A post has many images and images has a foreign key to the posts table. So when a user edits, updates, creates, and deletes a post, they affect the images related to the post. Sometimes a post can have more than one image, like three images. Hence I rendered this in the view (note that I am using a datamapper that converts tables to objects and fields to key/value pairs): Code: [Select] foreach($records as $post){ echo form_open_multipart("homes/update/$post->id"); //File uploads require a multipart form. Default form handling uses the application/x-www-form-urlencoded content type. Multipart forms use the multipart/form-data encoding. //this is critical to pass the id as part of the action attribute of the form, so we can use our params hash to target the id to update the specific record echo label('Update Title'); echo form_input('title',$post->title); echo label('Update Body'); echo form_textarea('body',$post->body); $images = $post->images->include_join_fields()->get(); if(!is_null($images->image_file_name)){ echo label('Update Images'); foreach($images as $image){ echo form_upload('image_file_name',$image->image_file_name); } } } echo form_submit('submit','Update'); The above line of code will render a few input file types. The problem occurs during posting to my update method. It is looking for one parameter from the input file field and so if I upload three different images, it will only look for one and write only one to database: Code: [Select] $field_name = 'image_file_name'; if ( ! $this->upload->do_upload($field_name)){ $error = array('error' => $this->upload->display_errors()); echo $error['error']; // redirect('homes/edit'); } else { $data = array('upload_data' => $this->upload->data()); $image_file_name = $data['upload_data']['file_name']; Is it possible to do wht I am trying to do? Should I only have on input file type per form submission or is that I need to fix the code to accomodate for multiple submissions by creating an array of sorts? Thanks for response. I know it needs a for loop, but i don't know where in the code i should be putting it? Code: [Select] function check_input($value) { // Stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote if not a number if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value) . "'"; } return $value; } $_POST = array_map('check_input', $_POST); $sql="INSERT INTO testimonials (CustomerName, Town, Testimonial, SortOrder, Images) VALUES ({$_POST['customername']}, {$_POST['town']}, {$_POST['testimonial']}, {$_POST['sort_order']}, '$imgname' )"; } if (!mysql_query($sql,$con)) { die("<br>Query: $sql<br>Error: " . mysql_error() . '<br>'); } echo "<p align=center><b>1 testimonial added</b></p>"; mysql_close($con); Thanks in Advance, Steve I'm ok with PHP but probably not half as good as some of you guys on here. I am basically trying to find a way to grab a line from a huge and I mean huge text file.... its basically a list of keywords I want to call by line number but without preferably going through them all before I get to that line.....otherwise couldmcrash my server obviously. At the moment im using this Code: [Select] $lines = file('http://www.mysite.com/keywords.txt'); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num => $line) { echo "$line_num"; } This works but im sure theres gotta be a better way of doing to save on usuage because this is putting the whole file into the memory and if I can simply say to php give me line number 97, would umm RULE.... Hope you guys can come up with a solution as your much smarter than me ty I've inherited a website and I'm no PHP expert. The way pages work is the urls are displayed as follows http://www.website.com/?action=<page_name> The pages are stored in a folder called templates as .tpl files. Amongst these is a file called layouts.tpl which is the website layout and menus, inside this there's a php include Code: [Select] <?php include("template/$content_for_layout.tpl"); ?> which basically draws the content for the page from each static file when requested. In the index.php each static file has to be included as in the following example: Code: [Select] case "conditions"; $title = "Terms & Conditions"; $content_for_layout = $_GET['action']; break; Without this in the index.php the page just reverts back to the homepage when you enter the url. I personally don't think this is right? It is handy to be able to manage all the page titles from a central location (index.php) but seems quite messy and cumbersome. I plan on making an articles or news folder and regularly creating pages and if each one has to be relayed this way in the index it is going to get big and cause headaches. Is there any way around this that anyone can see? ... On another note. If you type in the actual physical url of the file location it shows the html of the page without the layout i.e. http://www.website.com/template/conditions.tpl I don't know how common it is for websites to display "../?action=pagename" or similar but I wouldn't have thought it would be ideal for SEO purposes? Sorry,guys,just can`t get thru: 1.there`s a file index.php <html> <body> <form action=/open.php> <button name=Jack value="150" type=submit>Send Form</button> </form> </body> </html> 2.there`s another file open.php <? echo $Jack; ?> Press the button,in the address box it says: http://mysite.net/open.php?Jack=150 But nothing happens,open.php doesn`t work.I got Denwer,open.php is in www.mysite.net. Please,help.Thanx. PHP script return 20 UL LIST values like, < ul >
A < /ul > How to display UL LIST into row wise 5 columns like
A B C D I am just trying to use Associate array in another php file through session.
file1.php <?php $age = array(); $_SESSION["age"] = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); foreach($_SESSION["age"] as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>\n"; } ?> OUTPUT: Key=Peter, Value=35 Key=Ben, Value=37 Key=Joe, Value=43 file2.php <?php session_start(); foreach( $_SESSION["age"] as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>\n"; } ?> OUTPUT: PHP Notice: Undefined index: age in session.php on line 3 PHP Warning: Invalid argument supplied for foreach() in session.php on line 3 Why am I getting this error? Above is just example I tried to demonstrate for asking question for other issue, unfortunately I got new error in this example. But actual issue was, I was trying to plot graph using library which requires only Associate array, where the data is formed in file1.php. But I get only last index value displayed in file2.php even in graph or in echo. I don't understand why other values are not displayed in file2.php Please point me what is going wrong, Thanks. hello. im having trouble getting my images to show my navigation (which i downloaded from http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu.htm) im pulling in the navigation dynamically. i can get it to show the navigation and css but not the images its quite a long destination url... if i put this code on the ddAccordian.php page it works Code: [Select] <link href="http://localhost:8888/djsonrotation/admin/pages/contElements/Navigation/Vertical/ddAccordion/css/styles.css" rel="stylesheet" type="text/css" /> if i try and shorten the url like below the css works but i get no images Code: [Select] <?PHP require_once("../includes/initialize.php"); ?> <style type="text/css" rel="stylesheet"> <?php include(NAVIGATION.DS."styles.css"); ?> </style> the Quote include(NAVIGATION.... is being created in my initialize file Code: [Select] defined('NAVIGATION') ? null : define('NAVIGATION', $_SERVER['DOCUMENT_ROOT'].DS.'djsonrotation'.DS.'admin'.DS.'pages'.DS.'contElements'.DS.'Navigation'.DS.'Vertical'.DS.'ddAccordion'.DS.'css'); in my css file i have tried all of these (1 at a time) but none work: Code: [Select] background: black url(titlebar.png) repeat-x center left; background: black url(/titlebar.png) repeat-x center left; background: black url(./titlebar.png) repeat-x center left; background: black url(../titlebar.png) repeat-x center left; background: black url(images/titlebar.png) repeat-x center left; background: black url(/images/titlebar.png) repeat-x center left; background: black url(./images/titlebar.png) repeat-x center left; background: black url(../images/titlebar.png) repeat-x center left; my folders are like this /ddAccordion/css/styles.css /ddAccordion/images/ /ddAccordion/js/ /ddAccordion/ddAccordion.php any thoughts. thanks ricky hello, i cant see why my navigation file path is not working im working on my localhost: http://localhost:8888/djsonrotation my initialize file is located at http://localhost:8888/djsonrotation/includes/initialize.php my navigation code is located at http://localhost:8888/djsonrotation/pages/pageContent/navigation/ddAccordion.php my js is located at http://localhost:8888/djsonrotation/js/ddaccordion.js if i put these on my ddAccordion.php it works Code: [Select] to find my initialize file <?PHP require_once("../../../includes/initialize.php"); ?> to find my js file <script type="text/javascript" src="../../../js/ddaccordion.js"> this is how my initialize file looks Code: [Select] <?PHP defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR); defined('SITE_DOMAIN') ? null : define('SITE_DOMAIN', 'http://localhost/djsonrotation'); defined('SITE_ROOT') ? null : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'].DS.'djsonrotation'); defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes'); defined('ELEMENTS') ? null : define('ELEMENTS', $_SERVER['DOCUMENT_ROOT'].DS.'djsonrotation'.DS.'pages'.DS.'contElements'); the problem is i can't seem to change ../../../ in to a file path like this does not work Code: [Select] <?PHP require_once(include(LIB_PATH.DS."initialize.php")); ?> i tried a couple of different file paths for my js file but they dont work either Code: [Select] <script type="text/javascript" src="<?php include(SITE_DOMAIN.DS."js".DS."ddaccordion.js"); ?>"> or Code: [Select] <script type="text/javascript" src="<?php include(SITE_ROOT.DS."js".DS."ddaccordion.js"); ?>"> i guess i could just use ../../../ but why are the include paths not working ???? thanks Hi, I have the following code which allows a user to enter a name for a mysql column field. Once they have submitted the form they are then redirected back to the form which allows them to enter the name for another mysql column form. When they are returned to the form, I would like the new column field added to the file named userinfo.php The problem is, I need the column field variable entered into the userinfo.php in the following format $newcolumn = $info['newcolumn'] but when I put it like this $stringData = "$newcolumn = $info['newcolumn']"; I get this error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/tropicsb/public_html/MemberSiteMaker/admin.php on line 398 Code: [Select] // Profile and Application details case "profileFields": session_start(); if(isset($_SESSION['username'])) { $newcolumn = $_GET['newcolumn']; $file = "lib/userinfo.php"; $fh = fopen($file, 'a') or die ("Cant open file"); $stringData = "$newcolumn = $info['newcolumn']"; fwrite($fh, $stringData); fclose($fh); echo "This is the logged in page\n<br>"; ECHO <<<PAGE <form action=admin.php?cmd=addfield&username=admin method=POST> <input type=text name=newcolumn> <input type=submit name=submit> PAGE; } else { echo "This is a failed login"; } break; case "addfield": include_once("data/mysql.php"); $newcolumn = $_POST['newcolumn']; $mysqlPassword = (base64_decode($mysqlpword)); $con = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die(mysql_error()); mysql_select_db("$dbname", $con) or die(mysql_error()); $result=mysql_query("ALTER TABLE members ADD $newcolumn VARCHAR(30) AFTER approved") or die("Alter Error: ".mysql_error()); mysql_close($con); echo "Database has been modified successfully."; echo '<meta http-equiv="REFRESH" content="5;url=admin.php?cmd=profileFields&username=admin&$newcolumn">'; break; thanks I'm new to the PHP world and trying to work my way through a problem. I've gone down many roads, but can't seem to find the answer. I'm not even sure this is so much a PHP question at this point as a host configuration issue. I'm trying to grab an XML file from a remote server. My first try was to try to shell out a wget as follows: exec("wget -q -O status.xml - http://$username:$password@$hostname:$port/cgi-bin/status.xml",$xmlget,$err); This didn't work. Not a surprise since doing it directly from SSH gave: Connecting to mydomain.com|99.99.99.99|:8080... failed: Connection refused. [Note that the port 8080 above is, I think, key] I've since tried method using both file_get_contents and cURL. Similar results for all. I won't clutter this up with the code unless you ask. It's all very straightforward. [file_get_contents complains 'Connection refused' and curl_error says 'couldn't connect to host']. With all of the methods, I'm able to grab, say, google.com AND a page from mydomain.com (default port 80), just not from port 8080. I've set 'allow_url_fopen = on' in php.ini and in my code for good measure. Also, the XML file that lives at 8080 is retrieved fine through a browser. I'm hosted at GoDaddy on their "deluxe shared linux" plan. Is there something obvious I'm missing that would allow all this to work over port 80, but not 8080? Thanks is advance! Greg Trying to a. check if dir exists if not create it, and b. save an uploaded file to that directory. Nothing however is working but I'm pulling no errors, heres the code: $test_pic = $_POST['test_pic']; // I've also tried $test_pic = $_FILES["test_pic"]; : with no success if (is_uploaded_file($test_pic)) { if (!file_exists("tests/uploads/" . $test_name . "/")) { $create_test_folder = (mkdir("tests/uploads/" . $test_name)); if (!$create_test_folder) { echo "cant create folder"; die; } } $target_path = ("tests/uploads/" . $test_name . "/" . $test_name . "_1"); if (($_FILES["test_pic"]["type"] == "image/gif") || ($_FILES["test_pic"]["type"] == "image/jpeg") || ($_FILES["test_pic"]["type"] == "image/jpg") || ($_FILES["test_pic"]["type"] == "image/png") && ($_FILES["test_pic"]["size"] < 50000)) { if (!copy($test_pic, $target_path)) { echo "cant copy picture"; die; } } else { echo "file type or size bad"; die; } } and I understand its not at all public-safe but I'm just wanting to get it to work before I throw in the security. Thanks for the help! |