Jump to content

pyrodude

Members
  • Posts

    97
  • Joined

  • Last visited

    Never

Everything posted by pyrodude

  1. You don't have any conditionals checking to see if the submit button was pressed. Try adding if (isset($_POST['submit'])) { // Code here }
  2. Would a preg_replace() be more efficient than trying to use substr_replace()?
  3. I haven't tried your code yet, but I have a question - I'm fairly new to php coding and have no idea what the => operator does, but my guess would be that it assigns the value to the right of the symbol to the array $srch with the key of the value to the left of the symbol. Is that correct? Also, will it do all of the <?php replaces prior to trying to do <? replaces? Thanks!
  4. I'm integrating a javascript online WYSIWYG, but it has no handling for php code or tags. What I was planning to do was change <?php to <font color=orange>[code=php:0] and <? to </font>[/code] to make it a lot easier to pick out. I can get the [code=php:0] and [/code] to substitute easy enough on read and write, but when I added the font tag (I know, it's deprecated...was just in a rush) I get a weird display. substr_replace() is turning <?php into: ont color=orange> color=orange>[code=php:0] My function to replace the tags is as follows: function phpTagsReplace($editfile) { $file = file_get_contents($editfile); $count = substr_count($file,'<?php'); if ($count !== 0) { for ($i = 0; $i<=$count; $i++) { $strpos = strpos($file,'<?php'); $file = substr_replace($file,'<font color=orange>[code=php:0]',$strpos,5); } } $count = substr_count($file,'<?'); if ($count !== 0) { for ($i = 0; $i<=$count; $i++) { $strpos = strpos($file,'<?'); $file = substr_replace($file,'<font color=orange>[code=php:0]',$strpos,2); } } $count = substr_count($file,'?>'); if ($count !== 0) { for ($i = 0; $i<=$count; $i++) { $strpos = strpos($file,'?>'); $file = substr_replace($file,' </font>',$strpos,2); } } return $file; } [/code] On a side note, how big of strings can file_get_contents() and file_put_contents handle? Should I think about switching to fopen() and fread()/fwrite()? Thanks for the help!
  5. Well, whoever told you unlink() needed to be the url was somewhat right. It needs to be the path to the file from the current working directory. So, if it's up 1 directory and then in the images folder, it would be $file = '../images/' . $filename; unlink($file); Am I making any sense? On an unrelated note, you should be careful using $_REQUEST, as it's rather susceptible to attacks (especially if you're not doing any security checks on the input) If it still doesn't work, perhaps add an echo $file1 prior to the unlink, or even change it to unlink($file1) or die("Unable to delete: $file1");
  6. maybe you could post the code and we could take a look at it
  7. where is $row['pic'] generated? I mean, do you want to delete $file2 from the database, or $row['pic']? also, you'll need to delete the local file (unlink($filename)) rather then the URL to remove the actual image file
  8. Not sure if it'll make a difference, but try include('calendar_system.php');
  9. or you could set your href to www.yoursite.com/image/image.php?img= $row['pic'] and then in image.php check for $_GET['img']
  10. Let me go back and modify the code you posted for your entire page. The Working code is as follows (And I modified your code a little bit to make it more to my liking): <?php // Initialize the variables if (isset($_POST['h_meters'])) { $h_meters = $_POST['h_meters']; } if (isset($_POST['units_listA'])) { $units_listA = $_POST['units_listA']; } if (isset($_POST['units_listB'])) { $units_listB = $_POST['units_listB']; } if (isset($_POST['valueA'])) { $valueA = $_POST['valueA']; } if (isset($_POST['valueB'])) { $valueB = $_POST['valueB']; } if (isset($_POST['Calculate'])) { $Calculate = $_POST['Calculate']; } if (isset($_POST['Convert'])) { $Convert = $_POST['Convert']; } ?> <html> <head> <title>Conversion</title> </head> <body> <!--- No form action is necessary - If one is not given, it defaults to the current page. ---> <form method="POST"> <?php // If the h_meters field has been entered in and the Calculate button has been pressed, convert meters to feet in ValueA textbox and to inch in ValueB textbox. if ((strlen($h_meters)>0) && is_numeric($h_meters) && isset($Calculate)) { // Do some math $valueA = $h_meters*3.2808399; $valueB = $valueA*12; $units_listA = "feet"; $units_listB = "inch"; } // If valueA field has been entered in and the Convert button pressed, check what is selected in the options box. If feet is chosen in the units_listA then elseif ((strlen($valueA)>0) && is_numeric($valueA) && isset($Convert)) { // when units_listB should be set to inch and ValueB should be ValueA*12 if($units_listA == "feet") { $valueB = $valueA*12; // Make sure units_listB is set to inches - pointless to make it display as a conversion from feet to feet $units_listB = "inch"; } // If units_listB is set to inch, then units_listB should be set to feet and ValueB should be ValueA/12 else { $valueB = $valueA/12; // Make sure units_listB is set to inches - pointless to make it display as a conversion from inches to inches $units_listB = "feet"; } } else echo "<b>LAME!</b><br />"; ?> Enter height in meters <input type="text" size="12" name="h_meters" value="<?php echo $h_meters; ?>" /> <input type="submit" name="Calculate" value="Calculate" style="border-color: red; border-width: 2px;"/> <hr /> <input type="text" size="12" name="valueA" value="<?php echo $valueA; ?>" /> <select name="units_listA"> <?php // Use a foreach loop to loop through an array and establish the drop-down list foreach(array('inch','feet') as $value) { if ($units_listA == $value) { $selected = ' Selected="selected"'; } echo '<option value="'.$value.'"'.$selected.'>'.$value.'</option>'; unset($selected); } ?> </select> <br /> <input type="submit" name="Convert" value="Convert" style="border-color: red; border-width: 2px;"/> <br /> <input type="text" size="12" name="valueB" value="<?php echo $valueB; ?>" /> <select name="units_listB"> <?php // Use a foreach loop to loop through an array and establish the drop-down list foreach(array('inch','feet') as $value) { if ($units_listB == $value) { $selected = ' Selected="selected"'; } echo '<option value="'.$value.'"'.$selected.'>'.$value.'</option>'; unset($selected); } ?> </select> </body> </html>
  11. Your best bet would probably be to invest some time studying Outlook Macros. I haven't spent much time with them, but you would probably need to create a macro to delete all of the calendar entries once per day, then connect to your remote server and download them all. The remote server would keep an updated list of what currently needs to be in the calendar. Maybe I'm way off base, but it seems like it should work, even if it's far from efficient.
  12. place a session_start(); at the beginning of your code, before anything is output to the browser. Then, initialize $_SESSION['metric1'] = $_POST['metric1'] and so on, rather than just using $metric1. You can then, in the form, set <input type="text" name="metric1" value="<? echo $_SESSION['metric1']; ?>" /> Using sessions allows you to keep track of what options were input by the user. Sessions last until you end them (session_destroy(); and unset($_SESSION);) or when they expire, which is about an hour after initiated, although that's changeable in the php.ini Just a personal note, though...you may want to remove the check for pressing the submit button. If someone hits enter rather than clicking the button (which should have the same effect), but your script won't function correctly, as it checks if $Operation is set.
  13. Try posting the code for index.php. Perhaps it includes the contents of a few other files, in order to create the design for the page.
  14. You may want to work on aligning your code to make it a little easier to follow and see where you're going. Also, I have to ask: Are you using post or get in your form? One thing you could do to debug it would be to add echo "testX<br />"; before, after, and inside every if statement, x being a number that you increment everytime (1, 2, 3, etc). This way, you can quickly go down the page and see which if statements are executing and which arent. If you chose to do this, you should comment out the header relocation so that you can see the results. Personally, I don't see what could be wrong, unless it's an issue with the values being passed from the form to the php page. Also, to shorten your code, you could change $cnx = mysql_connect("localhost","********","*********"); if (!$cnx) { die('Could not connect: ' . mysql_error()); } into $cnx = mysql_connect("localhost","********","*********") or die('Could not connect: ' . mysql_error()); And you could do the same thing with $db_selected.
  15. Not to take over this topic, but is this possible without access to a .htaccess file (through php perhaps?)? I'm helping a friend of mine with a website on Yahoo webhosting, and they don't allow you to have a .htaccess file. Just curious. Thanks!
  16. You can use if statements for the output of the arrays, and use $_SESSIONs or even $_POST to output the submitted choice at the beginning of your <select> statement. However, on a completely unrelated point, you should check the input and make sure that only numbers were entered (no letters, underscores, etc.) You should is an is_num() statement for that. You should also change to using the post method rather than get, as it keeps your URLs more secure and less susceptible to hijacking.
  17. For the first month or so, it wouldn't hurt to do a daily backup. After that, (and depending on the sensetivity/necessity of the data) you may want to continue wit daily backups or perhaps switch to weekly. Should something happen to your lovely application, you wouldn't want your client to be SOL!
  18. $field_name = array(); and $values = array(); are just codes that identify that those variables will be arrays. The foreach takes all the entries in the $data array and adds them to the $values array with the key of $field_name (I believe - I'm a little fuzzy on this form of PHP programming so far) I'm not sure if continue exits out of that current loop, but that's what would make the most sense to me. It then adds the values to the individual arrays. . is the concatenation character in PHP so it connects the string before it to the string after it. The join() is synonymous to implode() which is the opposite of explode(). It turns an array (the second parameter) into a string based on the first parameter given (in this case, a comma).
  19. <?php // database information - set this to what your database login information is $host = localhost; $user = 'secretuser'; $password = 'sercret'; // This is the name of the database you will be connecting to. Might want to name it Tournaments or something $dbName = 'secretdb'; $dbTable = 'secrettbl'; // connect and select the database $conn = mysql_connect($host, $user, $password) or die(mysql_error()); $db = mysql_select_db($dbName, $conn) or die(mysql_error()); // Make sure the user entered values for all three fields if (strlen($_POST['name'])>0 && strlen($_POST['score'])>0 && strlen($_POST['purse'])) // IF TRUE { // Add the values to the $data array $data = array( 'Name' => $_POST['name'], 'Score' => $_POST['score'], 'Purse' => $_POST['purse'], ); echo "data array equals $data"; $field_names = array(); $values = array(); // Loop through the array foreach($data as $field_name => $value) { if(empty($value)) continue; $field_names[] = $field_name; // Make sure no invalid information was put into the form $values[] = "'".mysql_real_escape_string($value, $conn)."'"; } // Add the results into the table $insert_result = mysql_query("INSERT INTO $dbTable (".join(',',$field_names).") VALUES(".join(',',$values).")", $conn); // Pull the results from the table $select_result = mysql_query("SELECT Name,Score,Purse FROM $dbTable", $conn); { // The rest of this loops through outputting the information echo <<<FORMENT <table width=200 border=1> <th width=100>Name</th> <th width=50>Score</th> <th width=50>Winnings</th> FORMENT; } while($list = mysql_fetch_assoc($select_result)) { echo <<<EOF <tr> <td align=center width=100>{$list['Name']}</td> <td align=center width=50>{$list['Score']}</td> <td align=center width=50>{$list['Purse']}</td> </tr> EOF; }{echo <<<FORMENT </table> FORMENT; } } { echo <<<FORMENT <br> Make a new entry: <br> <form action = "{$_SERVER['PHP_SELF']}" method = "post"> <input type = "text" name = "name" maxlength="20" size = "10"> <br> <input type = "text" name = "score" maxlength="4" size = "10"> <br> <input type = "text" name = "purse" maxlength="6" size = "10"> <br> <input type = "submit" value = "Add Entry"> </form> FORMENT; } ?> [/code
  20. is_file() works on strings in an array. Maybe I just don't understand what exec() returns
  21. You can use is_file in your foreach statements if(array_key_exists('command', $_POST) and strlen($_POST['command']) > 0){ $command = $_POST['command']; exec($command, $arr); foreach($arr as $value){ if (is_file($value)) { echo "<h1>$value</h1>"; } else { echo "$value<br />"; } } }
  22. PHP.net says regarding setcookie(): So your verification in name.php seems pointless. Also, you should get rid of the empty echo statements in the first batch of code you posted. If you exit the PHP code, you don't need to use echo statements. However, this still doesn't correct your problem of them not setting, it's just simple schematics.
  23. I don't have any idea about the issue with your code, but I'm curious: why do you tell the user to limit their password to 16 characters but the textbox for the password has maxlength:255 set?
  24. My page is displaying correctly (well, the way I want it to at least!) in IE6, but IE7 and Firefox shift the navigation bar too far to the right. I want it to rest on the left side of the screen. I've checked and it's valid xhtml 1.0 transitional and valid css, so there must be some issue with the code that I just can't find. The site is available on [link]67.185.245.81/btest/phptest[/link] and the source is as follows: <!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"> <head> <title>Disc Golf NW.com</title> <meta name="description" content="DiscGolfNW.com - The Inland northwest's premiere website for information about the fast-paced game of Disc Golf!" /> <meta name="Generator" content="" /> <meta name="robots" content="" /> <link rel="Website Icon" href="#" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="http://67.185.245.81/btest/phptest/clccss.css" rel="stylesheet" type="text/css" /> </head> <body class="bg_main" style="background-color: #5E945D"> <a name="top"></a> <table id="outer" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top"><div id="main_inner"> <!-- top areas begin--> <div id="logo"> </div> <!-- top areas end--> <div class="clear"> </div> <!-- Path begin--> <div id="can_pathway"> <span class="pathway">Home</span></div> <!-- Path end--> <div id="mid_out"> <div id="rightarea"> <div class="clear"> </div> <!-- main begin--> <div id="main_area"> <table width="745px" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top"><div id="rightmain"> <table cellpadding="0" cellspacing="0" class="moduletable"> <tr> <td><table width="202px" border="0" cellpadding="0" cellspacing="0"> <tr> <td><a class="mainlevel" href="http://67.185.245.81/btest/phptest/index.php?current=main">Home</a></td> </tr> <tr> <td><a class="mainlevel" href="http://67.185.245.81/btest/phptest/index.php?current=how">Learn How To Play</a></td> </tr> <tr> <td><a class="mainlevel" href="http://67.185.245.81/btest/phptest/index.php?current=tournaments">Tournaments</a> </td> </tr> <tr> <td><a class="mainlevel" href="http://67.185.245.81/btest/phptest/index.php?current=gallery">Photo Gallery</a></td> </tr> <tr> <td><a href="http://www.discgolfnw.com/PDGA2007rulebook.pdf" class="mainlevel">PDGA Rule Book</a></td> </tr> <tr> <td><a class="mainlevel" href="http://67.185.245.81/btest/phptest/index.php?current=contact">Contact us</a></td> </tr> <tr> <td><a class="mainlevel" href="http://67.185.245.81/btest/phptest/index.php?current=games">Fun & Games</a></td> </tr> </table> </td> </tr> </table> </div></td> <td style="width:1px;"> </td> <td valign="top"><div class="left_edge"> <div class="right_edge"> <div class="top_edge"> <div class="top_lcorner"> <div class="top_rcorner"> </div> </div> </div> <div class="corner_inner"> <div id="main_body"> <table cellpadding="0" cellspacing="0"> <tr> <td valign="top"><div> <table class="contentpaneopen"> <tr> <td valign="top"> <div id="main_content" style="width: 543px;"><h1><font color='5E945D'>Welcome to Disc Golf Northwest!</font></h1><br /> Disc Golf NW is the Inland Northwest's premier website for information about disc golf, including the PDGA rulebook, locations of upcoming tournaments, and more! </div> </td> </tr> </table> </div></td> </tr> </table> </div> </div> <div class="bottom_edge"> <div class="bot_lcorner"> <div class="bot_rcorner"> </div> </div> </div> </div> </div></td> </tr> </table> </div> <!-- main end--> <div class="clear"> </div> </div> </div> <!-- bottom begin--> <div class="clear"> </div> <div class="bottomcontainer"> <table class="moduletable-topnav" cellpadding="0" cellspacing="0"> <tr> <td><a class="topnav" href="http://67.185.245.81/btest/phptest/index.php?current=main">Home</a> | <a class="topnav" href="http://67.185.245.81/btest/phptest/index.php?current=how"> Learn To Play</a> | <a class="topnav" href="http://67.185.245.81/btest/phptest/index.php?current=tournaments"> Tournaments</a> | <a class="topnav" href="http://67.185.245.81/btest/phptest/index.php?current=gallery"> Photo Gallery</a> | <a class="topnav" href="http://67.185.245.81/btest/phptest/index.php?current=contact"> Contact Us</a> </td> </tr> </table> </div> <div class="clear"> </div> <div id="footer"> Copyright Disc Golf NW, 2007<br /> This page took 0.000722 seconds to load.</div> <!-- bottom end--> </div></td> </tr> </table> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.