PHP - File_exists Not Working
I've read as many previous posts as I can find and tried all the suggested solutions but the following simple test code will not work for me (the session variable has been echoed and is correct). Instead of echoing the correct answer, the if(file_exists($target_file)) skips the true result and always displays the false one. I've tested it with files that do and don't exist of course. Here is the code :- $filename = $_SESSION["filename"]; $target_file = $_SERVER['CONTEXT_DOCUMENT_ROOT'] . '/folder/' . $_SESSION["filename"]; if (file_exists($target_file)) { echo 'Selected file is ' . $filename . ' and will be written.'; } else { echo "Selected file " . $filename . " doesn't exist."; } I'd really appreciate any help on this please. Edited July 11, 2020 by oldceltSimilar TutorialsI am trying to do a loop which uses file_exists to check if an image exists and if so display it using the following code: <?php $i = 1; while ($i <= 8) { $filename = $img_loc . "/hovers-800px/" . $image . "-" . $i . ".jpg"; if (file_exists($filename)) { ?> <a class="fuglybox" rel="gxr" href="<?php echo $filename; ?>"> <!--Main thumbnail image--> <img src="<?php echo $img_loc; ?>/product-detail-90px/<?php $image . "-" . $i . ".jpg"; ?>" alt="" width="90" height="90" /></a> <?php } $i++; } ?> I have echoed out $filename to check my directory structure and filename is fine and copied the echoed directory out. The structure is however http://Http://www.xxxxxx.com/img/filename.jpg. Could this be whats causing the problem? <code> $jpg_path = '../../../users/user_avatars/' . $_SESSION['the_user'] . '.jpg'; $jpeg_path = '../../../users/user_avatars/' . $_SESSION['the_user'] . '.jpeg'; $gif_path = '../../../users/user_avatars/' . $_SESSION['the_user'] . '.gif'; $png_path = '../../../users/user_avatars/' . $_SESSION['the_user'] . '.png'; $jpg_test = file_exists($jpg_path); $jpeg_test = file_exists($jpeg_path); $gif_test = file_exists($gif_path); $png_test = file_exists($png_path); </code> the path is EXACTLY correct I've checked and rechecked and everything. echoed the path and everything else that is relevant. but later when I call if ($png_test == '1') { blah blah blah } it won't return 1. even though I KNOW that the picture is there and it is at that path. if i echo the path in a src for an image it appears. hmm? Hi, I am trying to verify if the given url exists or not, by using file_exists() function. It always returns 'FALSE' , according to my understanding it happening because the file to be checked on the given url is located in safe mode. Could anyone please suggest as to how this could be overcome, by similar function or by using alternative method. Regards Abhishek Madhani I'm just trying to find out if php has the ability to check if any file exists, with only part of the filename given.. I have this path: if (file_exists($dir.'/'.$c_file.'/templ_*')) { I added a little star.. That star represents whatever the rest of that file is named for this example.. It could be anything.. So can php match any files that start with "templ_", and say that it does or does not exist?? Thanks Hello all, I am a real newby to this but need some help with a file_exists / while loop issue i have. I am trying to show a table of pictures (with their own ID's) but also if someone hasn't uploaded a picture to the server a default picture will be shown instead. I get the error: Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/thefrien/public_html/members1.php on line 103 Here is my code: $i = 1; echo "<table border='1' align='center'><tr>"; $result = mysql_query( "SELECT * FROM membership order by L_ID asc" ); while ( $row = mysql_fetch_assoc( $result ) ) { echo "<td align='center' bgcolor='#DDDEFF'><a href='profile_view.php?L_ID=".$row["L_ID"] ."'>" $pic = 'images/avatar/'. $row["L_ID"] .'s.jpg'; if (file_exists($pic)) { echo '<img src=http://www.thefriendzconnection.co.uk/images/avatar/'.$row["L_ID"] ."s.jpg>"; } else { echo '<img src=http://www.thefriendzconnection.co.uk/images/0s.jpg border='0'>'; } "</a> <br><font size='1' face='Arial, Helvetica, sans-serif'>".$row["name"] ."</font> <br><font size='1' face='Arial, Helvetica, sans-serif'>ID: ".$row["L_ID"] ."</font> <br> </td>"; if ( $i % 6 == 0 ) { echo "</tr><tr>"; } $i++; } mysql_free_result( $result ); echo "</tr></table>"; The line I am having issues with seems to be: $pic = 'images/avatar/'. $row["L_ID"] .'s.jpg'; Any suggestions would be greatfully received Thanks. I want to get suggested keywords from yahoo api service. When xml file is empty (no keyword), it gives error. To resolve this problem I used this code: if (file_exists('http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2')) { $xmlmetades = simplexml_load_file('http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2'); } Since it is not a normal .xml file, it is always considered no file, and return nothing. I'm working on a WordPress theme and I'm trying to build in a simple if statement which will check if the user has add his own logo into the images folder if he doesn't then the name of the blog will appear as normal text in place of the graphic logo. This is how it looks like: <?php $logo_dir = get_template_directory_uri() . "/images/logo.png"; if (file_exists($logo_dir)) { ?> <li><img src="<?php bloginfo ('template_directory'); ?>/images/logo.png" alt="<?php bloginfo('description'); ?>" /></li> <?php } else { ?> <li id='blog_name'><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?><font>*</font></a></li> <?php } ?> I've echo'd out $logo_dir, the URL is correct, but still for some reason it's seeing it as if there would no file exist. If I turn it around into !file_exists then the graphic logo WILL show up. So it's always seeing it as non-existent. Any ideas why this could be or am I using this function in a wrong fashion? As far as I've understood the PHP manual, this is the correct way of using it. My setup: (everything on a local network) Web server: Ubuntu Server 8.10 -- Workgroup File server: Windows Server 2008 x64 -- domain Test server: Win 2000 running WAMP -- domain I'm trying to run the code snippet below. $file is a file on the File server above. It definitely exists. Running the code below on the Test server works perfectly. But the file cannot be found when running from the Web server. $file = '//server/share/file.txt'; if (file_exists($file)) echo 'yay!'; else echo 'error'; What with the safe mode considerations, I've also tried to add: ini_set('safe_mode', 'Off'); to no effect. And since file, and fopen similarly not work, I'm pretty sure it's not that either. The File & Test servers are on the same Windows domain, but that's definitely not the reason. I tried the code on a file on a Linux computer in the Workgroup (where the Web server is) with the same results: Test server works, Web server does not. Please advise; I'm really lost. Hi ppl got code problem cant get it show users avatar & blank avatar at same time not that good at php ppl. avatar box page Code: [Select] <style type="text/css"> #name_area{height:20px; padding:3px;}; </style> <script language="javascript"> <!-- function member_change(id){ <?php $allgames = mysql_query("SELECT * FROM games") or die (mysql_error()); $allgames_total = @mysql_num_rows($allgames); if($allgames_total!=0) { $i=0; while($i<$allgames_total) { ?> document.getElementById('<?php echo mysql_result($allgames, $i, 'game_id'); ?>').style.display = "none"; <?php $i++; } } ?> document.getElementById(id).style.display = "block"; } function show_name(name){ document.getElementById('name_area').innerHTML = name; } function hide_name(){ document.getElementById('name_area').innerHTML = ''; } //--> </script> <div style="text-align:left;"> Choose Squad: <select name="D1" onchange="member_change(this.options[this.selectedIndex].value)" class="standardforms"> <?php $allgames = mysql_query("SELECT * FROM games") or die (mysql_error()); $allgames_total = @mysql_num_rows($allgames); if($allgames_total!=0) { $i=0; while($i<$allgames_total) { $game = mysql_result($allgames, $i, 'game_title'); $members_total2 = mysql_num_rows(mysql_query("SELECT * FROM members WHERE game = '$game'")); if($members_total2!=0) { ?> <option value="<?php echo mysql_result($allgames, $i, 'game_id'); ?>"><?php echo mysql_result($allgames, $i, 'game_title'); ?></option> <?php } $i++; } } ?> </select><br /><br /> </div> <?php $allgames = mysql_query("SELECT * FROM games") or die (mysql_error()); $allgames_total = @mysql_num_rows($allgames); if($allgames_total!=0) { $i=0; while($i<$allgames_total) { $game = mysql_result($allgames, $i, 'game_title'); $members = mysql_query("SELECT * FROM members WHERE game = '$game'"); $members_total = @mysql_num_rows($members); if($allgames_total!=0) { ?> <div id="<?php echo mysql_result($allgames, $i, 'game_id'); ?>" style="display: block; text-align:left;"> <?php if($members_total!=0) { $d=0; while($d<$members_total) { ?> <a href="index.php?page=members&id=<?php echo mysql_result($members, $d, 'id'); ?>"><img onmouseover="show_name('<?php echo mysql_result($members, $d, 'username'); ?>')" onmouseout="hide_name()" src="user/<?php echo mysql_result($members, $d, 'avatar_link'); $filename = 'avatar_link'; if (file_exists($filename)) { echo "avatar_link"; } else { echo "avatars/blank.jpg"; } ?>" width="50" height="50" alt="<?php echo mysql_result($members, $d, 'username'); ?>" title="<?php echo mysql_result($members, $d, 'username'); ?>"/></a> <?php $d++; } } } echo "</div>"; $i++; } } ?> <div id="name_area"></div> PHP Warning: file_exists() expects parameter 1 to be string, array given in /home/mysite/public_html/display.mysite.com/wp-content/themes/mytheme/form.php on line 9 PHP Warning: file_exists() expects parameter 1 to be string, array given in /home/mysite/public_html/display.mysite.com/wp-content/themes/mytheme/form.php on line 13I have a form that is having some issues and in the error log I see a bunch of these warnings. What is wrong with this?? I numbered the offending lines below (lines 9 & 13) Thanks for any help on this. function CheckExistance($VUrl) { /*9*/ if ( file_exists($VUrl) ) echo $VUrl; /*13*/ elseif ( file_exists(str_replace('www.display.mysite.com','www.display.com', $VUrl)) ) echo str_replace('www.display.mysite.com','www.mysite.com', $VUrl); else echo str_replace('www.mysite.com','www.display.mysite.com', $VUrl); } Edited by damion, 02 July 2014 - 06:01 PM. From my old gentoo server I run the following code with success. "/mnt/images" is a cifs mount! Code: [Select] <?php $source = '/mnt/images/1001.jpg'; $target = '/tmp/1001.jpg'; if ( file_exists($source) ) echo "file_exists: TRUE<br/>"; else echo "file_exists: FALSE<br/>"; if ( is_file($source) ) echo "is_file: TRUE<br/>"; else echo "is_file: FALSE<br/>"; if ( copy($source, $target) ) echo "copy: TRUE<br/>"; else echo "copy: FALSE<br/>"; echo "filesize source: ".filesize($source)."<br/>"; echo "filesize target: ".filesize($target)."<br/>"; ?>The output is Quote file_exists: TRUE is_file: TRUE copy: TRUE filesize source: 4715 filesize target: 4715 When I try this on my newly installed CentOS machine I get Quote file_exists: FALSE is_file: FALSE Warning: copy(/mnt/images/1001.jpg) [function.copy]: failed to open stream: Permission denied in /var/www/html/filetest.php on line 16 copy: FALSE Warning: filesize() [function.filesize]: stat failed for /mnt/images/1001.jpg in /var/www/html/filetest.php on line 21 filesize source: Warning: filesize() [function.filesize]: stat failed for /tmp/1001.jpg in /var/www/html/filetest.php on line 22 filesize target: Every function fails. Then I found that when I disable SELinux with "echo 0 > /selinux/enforce" file_exists() and copy() works. Quote file_exists: TRUE is_file: FALSE copy: TRUE Warning: filesize() [function.filesize]: stat failed for /mnt/images/1001.jpg in /var/www/html/filetest.php on line 21 filesize source: filesize target: 4715 But is_file() and filesize() still doesn't work. They all work when I run them on local files so it is somewhat related to the cifs mount. What could be the problem here? *delurk! It had to happen sooner or later!* OK, I am totally and utterly stumped. I have this script: $this->clear_cache ($this->cache_dir, $this->cache_time); if ($this->cache_time > 0) { $current_page = $_SERVER ['REQUEST_URI']; $current_page_encoded = base64_encode($current_page); $current_page_path = $this->cache_dir . $current_page_encoded; if (file_exists($current_page_path)) { // see if there is still a file with the name of the current request URI after cache cleared $content = file_get_contents ($current_page_path); return $content; } } Basically, it is for checking if there is a cached version of the page before running the rest of the script, using the REQUEST_URI as the identifier. So it calls a function to clear the cache, which works fine (and I've tried just deleting the cache files manually anyway). Then it checks if we are even caching, i.e. if cache time is greater than 0. Then it uses the BASE64-encoded REQUEST_URI (under which name the file would have been cached previously) to check if a file with that name still exists in the cache dir, and if so loads it. Now, this works perfectly with a url like: mysite/myscript/mysubpage But when the page has parameters, like: mysite/myscript/mysubpage?search=widgets the file_exists function returns TRUE, even though the directory is empty. I did do a clearstatcache(); but it made no difference and anyway, it wouldn't explain why the URI with query string would fail while the regular one would not. And even if something is wrong with my code elsewhere, the fact is it is returning TRUE for a non-existent file. Can someone prevent my slide into insanity?! Hi all My code give this: <b>Warning</b>: file_exists(): open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/home/clients/........ I get the tmp folder and check for its existanse and whether it is writeable
$t=sys_get_temp_dir(); Both gives no which is fine, I can process that. I do it to avoid the output above, but I still get that. How should I check for allowed paths? This runs on several systems where I cannot access php.ini or other system stuff.
http://paste.ee/p/OhiWv
The above is a link to a readable version of my code. The XMLHTTPREQUEST worked, and the array was pulled down. Was able to print out the undecoded/unparsed array. However, immediately afterwards, all code stops working.
<script> var xhr; if (window.XMLHttpRequest) { // Mozilla, Safari, ... xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE 8 and older xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("POST", "PHPLibrary/selectMemberResults.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send(); xhr.onreadystatechange = display_data; var $phparray function display_data() { if (xhr.readyState == 4) { if (xhr.status == 200) { //alert(xhr.responseText); $phparray = xhr.responseText; document.getElementById("suggestion").innerHTML = $phparray; // // //......................................................? // The above line of code is the last thing to print or // to do anything that returns to the browser.... //.......................................................? // All lines below do nothing............................? // } else { //alert('There was a problem with the request.'); } } } document.write("Length of phparray Array :" + $phparray.length + "<"); var output = JSON.parse($phparray, function (key,val) { if ( typeof val === 'string' ) { // regular expression to remove extra white space if ( val.indexOf('\n') !== -1 ) { var re = /\s\s+/g; return val.replace(re, ' '); } else { return val; } } return val; } ); document.write("Length of Array :" + $output.length + "<"); for (var i=0; i < $output.length; i++) { document.getElementById("suggestion").innerHTML = $output[i].MEMBER_NAME; } </script> i dont understand what is wrong plz help me.
here is code
$name = "img/".rand(1,9999999).".png"; $myFile = $name; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $html; fwrite($fh, $stringData); fclose($fh); $file=$name; $fst=file_get_contents($file); $im=imagecreatefromstring($fst); imagefilter($im, IMG_FILTER_GRAYSCALE); imagefilter($im, IMG_FILTER_NEGATE); //Convert to Grey Scale for($i=0;$i<123;$i++){ for($j=0;$j<50;$j++){ $px=imagecolorat($im,$i,$j); if($px<0x303030){ imagesetpixel($im,$i,$j,0); }else{ imagesetpixel($im,$i,$j,0xffffff); } } } $database = unserialize(@file_get_contents("db.txt")); if($database === false) $database = array(); // modify the database if needed if($_SERVER['REQUEST_METHOD'] == 'POST'){ if($_POST['submit'] == 'Add') $database[$_POST['ident']] = substr($_POST['letter'], 0, 1); if($_POST['submit'] == 'Del') unset($database[$_POST['ident']]); if($fh = @fopen('db111.txt', 'w+')){ fwrite($fh, serialize($database)); fclose($fh); } }else{ $newimage = true; } $width = 130; $height = 40; $captcha_gridstart =1; $captcha_gridspace =2; $letters = findletters($im, $width, $height, $captcha_gridstart, $captcha_gridspace); $count = count($letters); $cellw = ($count > 0) ? intval(100 / $count) : 0; //dispeckle the image and GET co-ordinates of the characters of captcha image and return them. function findletters($image, $width, $height, $gridstart, $gridspace){ $offsets = array(); $o = 0; $atstartx = true; for($x = 0; $x < $width; $x++){ $blankx = true; for($y = 0; $y < $height; $y++){ if(imagecolorat($image, $x, $y) == 0){ $blankx = false; break; } } if(!$blankx && $atstartx){ $offsets[$o]['startx'] = $x; $atstartx = !$atstartx; }else if($blankx && !$atstartx){ $offsets[$o]['endx'] = $x; $atstartx = !$atstartx; $o++; } } $count = $o; for($o = 0; $o < $count; $o++){ for($y = 0; $y < $height; $y++){ $blanky = true; for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){ if(imagecolorat($image, $x, $y) == 0){ $blanky = false; break; } } if(!$blanky){ $offsets[$o]['starty'] = $y; break; } } for($y = $height-1; $y > $offsets[$o]['starty']; $y--){ $blanky = true; for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){ if(imagecolorat($image, $x, $y) == 0){ $blanky = false; break; } } if(!$blanky){ $offsets[$o]['endy'] = $y; break; } } } for($o = 0; $o < $count; $o++){ $offsets[$o]['ident'] = ""; for($x = $offsets[$o]['startx'] + $gridstart; $x < $offsets[$o]['endx']; $x += $gridspace){ for($y = $offsets[$o]['starty'] + $gridstart; $y < $offsets[$o]['endy']; $y += $gridspace){ $offsets[$o]['ident'] .= ((imagecolorat($image, $x, $y) == 0) ? "0" : "1"); #echo $offsets[$o]['ident'].'<br>'; } } } return $offsets; } $a=""; foreach($letters as $letter){ $asciiletter = $database[$letter['ident']]; if(!empty($asciiletter)) { $a.=$asciiletter; } } I need bit of help, so I am looking into a plugin created for newsletter where default is it shows ad but it has option to remove ads by checking the check box. Default is to send ads in newsletter but if you don't want to send ads through newsletter then check the box. The problem is, it seems like checkbox selected is not being picked up. Some help would be appreciated. The custom field in wp:
'label' => 'Hide newsletter ads', 'name' => 'hide_ads', 'type' => 'checkbox', 'instructions' => 'Checking the checkbox will remove ads', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'choices' => array( 'Hide newsletter ads' => 'Hide newsletter ads', ), 'allow_custom' => 0, 'default_value' => array( ), 'layout' => 'block', 'toggle' => 0, 'return_format' => 'value', 'save_custom' => 0, ),
This is the php code for it: <!doctype html> <html lang="en-GB"> <head> <meta name="viewport" content="width=device-width" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="x-apple-disable-message-reformatting"> <title><?php the_title(); ?></title> <style> <?php require ABSPATH . 'path/newsletter.css'; ?> </style> <!--[if mso]> <style type="text/css"> .outlook-fallback-font { font-family: 'Lucida Bright', 'Cambria', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; } </style> <![endif]--> </head> <?php $hide_newsletter_ads = get_field('hide_ads'); echo $hide_newsletter_ads; ?> <body itemscope itemtype="http://schema.org/EmailMessage"> <div class="wrap"> <?php if (!$hide_newsletter_ads) { include ABSPATH . 'path/ad-banner.php'; } ?> <div class="header"> <a href="<?php bloginfo( 'url' ); ?>"> <img src="<?php echo get_home_url().'logo.png' ?>" alt="News" /> </a> </div> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if ( get_field( 'newsletter_summary' ) ) { ?> <div class="newsletter-summary"><?php the_field( 'newsletter_summary' ); ?></div> <?php } ?> <?php if ( have_rows( 'newsletter_content' ) ) : ?> <?php // Loop through the ACF blocks $count = 0; while ( have_rows( 'newsletter_content' ) ) : the_row(); if ( get_row_layout() === 'story' ) : ?> <?php if ( 0 === $count ) { ?> <span class="date outlook-fallback-font"><?php the_time( 'd M Y' ); ?></span> <?php } ?> <?php if ( get_sub_field( 'story_heading' ) ) : ?> <h1><?php the_sub_field( 'story_heading' ); ?></h1> <?php endif; ?> <div class="content"> <?php the_sub_field( 'story_content' ); ?> </div> <?php endif; if ( 'post_list' === get_row_layout() ) : ?> <?php $posts = get_sub_field( 'post_list' ); if ( $posts ) : ?> </div> <div class="story-list"> <h2><span class="wrap"><?php the_sub_field( 'post_list_heading' ); ?></span></h2> <div class="wrap-table"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <?php // Output story cards foreach ( $posts as $i => $post ) { if ( 0 === $i % 2 ) { echo '<tr>'; } $class = ( 0 === $i % 2 ) ? 'odd' : 'even'; $image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( 640, 345 ) ); $image_srcset = wp_get_attachment_image_srcset( get_post_thumbnail_id( $post->ID ) ); echo sprintf( '<td class="story-cell %4$s" valign="top"> <a href="%1$s" class="story-card outlook-fallback-font"> <img src="%3$s" alt="" height="120" style="height: 150px; object-fit: cover;" /> <span>%2$s</span> </a> </td>', esc_url( get_permalink( $post->ID ) . '?utm_source=newsletter&utm_medium=email&utm_campaign=newsletter' ), // permalink esc_html( get_the_title( $post->ID ) ), // title // esc_attr( $image_src[0] ), // image - src esc_attr( $image_src[0] ), // image - src esc_attr( $class ) // class ); if ( 0 !== $i % 2 || count( $posts ) === ( $i + 1 ) ) { echo '</tr>'; } } ?> </table> </div> </div> <div class="wrap"> <?php endif; endif; if (!$hide_newsletter_ads) { (0 === $count) { include ABSPATH . 'path/mpu-1.php'; } if (1 === $count) { include ABSPATH . 'path/mpu-2.php'; } } $count++; endwhile; endif; ?> <div class="footer"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="left"> © <?php echo esc_html( date( 'Y' ) ); ?> </td> <td class="footer-link"> <a href="<?php echo get_permalink( get_page_by_path( 'privacy-policy' ) ); ?>">Privacy Policy</a> · <a href="%unsubscribe_url%">Unsubscribe</a> </td> </tr> </table> </div> </div> <?php endwhile; endif; ?>
When I echo the POST, it echoes the correct value. The MySQL portion seems to just ignore it all together. I've tried changing the dropdown option to just a text field, same thing occurred. I have text fields right above this particular one that update just fine with the SAME exactly scripting. if POST, update query, done. Works. This one for some reason will not. MySQL portion: if ($_POST['bUpdate']){ mysql_query("UPDATE `Patients` SET `b` = '$_POST[bUpdate]' WHERE `id` = '".$_GET['id']."'"); } echo $_POST['bUpdate']; Form Portion: Code: [Select] <tr onmouseover="color(this, '#baecff');" onmouseout="uncolor(this);"> <td width="310" colspan="2" align="center"><span class="fontoptions">Postcard Status </span><br /> <? if ($data['b'] == 1){ echo '<select name="bUpdate"><option value="1" selected>Yes</option><option value="0">No</option></select>'; } else { echo '<select name="bUpdate"><option value="1">Yes</option><option value="0" selected>No</option></select>'; } ?> </td> </tr> I'm trying to turn this while loop into a for loop and am unable to get my result set to display properly in the for loop. The while works fine I just want to be able to have more control over which information is shown in my table as I loop and was wanting to use a for loop that way I can take advantage of the counter variable while i"m displaying my information. Any help would be appreciated. while ($row = mysql_fetch_assoc($data_result_set)) { echo "<td>".$row["product_id"]."</td>"; echo "<td>".$row["city"]."</td>"; echo "<td>".$row["quantity"]."</td>"; } *** I'm wanting it to look like something like this but can't figure out how to properly work in which row to display with the $i variable. $count=mysql_num_rows($data_result_set); for($i = 0; $i <= $count; $i++){ echo "<td>".mysql_fetch_assoc[$i]["product_id"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["city"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["quantity"]."</td>"; } I know the syntax for the for loop is totally off with the method mysql_fetch_assoc just dropped in there like a jerk but I'm just kinda pseudoing it out. Any help would be appreciated. Thanks in advance. Hi, I have the following file structure /.htaccess /index.php /displaypage.php All files are on root. I have following written in .htaccess file Options FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z0-9-]+)$ displaypage.php?page=$1 [NC,L] I have following written in displaypage.php echo $_GET["page"]; Now when I run http://localhost/ then it shows index.php page which is correct. If I run http://localhost/something then it shows a blank page. Previously it used to display that "page" variable on screen. mod_rewrite is enabled and I am using Windows with XAMPP. What am I doing wrong? Thanks I just did a huge import from an app I have been working on. No issues except for this. I uploaded & imported all files & databases from my wampserver (localhost, local server) to my main online server. Before I continue with the problem, I have to give you info on how the files work. I am using a "controller" to view the files. Meaning, from index.php, I call all the files. For example, instead of mysite.com/register.php, its mysite.com/index.php?page=register. The index defines the doctype & html tags etc. The other files that are called through index.php are just pure php code, it does not contain the head & body tags etc. So, the issue is , when the surfer submits a form, i need to set a cookie. this cookie is VERY important. I cannot get it to work. I am getting the header warnings after submit Of course, this is to be expected. But I tried it on my local server, & it worked. I am not very familiar with cookies, this is a side of PHP i never really even touched. I know almost everything but that. So the php code is before the html code on the page, so I figured it was worth a shot. Im guessing the problem here is, since the code being outputted as index.php code + the form page code. So the cookie is being set after the html tags. How can I fix this? I need it to work thru the controller. I cannot just make it a single file, all files on the site needs to be thru this controller, otherwise it will mess everything up. Ino I could just add the code from index.php plus the form page code & just run the php code before all of the html tags, but like I said it has to be called thru index.php. I appreciate your replies, & I hope you guys dont think im an idiot & can understand my question, im terrible with words! |