PHP - Calc Not Working Out Correctly - Bad Code - Just Needs To Work :d
Problem -
http://runehints.com/calculators/mining?rsname=gaogier&action=calculator So far all is correct, once you click calculate the problems start. If I do a little math, level 67 is the target, with 548028 xp, minus the current xp of 533469 that = 14559 14559 / 50 xp per coal = x amount of coal which is 291.18 coal. Now, my calculator is saying, 33173 is the answer. Which it clearly is not the case. The URL I get, http://runehints.com/calculators/mining?rsname=gaogier&action=calculate&cxp=533469&lvl=2192114 if you change the last part (2192114) to 548028 it nearly works out to be right, as it shows 291 coal. http://runehints.com/calculators/mining?rsname=gaogier&action=calculate&cxp=533469&lvl=548028 I plan to get this script rewritten over the next couple of months, is it worth fixing it? I mean can you spot the error? <?php preg_match('~calculators\/([a-zA-Z]+)~', $_SERVER['REQUEST_URI'], $which); $which = $which[1]; ?> <div id="contenttitle"><?php echo ucfirst($which); ?> Calculator</div> <div class="news"> <?php preg_match('~(agility|attack|combat|cooking|crafting|defence|farming|firemaking|fishing|fletching|herblore|hitpoints|magic|mining|prayer|ranged|runecrafting|slayer|strength|summoning|thieving|woodcutting)~', $_SERVER['REQUEST_URI'], $url); $uri = $url[1]; if (empty($uri)) { echo '<table class="guide"> <tr class="trtitle"> <th class="main">Skill Name</th> <tr> <tr> <td><a href="/calculators/agility">Agility</a></td> <tr> <tr> <td><a href="/calculators/attack">Attack</a></td> <tr> <tr> <td><a href="/calculators/cooking">Cooking</a></td> <tr> <tr> <td><a href="/calculators/crafting">Crafting</a></td> <tr> <tr> <td><a href="/calculators/defence">Defence</a></td> <tr> <tr> <td><a href="/calculators/farming">Farming</a></td> <tr> <tr> <td><a href="/calculators/fishing">Fishing</a></td> <tr> <tr> <td><a href="/calculators/fletching">Fletching</a></td> <tr> <tr> <td><a href="/calculators/herblore">Herblore</a></td> <tr> <tr> <td><a href="/calculators/hitpoints">Hitpoints</a></td> <tr> <tr> <td><a href="/calculators/magic">Magic</a></td> <tr> <tr> <td><a href="/calculators/mining">Mining</a></td> <tr> <tr> <td><a href="/calculators/prayer">Prayer</a></td> <tr> <tr> <td><a href="/calculators/ranged">Ranged</a></td> <tr> <tr> <td><a href="/calculators/runecrafting">Runecrafting</a></td> <tr> <tr> <td><a href="/calculators/slayer">Slayer</a></td> <tr> <tr> <td><a href="/calculators/strength">Strength</a></td> <tr> <tr> <td><a href="/calculators/summoning">Summoning</a></td> <tr> <tr> <td><a href="/calculators/thieving">Thieving</a></td> <tr> <tr> <td><a href="/calculators/woodcutting">Woodcutting</a></td> <tr> </table>'; } else { # All Calculator - calculate.php # Orignally created on 28 December 2004 remade using RS Hiscores on 9 June 2005 # Created by Joseph Jeffery of DSIBaN Designs //This page functions as every calculator //set page headers $lvl = 0; preg_match('~rsname=(.*)&action~', $_SERVER['REQUEST_URI'], $rsnam); $rsn = $rsnam[1]; /** * Return current xp for specific skill */ function return_exp($name, $skill) { $url = "http://hiscore.runescape.com/index_lite.ws?player=" . strtolower(str_replace(' ', '_', $name)); if (($page = @file_get_contents($url)) === false) { echo "User $name was not found in the highscores for $skill"; return false; } if(strpos($page, "<html>")) { trigger_error('Unable to parse RuneScape highscore page', E_USER_WARNING); echo "<h1>DUMP</h1>"; } $catagories = split(' ', $page); //Find proper index for skill switch($skill) { case "attack": $ind = 1; break; case "defence": $ind = 2; break; case "strength": $ind = 3; break; case "constitution": $ind = 4; break; case "ranged": $ind = 5; break; case "prayer": $ind = 6; break; case "magic": $ind = 7; break; case "cooking": $ind = 8; break; case "woodcutting": $ind = 9; break; case "fletching": $ind = 10; break; case "fishing": $ind = 11; break; case "firemaking": $ind = 12; break; case "crafting": $ind = 13; break; case "smithing": $ind = 14; break; case "mining": $ind = 15; break; case "herblore": $ind = 16; break; case "agility": $ind = 16; break; case "thieving": $ind = 17; break; case "slayer": $ind = 18; break; case "farming": $ind = 20; break; case "runecrafting": $ind = 21; break; case "hunter": $ind = 22; break; case "construction": $ind = 23; break; case "summoning": $ind = 24; break; case "dungeoneering": $ind = 25; break; } $skill_info = split(",", $catagories[$ind]); $skill_exp = $skill_info[2]; return $skill_exp; } function enter_name(){ $skill = $_GET['skill']; $mem = $_GET['members']; $_GET['action'] = 'calculator'; preg_match('~rsname=(.*)&action~', $_SERVER['REQUEST_URI'], $rsnam); $rsn = $rsnam[1]; preg_match('~&action=(.*)~', $_SERVER['REQUEST_URI'], $action); $_GET['action'] = $action[1]; echo '<form action="" method="get"> <p>Runescape name: <input type="text" name="rsname" class="text" value="' . $rsn . '" /> <input type="hidden" name="action" value="calculator" /></p> <input type="submit" class="text" value="Grab XP" onMouseOver="this.style.cursor=\'hand\';"/> </form><br /> '; } function calculator(){ preg_match('~rsname=(.*)&action~', $_SERVER['REQUEST_URI'], $rsnam); $rsn = $rsnam[1]; preg_match('~calculators\/(.*)\?rsname~', $_SERVER['REQUEST_URI'], $skill); $skill = $skill[1]; preg_match('~&action=(.*)~', $_SERVER['REQUEST_URI'], $action); $_GET['action'] = $action[1]; if($rsn != "") { $xp = return_exp($rsn, $skill); } $mem = $_GET['members']; if ($xp > 13034430){ echo 'You\'re already level 99!'; } ?> <form action="" method="get"> <table border="0" class="calcinput"> <input type="hidden" name="rsname" value="<?php echo $rsn; ?>"> <input type="hidden" name="action" value="calculate" /> <tr><td>Current Xp:</td><td> <input type="text" name="cxp" class="text" value="<?php if ($xp != "0") { echo $xp; } ?>" /></td></tr> <tr><td>Current Level:</td><td><input type="text" class="text" value="<?php echo getLevel($xp); ?>" /></td></tr> <tr><td>Desired Level:</td><td> <SELECT name="lvl" class="text"><?php genDropDown($xp); ?> </select> <?php if ($mem == "yes"){ echo '<tr><td>Show members items?:</td><td> <input name="showmembers" type="checkbox" disabled="true" value="yes" checked></td></tr> '; }else{ echo '<tr><td>Hide members items?:</td><td> <input name="showmembers" type="checkbox" value="no"></td></tr> '; } ?> <tr><td><input type="submit" class="text" value="Calculate" onMouseOver="this.style.cursor='hand';"/></td><td> <input type="reset" class="text" value="Reset" onMouseOver="this.style.cursor='hand';"/></td></tr> </table> <?php } /*Calculate level based on experience function getLevel($xp) { $a = 0; for($i = 0; $i < 100; $i++) { if($a / 4 > $xp) { return $i; } $a += floor($i + 300 * pow(2, ($i / 7))); } } */ function getLevel($exp){ $levels = array(1 => 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254, 224466, 247866, 273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445, 899256, 992895, 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1968068, 2192818, 2421087, 2673114, 2951373, 3258594, 3597729, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7994614, 8771558, 9684577, 10692629, 11805606, 13034431); $l = count($levels); while ($levels[$l] > $exp) $l--; return $l; } //Generate dropdowns based on xp function genDropDown($xp) { //Gather experience $a = 0; for($i = 0; $i < 100; $i++) { if($a / 4 > $xp) { if($lvl == 0) { $lvl = $i; } echo "<option value=\"$a\">Level $i - " . floor($a / 4) . " xp</option>"; } $a += floor($i + 300 * pow(2, ($i / 7))); } } function calculate(){ preg_match('~&lvl=(.*)~', $_SERVER['REQUEST_URI'], $lvl); $lvl = $lvl[1]; preg_match('~&cxp=(.*)&lvl~', $_SERVER['REQUEST_URI'], $cxp); $cxp = $cxp[1]; preg_match('~rsname=(.*)&action~', $_SERVER['REQUEST_URI'], $rsnam); $rsn = $rsnam[1]; preg_match('~calculators\/(.*)\?rsname~', $_SERVER['REQUEST_URI'], $skills); $skills = $skills[1]; preg_match('~&action=(.*)~', $_SERVER['REQUEST_URI'], $action); $_GET['action'] = $action[1]; $lev = $_POST['lev']; $xpn = $lvl - $cxp; if ($xpn == ""){ $xpn = $_GET['xpn']; } if ($lev == ""){ $lev = $_GET['lev']; } $show = $_GET['showmembers']; if ($show == "0"){ $show = $_POST['showmembers']; } switch($skills) { case 'firemaking': $skill = "fire"; $item = "Log"; break; case 'runecrafting': $skill = "rune"; $item = "Rune"; break; case 'ranging': $skill = "range"; $item = "Monster"; break; case 'herblore': $skill = "herb"; $item = "Herb/Potion"; break; case 'fishing': $skill = "fish"; $item = "Fish"; break; case 'cooking': $skill = "cook"; $item = "Food"; break; case 'woodcutting': $skill = "wood"; $item = "Log"; break; case 'agility': $skill = "agility"; $item = "Course"; break; case 'slayer': $skill = "slayer"; $item = "monster"; break; case 'farming': $skill = "farming"; $item = "Seed/Action"; break; case 'fletching': $skill = "fletching"; $item = "Item"; break; case 'magic': $skill = "magic"; $item = "Spell"; break; case 'mining': $skill = "mining"; $item = "Ore"; break; case 'smithing': $skill = "smithing"; $item = "Bar"; break; case 'thieving': $skill = "thieving"; $item = "Chest/Stall/Pickpocket"; break; case 'fighting': $skill = "fighting"; $item = "Monster"; break; case 'crafting': $skill = "crafting"; $item = "Item"; break; case 'prayer': $skill = "prayer"; $item = "Bones"; break; default: $skill = $skill[1]; $item = "Item"; } $mem = $_GET['members']; echo' <table border="0.5" cellspacing="1" cellpadding="2" align="center" bgcolor="#857553"> <tr><td class="tableheader"><a style="color: #EED8B4" href="'.$_SERVER['PHP_SELF'].'?action=calculate&skill='.$skill.'&orderby=level&xpn='.$xpn.'&lev='.$lev.'&members='.$mem.'&showmembers='.$show.'">Level needed</a></td><td class="tableheader"><a style="color: #EED8B4" href="'.$_SERVER['PHP_SELF'].'?action=calculate&skill='.$skill.'&orderby=item&xpn='.$xpn.'&lev='.$lev.'&members='.$mem.'&showmembers='.$show.'">'.$item.'</a></td><td class="tableheader"><a style="color: #EED8B4" href="'.$_SERVER['PHP_SELF'].'?action=calculate&skill='.$skill.'&orderby=xp&xpn='.$xpn.'&lev='.$lev.'&members='.$mem.'&showmembers='.$show.'">Experience given</a></td><td class="tableheader"><a style="color: #EED8B4" href="'.$_SERVER['PHP_SELF'].'?action=calculate&skill='.$skill.'&orderby=xp&xpn='.$xpn.'&lev='.$lev.'&members='.$mem.'&showmembers='.$show.'">Number of times</a></td><td class="tableheader"><a style="color: #EED8B4" href="'.$_SERVER['PHP_SELF'].'?action=calculate&skill='.$skill.'&orderby=members&xpn='.$xpn.'&lev='.$lev.'&members='.$mem.'&showmembers='.$show.'">Members?</a></td>'; require_once ('includes/connect.php');//connect to db $by = $_GET['orderby']; if ($mem == "no"){ if ($show == "no"){ $mess = '<a href="'.$_SERVER['PHP_SELF'].'?action=calculate&skill='.$skill.'&orderby=level&xpn='.$xpn.'&lev='.$lev.'&members='.$mem.'&showmembers=no">Click here to show members items</a>'; $n_query = 'SELECT * FROM `'.$skill.'calc` WHERE `members`="0" ORDER BY `'.$by.'` ASC'; }else{ $mess = '<a href="'.$_SERVER['PHP_SELF'].'?action=calculate&skill='.$skill.'&orderby=level&xpn='.$xpn.'&lev='.$lev.'&members='.$mem.'&showmembers=yes">Click here to hide members items</a>'; $n_query = 'SELECT * FROM `'.$skill.'calc` ORDER BY `'.$by.'` ASC'; } }else{ $n_query = 'SELECT * FROM `'.$skill.'calc` ORDER BY `'.$by.'` ASC'; } $n_result = mysql_query ($n_query); while ($n_row = mysql_fetch_assoc($n_result)) { $level = $n_row['level']; $course = $n_row['item']; $xpg = $n_row['xp']; $tot1 = $xpn / $xpg; $tot = sprintf('%.0f', $tot1); $members1 = $n_row['members']; if ($members1 == "1"){ $members = "Yes"; $bg2 = "#808080"; }else{ $members = "No"; $bg2 = "#FF8C00"; } if ($lev < $level){ $bg = "#049f2c"; }else{ $bg = "#006600"; } echo '<tr><td class="calc" bgcolor="'.$bg.'"onMouseOver="this.style.backgroundColor=\'#71828A\'" onMouseOut=this.style.backgroundColor="'.$bg.'">'.$level.'</td><td>'.$course.'</td><td>'.$xpg.'</td><td>'.$tot.'</td><td class="calc" bgcolor="'.$bg2.'" onMouseOver="this.style.backgroundColor=\'#71828A\'" onMouseOut=this.style.backgroundColor="'.$bg2.'">'.$members.'</td>'; } echo' </table><br /> '; echo $lev; } preg_match('~rsname=(.*)&action~', $_SERVER['REQUEST_URI'], $rsnam); $rsn = $rsnam[1]; preg_match('~calculators\/(.*)\?rsname~', $_SERVER['REQUEST_URI'], $skill); $skill = $skill[1]; preg_match('~&action=([a-zA-Z0-9]+)~', $_SERVER['REQUEST_URI'], $action); $_GET['action'] = $action[1]; switch($_GET['action']) { case 'calculate': enter_name(); calculate(); break; case 'calculator': enter_name(); calculator(); break; case 'enter_name': enter_name(); calculator(); break; default: enter_name(); } } ?> </div> Similar TutorialsI'm getting the following error with the code below: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\wamp\www\flow\fpdf\rev.php on line 47 Can I get another set of eyes to look at it & see what I'm missing? Code: [Select] <html <head> <?php require('connection.php'); if (isset($_GET['op']) && $_GET['op'] == "d") if($_GET['op'] == "d" && !empty($_GET['id']) ) { { $result = mysql_query($query) or die(mysql_error()); } $query="SELECT fid, pacts, fname, lname, employee, dock, due_owner, due_attny, due_suspo, due_clerk, interv_date, due_rev, assgn_date, sent_date FROM psrinfo"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array( $result )) { ?> <?php } require('connection.php'); if (isset($_GET['op']) && $_GET['op'] == "d") if($_GET['op'] == "d" && !empty($_GET['id']) ) { $result = mysql_query($query) or die(mysql_error()); } $query="SELECT fid, pacts, fname, lname, employee, dock, due_owner, due_attny, due_suspo, due_clerk, interv_date, due_rev, assgn_date, sent_date FROM psrinfo WHERE employee = 'employee1' "; $result = mysql_query($query) or die(mysql_error()); echo '<form action="111.php" method="post"> <h2> <center> Paper Review </center></h2> <table width="75%" border="1">'; while($row = mysql_fetch_array( $result )) { echo '<tr> <td><b>PACTS:</b> <br><input type="text" name="pacts" size="25" maxlength="30" value="'. $row['pacts'] .'" /><br> </td> <td><b>Reviewer:</b> <br><input type="text" name="dock" size="25" maxlength="30" value="''" /><br> </td> </tr> <tr> <td><b>First Name:</b> <br><input type="text" name="fname" size="25" maxlength="30" value="'. $row['fname'] .'" /><br> </td> <td><b>Last Name:</b> <br><input type="text" name="lname" size="25" maxlength="30" value="'. $row['lname'] .'" /><br> </td> <td><b>Dock:</b> <br><input type="text" name="dock" size="25" maxlength="30" value="'. $row['dock'] .'" /><br> </td> </tr> <tr> <td><b>Sent Date:</b> <br><input type="text" name="sent_date" size="25" maxlength="30" value="'. $row['sent_date'] .'" /><br> </td> <td><b>Assign Date:</b> <br><input type="text" name="assgn_date" size="25" maxlength="30" value="'. $row['assgn_date'] .'" /><br> </td> <td><b>Interview Date:</b> <br><input type="text" name="interv_date" size="25" maxlength="30" value="'. $row['interv_date'] .'" /><br> </td> </tr> <tr> <td></b><br><input type="text" name="assgn_date" size="30" maxlength="30" value="Given to Reviewer" /> <br><input type="text" name="assgn_date" size="30" maxlength="30" value="Given to SUSPO" /> <br> <input type="text" name="assgn_date" size="30" maxlength="30" value="Given to Clerk" /> <br> <input type="text" name="assgn_date" size="30" maxlength="30" value="PSR Disclosed to Attn" /> <br> <input type="text" name="assgn_date" size="30" maxlength="30" value="PSR Disclosed to owner" /> </td> <td><b>Initials</b> <br><input type="text" name="dock" size="30" maxlength="30" /> <br> <input type="text" name="dock" size="30" maxlength="30" /> <br><input type="text" name="dock" size="30" maxlength="30" /> <br> <input type="text" name="dock" size="30" maxlength="30" /> <br> <input type="text" name="dock" size="30" maxlength="30" /></td> <td><b>Due Date:</b> <br><input type="text" name="due_rev" size="25" maxlength="30" value="'. $row['due_rev'] .'" /> <br> <input type="text" name="due_suspo" size="25" maxlength="30" value="'. $row['due_suspo'] .'" /> <br> <input type="text" name="due_clerk" size="25" maxlength="30" value="'. $row['due_clerk'] .'" /> <br> <input type="text" name="due_attny" size="25" maxlength="30" value="'. $row['due_attny'] .'" /> <br> <input type="text" name="due_" size="25" maxlength="30" value="'. $row['due_owner'] .'" /> </td> <td><br><input type="text" name="assgn_date" size="30" maxlength="30" value="Given to Reviewer" /> <br><input type="text" name="assgn_date" size="30" maxlength="30" value="Given to SUSPO" /> <br> <input type="text" name="assgn_date" size="30" maxlength="30" value="Given to Clerk" /> <br> <input type="text" name="assgn_date" size="30" maxlength="30" value="PSR Disclosed to Attn" /> <br> <input type="text" name="assgn_date" size="30" maxlength="30" value="PSR Disclosed to Owner" /> </td> <td><b>Actual Date:</b><br><input type="text" name="assgn_date" size="30" maxlength="30" value="" /> <br> <input type="text" name="assgn_date" size="30" maxlength="30" value="" /> <br> <input type="text" name="assgn_date" size="30" maxlength="30" value="" /> <br> <input type="text" name="assgn_date" size="30" maxlength="30" value="" /> <br> <input type="text" name="assgn_date" size="30" maxlength="30" value="" /> </td> </tr>; <td> <b>Employee Notes:</b> <br> <textarea name = "notes" rows=9 cols=100></textarea> </td> </tr>'; } echo '</table> </form>'; mysql_close(); // Close the database connection. ?> </tbody> </table> Hello! This is the code for the header of my blog. It isn't displaying the CSS correctly, and the links aren't working. I think there is something wrong with the PHP, but am totally blind. Any ideas? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> <title><?php wp_title('//', true, 'right'); ?> <?php bloginfo('name'); ?></title> <meta name="description" content="<?php bloginfo('description'); ?>" /> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/colours.css" type="text/css"/> <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" /> <link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" /> <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> <?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?> <?php wp_head(); ?> </head> <body id="top" class="<?php echo setColourScheme(); ?>"> <div id="header"> <div class="blog-name"><a href="<?php echo get_option('home'); ?>/"><?php bloginfo('name'); ?></a></div> <div class="description"><?php bloginfo('description'); ?> </div> <ul id="menu"> <li><a href="<?php echo get_option('home'); ?>/" <?php if(is_home()) {echo 'class="selected"';} ?>>HOME</a></li> <li><a href="http...com">MAG</a></li> <li><a href="http...com">ABOUT</a></li> <li class="last"><a href="http...com">SUBSCRIBE</a></li> </ul> <div class="clearboth"><!-- --></div> </div> </body> Thanks so much! Elvia Here's my website page with the Contact Form: http://www.3dmark3t.com/contact.html Now the problem is if you don't fill out any info it will have an error message with all the things but not the selection. when I get the email it shows if the user has selected something out of the selection box but it doesn't have an error message and it still goes through even if you don't select something. could someone please help me with my PHP form validation. PHP: Code: [Select] <?php if(isset($_POST['email'])) { // CHANGE THE TWO LINES BELOW $email_to = "user@domain.com"; $email_subject = "3DMark3t Contact:"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { if(isset($_POST['formGender']) ) { $errorMessage = ""; $var3dmodels = $_POST['3DModels']; $vargraphic_design = $_POST['Graphic Design']; $varweb_design = $_POST['Web Design']; $vartutorials = $_POST['Tutorials']; $varreport = $_POST['Report']; $varrequests = $_POST['Requests']; } died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $formGender = $_POST['formGender']; // required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!isset($_POST['formGender'])) { $errorMessage .= "<li>You forgot to select your Gender!</li>"; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "3DMark3t Contact:"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Select One: ".clean_string($formGender)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- place your own success html below --> Thank you for contacting us. We will be in touch with you very soon. <meta http-equiv="refresh" content="3; URL=http://www.3dmark3t.com" /> <?php } die(); ?> HTML: Code: [Select] <html> <head> </head> <body> <form name="htmlform" method="post" action="php/html_form_send.php"> <table width="450px"> </tr> <tr> <td valign="top"> <label for="first_name">First Name *</label> </td> <td valign="top"> <input type="text" name="first_name" maxlength="30" size="30"> </td> </tr> <tr> <td valign="top"> <label for="last_name">Last Name *</label> </td> <td valign="top"> <input type="text" name="last_name" maxlength="30" size="30"> </td> </tr> <tr> <td valign="top"> <label for="email">Email Address *</label> </td> <td valign="top"> <input type="text" name="email" maxlength="30" size="30"> </td> </tr> <tr> <td valign="top"> <label for="telephone">Telephone Number</label> </td> <td valign="top"> <input type="text" name="telephone" maxlength="30" size="30"> </td> </tr> <tr> <td valign="top"> <label for="select">Select One *</label> </td> <td valign="top"> <select name="formGender"> <option value="">Select...</option> <option value="3DModels">3DModels</option> <option value="Graphic Design">Graphic Design</option> <option value="Web Design">Web Design</option> <option value="Tutorials">Tutorials</option> <option value="Report">Report</option> <option value="Requests">Requests</option> </select> </td> </tr> <tr> <td valign="top"> <label for="comments">Comments *</label> </td> <td valign="top"> <textarea name="comments" maxlength="1000" cols="32.5" rows="6"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input type="submit" value="Submit"> </td> </tr> </table> </form> </body> </html> MySQL version 5.1.73-cll
I can't seem to get the inventory table to insert the information I have stared in an array any help would be appreciated!!
<?php $username = $_SESSION['username']; ini_set('display_errors',1); error_reporting(E_ALL); //include "php/db/db_config.php"; include "php/db/db_config.php"; include "php/db/item_connect.php"; $id = $items_id['id']; $player = $account_info['player_id']; //Update database $sql = mysqli_query($my_database,"INSERT INTO inventory ( player_id, username, id ) VALUES('$player', '$username', '$id')"); //echo values of item id echo "<div class=\"loot\">"; echo "<b>Required Level:" . $items_id['requ_level'] . "</b><br />"; echo "<b>Name:" . $items_id['name'] . "</b><br />"; echo "<b>Min Str:" . $items_id['min_str'] . "<br />"; echo "<b>Min Int:" . $items_id['min_int'] . "<br />"; echo "<b>Min Dex:" . $items_id['min_dex'] . "<br />"; echo "<b>Type:" . $items_id['type']. "<br />"; echo "<b>Min Physical Dmg:" . $items_id['min_dmg'] . "<br />"; echo "<b>Max Physical Dmg:" . $items_id['max_dmg'] . "<br />"; echo "<b>Min Magic Dmg:" . $items_id['mag_attk_min'] . "<br />"; echo "<b>Max Magic Dmg:" . $items_id['mag_attk_max'] . "<br />"; echo "<b>Phys Defense:" . $items_id['phy_def'] . "<br />"; echo "<b>Magical Defense:" . $items_id['mag_def'] . "<br />"; echo "</div>"; ?>I get no errors or notices and the info fields show up as being populated. I am using PHP 5.5 on windows 8 and I am trying to localize my website to multiple languages while everything is OK on remote host , the gettext function does not work correctly in my localhost. I have implemented the whole tutorial of http://www.sitepoint...applications-1/ step by step but it seems setlocale(LC_ALL, "en_US") fails and I don't know how to correct or install "en_US" in my system. when I use "en-US" instead of "en_US" the sellocale function does not return FALSE but again the gettext function return the original string.
Hello, I am pasting code below that isn't working corrrectly. One problem is the pagination. When I get more than 10 records, it will show the next 10 link but when I click on it, it just takes me back to an empty page with NO results. How do I fix this? Also where do I insert the block of code for a table to structure my results. As of now, the returned results are all over the page! Thanks! This is the code: Code: [Select] <?php // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["1st_field"]; echo "$count.) $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> MOD EDIT: [code] . . . [/code] BBCode tags added. Hey guys, I don't know why but the following script is not working for me. Its a simple login script which check the validity of username and password and based on the uses header function to redirect the user. Please have a look at the script Code: [Select] <?php include('dbinfo.inc'); if(empty($_POST['username']) || empty($_POST['pword'])) { header('Location: http://localhost/vits/index.php?login=error'); } else { $username = $_POST['username']; $pword = $_POST['pword']; $actype = $_POST['actype']; $connect = mysql_connect($host,$dbuser,$password) or die("Cannot connect to DB"); mysql_select_db($dbname,$connect); $sql = "select * from memberinfo where username='$username'"; $result = mysql_query($sql,$connect); $row = mysql_fetch_assoc($result); } if($row['username'] == $username && $row['pword'] == $pword && $row['actype'] == $actype) { session_start(); $_SESSION['username'] = $_POST['username']; $_SESSION['loggedin'] = TRUE; $_SESSION['actype'] = $_POST['actype']; header('Location: http://localhost/vits/index.php?login=correct'); } else { header('Location: http://localhost/vits/index.php?login=incorrect'); } ?> Now the problem is it never succeeds i.e. it never goes into the if block where the checking is being done for username and password and of course actype. No matter what I enter in login information it always throws me to this http://localhost/vits/index.php?login=incorrect' Please help as am not able to sort out this problem if($value != "0"){ $errors[] = 'Invalid option chosen'; }$value is a string. IF $value equals '00', it doesn't work why? It does not equal 0? I'm trying to check if a value equalis 1 or 0. LITERALLY the string has to be 1 or 0, if not I need to error out. Why is this so difficult? How does 2 zero's (00) = 0? Doesn't make sense. Especially when it's matching 2 STRINGs.. If it were a numeric value I could see PHP saying 00 might equal 0. But how does 00 and 0 equal the same thing? makes no sense. Edited by Monkuar, 23 January 2015 - 06:27 PM. I am using the following request on my site (index.php) Code: [Select] $compass = $_REQUEST['compass']; I wanted to use an if statement to echo an error message if $compass was anything other than north,east,south or west. However the code im using is constantly displaying the error message even when /index.php?compass=north etc. Can anyone see what I have done wrong? Code: [Select] if (($compass != "north") || ($compass != "east") || ($compass != "south") || ($compass != "west")) { echo '<strong>Stop cheating!</strong>'; } I want to make it so that whoever is sending the fame (sender) doesn't send it to themselves (receiver). However, I can't get it to block that. Everything else works, so something must be up with that specific requirement. Any help would be appreciated! Thanks! <?php //error_reporting(E_ALL); //ini_set('display_errors', 1); include("fightfunc.php"); include("lib.php"); define("PAGENAME", "GFame"); $player = check_user($secret_key, $db); $x = $player->username; if($_SESSION['234asdfas']){$y = $_SESSION['234asdfas'];}else{echo 'Error: You do not have a session variable set'; exit;} $command = 1; if (isset($_POST["sendfame"])) { $maxgfame = $player->gfame; include("tmpconfig.php"); $checkquery = mysql_query("SELECT * FROM `users` WHERE `username`='".ucwords(strtolower($_POST['receiver']))."'"); extract($_POST); if($sender == "") { echo "You must put a sender's name in the text box.";//The amount would create a negative balance - implement error condition } elseif ($gfamesent == 0) { echo "Enter an amount greater than 0."; } elseif ($gfamesent < 0) { echo "Enter an amount greater than 0."; } elseif (!is_numeric($gfamesent)) { echo "Enter a numerical amount!"; } elseif ($gfamesent == "") { echo "Enter a numerical amount!"; } elseif ($receiver == "") { echo "You must put a name in the Receiver field."; } elseif ($gfamesent > $maxgfame) { echo "You don't have that much gfame to give."; } elseif ($receiver == $sender) { echo "You can't give gfame to yourself."; } elseif (mysql_num_rows($checkquery) == 0) { echo "That player does not exist."; } else { $query = $db->execute("UPDATE `users` SET `gfame`=? WHERE `id`=?", array($player->gfame - 1, $player->id)) or die("querya failed: ". mysql_error()); if($query) $qry = $db->execute("select * from `users` where `username`=?", array(ucwords(strtolower($_POST['reciever'])))) or die("qry failed: ".mysql_error()); $rw = $qry->fetchrow(); if($qry){ $query2 = $db->execute("UPDATE `users` SET `fame`=? WHERE `username`=?", array($rw['fame'] + 1, $rw['username'])) or die("query2 failed: ". mysql_error()); if($query2){ echo("<br><br>You have successfully transfered your gfame over.<br>"); } } }} $player = check_user($secret_key, $db); ?> <br /><br /><blockquote><center>GFame is fame you can award 1 other person for what you feel is "noteworthiness". In otherwords, if you feel someone is doing a superb job of role-playing their character, you can "reward" them for their actions. You may send 1 gfame point per day. And no, you cannot send it to yourself.</center></blockquote><br /><br /> <table width="100%"> <tr> <td colspan="2"><fieldset> <legend>Transfer GFame:</legend> You have <b><?=$player->gfame?></b> GFame to give.<br /> <form method="post" action="gfame.php"> <input name="sender" type="hidden" value="$player->id" id="sender" /> <input type="submit" value="Transfer" name="sendfame"> <input type="text" value="1" name="gfamesent"> to <input name="receiver" type="text" id="receiver"> </form> </fieldset></td> </tr> </table> Ok, I have most of my CMS done. I have the data being displayed from the database. I also have the code working to create new pages and menu items. However, I am faced with two issues. 1. The menu will not display horizontally. This is not a major issue but would be good for people who use my script to be given that option if they want to modify the template. 2. Each page has an ID that is created in the database. The script creates a new page and tells the database to define a new ID for each page. For example page.php?id=2 This works fine. But, if I go to say page.php?id=2 and then click on the Home button to go back to the index, the home button also inherits the same URL as the page with the ID. I also noticed that any link on the page with the id= defined, also inherits that URL. I am unable to figure it out and was hoping someone here could help. Here is the page.php code: Code: [Select] <?php /***************************** * * Name: osPHPSite * Version: 0.0.1 * Developer: Dan O'Riordan * Email: dan@vichost.com * Copyright (c) 2010 VicHost * Date: September 2010 * Website: www.osphpsite.com * Licence: GNU/GPL v3 * ******************************/ include "language/english/english.php"; include "includes/settings.php"; include "includes/version.php"; include "includes/config.php"; include "templates/default/header.tpl"; include "nav.php"; ?> <div class="art-content-layout"> <div class="art-content-layout-row"> <div class="art-layout-cell art-content"> <div class="art-post"> <div class="art-post-body"> <div class="art-post-inner art-article"> <?php //if no id defined then load the home page. if(isset($_GET['id'])){ $id = $_GET['id']; if(!is_numeric($id)){ include "includes/404.php"; exit; } database_connect(); $query = "SELECT * from content where id = $id;"; $echo = mysql_error(); $result = mysql_query($query); $num_rows = mysql_num_rows($result); if ($num_rows == 0) { include "includes/404.php";; exit; } while ($row = mysql_fetch_assoc($result)) { $title = $row['title']; $text = $row['text']; $description = $row['description']; $keywords = $row['keywords']; } } include("includes/body.php"); ?> </div> </div> </div> </div> </div> </div> <?php include "templates/default/footer.tpl"; ?> This creates the pages defined in the database and also tells nav.php to create a new menu item. And here is the nav.php Code: [Select] <?php database_connect(); $query = "SELECT * from content WHERE status = 1 ORDER by position;"; $error = mysql_error(); if (!$result = mysql_query($query)) { print "$error"; exit; } $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $id = $row['id']; $menutitle = $row['menutitle']; //if no menu title entered, then use the title. if ($menutitle == ""){ $menutitle = $row['title']; } $startpage = $row['startpage']; $href = "page.php?id=$id"; if ($startpage == 1) { $href = ""; } ?> <ul class="art-vmenu"> <li> <a href="<?php echo $href; ?>"><span class="l"></span><span class="r"></span><span class="t"><?php echo $menutitle; ?></span></a> </li> </ul> <?php } ?>The HTML part of this relies on CSS for the layout. At the moment I have the menu displayed virtically, until I can figure out the horizontal bit body.php: Code: [Select] <?php database_connect(); $navquery = "SELECT * from content WHERE status = 1 ORDER by position;"; $navresult = mysql_query($navquery); while ($row = mysql_fetch_assoc($navresult)) { $navid = $row['id']; $menutitle = $row['menutitle']; $startpage = $row['startpage']; //if no menu title entered, then use the title. if ($menutitle == ""){ $menutitle = $row['title']; } if ($startpage == 1) { $href = "/"; }else{ $href = "page.php?id=$navid"; } $startpage = NULL; } echo $text; ?> Can anyone see where I am going wrong? Any help would be appreciated. if ($content['size'] == "sizel") {$content['size'] = "Large";} echo "{$content['size']}"; This doesn't work and just echo's "sizel". Why? Hey guys, I'm using a PHP form for my website & I can't get it to send the email correctly, all it send me is the first and last name, but none of the other boxes, any help? Also how can I secure it?
This is the PHP file:
<!DOCTYPE html> Hello PHP Wizards, i wonder if anyone can help, Ive got an associative array set up with a bunch of items, the idea is to compare the array items with items from a form using $_POST. So far ive got the items displaying from the form as follows Code: [Select] <?php while ($client_prices = each($_POST)) { /* sets the name of the array to $client_prices for easy identification */ echo $client_prices['key']; /* Displays the keys withing the $client_prices array */ echo ' - '; echo $client_prices['value']; /* Displays the values within the $client_prices array */ echo '<br />'; } ?> and for the sake of it ill display the array ive set up on the server side using similar code : Code: [Select] <?php while ($server_prices = each($coffee_prices)) { /* sets the name of the array to $server_prices for easy identification */ echo $server_prices['key']; /* Displays the keys withing the $server_prices array */ echo ' - '; echo $server_prices['value']; /* Displays the values within the $server_prices array */ echo '<br />'; } ?> now, what i want to do is make sure that the keys (name of items) and the values (cost of items) from the client side are the same as the keys and values ive set on the server. so i created an if statement : Code: [Select] <?php if( $client_prices['key'] === $server_prices['key'] && $client_prices['value'] === $server_prices['value'] ) echo 'Prices Match'; else echo '<h2>Oops! Somthing Has Gone, Please Call Us To Place Your Order</h2>'; ?> so i thought i had it all working when as it came back with 'prices match', i thought all is good. however when i purposely change the value of one of the items in my server side array so it will be different from the incoming client value, it still says 'prices match' when they clearly don;t? Anyone help would be appreciated p.s. im fairly new to php, and this is for my learning, not a real client. Hi, i am trying to add a very simple shopping cart script to my site, and the session is simply used to keep the contents of the shopping cart, yet its not working properly! Ok ignoring the layout issues with the cart here is the issues. Only two links to the same script First one is a link to the shopping cart with an action to add the item ID to it. http://www.heliuk.co.uk/index.php?n=pages/shop-cart-action&id=1&action=add This works, it adds the item to the session "cart", if that's successful it then shows the cart from the session. But if i just go to the shopping cart with no actions (so just to view it) it shows no items http://heliuk.co.uk/index.php?n=pages/shop-cart-action And what this is doing is checking it the cart is empty, if not show the cart, if it is then show nothing, which is what happening. But if you go back to the first link and add the item again, it is adding it on to the cart so the session is there and working? I don't understand what's happening! Here the shopping cart page. Code: [Select] <?php error_reporting(E_ALL ^ E_NOTICE); $product_id = $_GET["id"]; //the product id from the URL $action = $_GET["action"]; //the action from the URL //if there is an product_id and that product_id doesn't exist display an error message if($product_id && !productExists($product_id)) { die("Error. Product Doesn't Exist"); } switch($action) { //decide what to do case "add": $_SESSION['cart'][$product_id]++; //add one to the quantity of the product with id $product_id break; case "remove": $_SESSION['cart'][$product_id]--; //remove one from the quantity of the product with id $product_id if($_SESSION['cart'][$product_id] == 0) unset($_SESSION['cart'][$product_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items. break; case "empty": unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart. break; } ?> <table class='main' cellspacing='1' cellpadding='4'> <tr class='head'> <td class='head' colspan='2'>HeliUK Shop - Your Shopping Cart</td> </tr> <tr> <td style='Text-align:left;' class='con1' colspan='2'> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <?php error_reporting(E_ALL ^ E_NOTICE); if($_SESSION['cart']) { //if the cart isn't empty //show the cart echo "<table border=\"1\" padding=\"0\" width=\"100%\">"; //format the cart using a HTML table //iterate through the cart, the $product_id is the key and $quantity is the value foreach($_SESSION['cart'] as $product_id => $quantity) { //get the name, description and price from the database - this will depend on your database implementation. //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection $sql = sprintf("SELECT title, description, price FROM items WHERE id = %d;", $product_id); $result = mysql_query($sql); //Only display the row if there is a product (though there should always be as we have already checked) if(mysql_num_rows($result) > 0) { list($name, $description, $price) = mysql_fetch_row($result); $line_cost = $price * $quantity; //work out the line cost $total = $total + $line_cost; //add to the total cost echo "<tr>"; echo "<td style=\"border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px\" width=\"145\">"; echo "<font face=\"Tahoma\" size=\"2\">$quantity</font></td>" ; echo "<td style=\"border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px\" width=\"693\">"; echo "<font face=\"Tahoma\" size=\"2\">$name</font></td>" ; echo "<td style=\"border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px\" width=\"162\">"; echo "<font face=\"Tahoma\" size=\"2\">$line_cost</font></td>" ; echo "<td style=\"border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px\">"; echo "<p align=\"center\"><a href=\"$_SERVER[PHP_SELF]?action=remove&id=$product_id\">" ; echo "<img border=\"0\" src=\"empty-cart.jpg\" width=\"24\" height=\"24\"></a></td>" ; echo "</tr>"; } } //show the total echo "<tr>"; echo "<td colspan=\"0\" align=\"right\">Total</td>"; echo "<td align=\"right\">$total</td>"; echo "</tr>"; //show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation echo "<tr>"; echo "<td colspan=\"0\" align=\"right\"><a href=\"$_SERVER[PHP_SELF]?action=empty\" onclick=\"return confirm('Are you sure?');\">Empty Cart</a></td>"; echo "</tr>"; echo "</table>"; }else{ //otherwise tell the user they have no items in their cart echo "You have no items in your shopping cart."; } ?> </table> </td> </tr> </table> <? //function to check if a product exists function productExists($product_id) { //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection $sql = sprintf("SELECT * FROM items WHERE id = %d;", $product_id); return mysql_num_rows(mysql_query($sql)) > 0; } ?> Hey all! I'm writing a simple script to scan a local directory named 'files' and all sub directories of 'files', adding each file to a database in the same table. To do this, I'm using scandir on the current working directory/files to start, and iterating over each file in a loop, but if the file is a directory, I append the directory name to the cwd/files and call scandir on that, creating a list of files in the subfolder, and then I call my addFiles() function recursively, with this as the argument. As of now, it just stops at the second call to addFiles. It adds all the top level files fine, stops there. That's where all my print_r() lines have gotten me. Here's my code... <!-- To change this template, choose Tools | Templates and open the template in the editor. --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <?php include 'DBConnect.php'; $db = new DBConnect() or die("Can't connect to DB"); $conn = $db->getConn(); mysql_select_db('download', $conn) or die("Can't select DB"); $dir = getcwd(); $dir = $dir . '\files' . "\\"; $fid = 1; $dir = addslashes($dir); $files = scandir($dir); echo $fid . " "; echo $dir; function addFiles($files) { global $dir; global $conn; global $fid; unset($files[0]); unset($files[1]); print_r($files); foreach ($files as $aFile) { if (is_file($dir.$aFile)) { echo "<li> $aFile </li>"; $query = "INSERT INTO files (file_id, file_path, file_name) values ($fid, '$dir', '$aFile')"; mysql_query($query, $conn) or die("Something wrong with query"); $fid = $fid + 1; } else if (is_dir($dir.$aFile)) { $fid = $fid + 1; $aDir = $dir . $aFile . "\\"; echo $dir; addFiles(scandir($dir.$aFile)); } } } addFiles($files); ?> </body> </html> Thanks in advance for any ideas. Also, if I'm approaching this problem completely wrong, let me know! I just came up with this and I feel like it should work... Hi im pretty new to php but I was following a tutorial for a commenting system and implemented it onto my blog page. Anyway the problem I have is that as you go down the page each blog post displays its own comments + the comments for the posts above it. I have checked the database and the data seems to link the correct comments to the correct posts so I am confused to why this is happening. I have looked over my code and cant seem to find a problem (probably because I suck!). Here is the code for the blog page... Code: [Select] <?php include_once ("scripts/checkuserlog.php"); include_once ("scripts/connectToMysql.php"); include_once ("functions/agoTime.php"); $myObject = new convertToAgo; $username = ''; $errorMsg = ''; $successMsg = ''; $date = date("m.d.y"); if (isset($_GET['id'])) { $id = preg_replace('#[^0-9]#i', '', $_GET['id']); } else if (isset($_SESSION['idx'])) { $id = $logOptions_id; } else { header("location: index.php"); exit(); } $id = preg_replace('#[^0-9]#i', '', $id); $sql = mysql_query("SELECT * FROM members WHERE id='$id' LIMIT 1"); $existCount = mysql_num_rows($sql); if ($existCount == 0) { header("location: index.php?msg=user_does_not_exist"); exit(); } while($row = mysql_fetch_array($sql)){ $username = $row["username"]; } if(isset($_POST['workoutName'])){ $workoutName = $_POST['workoutName']; $workoutDescription = $_POST['workoutDescription']; if ((!$workoutName) || (!$workoutDescription)) { $errorMsg = 'Please fill in both fields'; } else { $insertBlog = mysql_query("INSERT INTO blog (userid, workoutName, workoutDescription, datetime) VALUES ('$id', '$workoutName', '$workoutDescription', now())") or die(mysql_error()); if ($insertBlog){ $successMsg = '<span class="errorMsg">Workout blogged successfully</span>'; } else { $errorMsg = '<span class="errorMsg">Problems arose during the information exchange, please try again later.</span>'; } } } $getBlog = mysql_query("SELECT * FROM blog WHERE userid='$id' ORDER BY id DESC"); $blogEntries = mysql_num_rows($getBlog); if($blogEntries < 1){ $blogDisplay = '<span class="blogName">' .$username. ' has not blogged a workout yet</span>'; } else { while($row = mysql_fetch_array($getBlog)){ $blogEntryId = $row["id"]; $sql_comment = mysql_query("SELECT * FROM blog_comments WHERE post_id='$blogEntryId' ORDER BY id ASC"); $countComment = mysql_num_rows($sql_comment); if($countComment > 0){ while($row2 = mysql_fetch_array($sql_comment)){ $comment_user_id = $row2["comment_user_id"]; $sql_comment_username = mysql_query("SELECT username FROM members WHERE id='$comment_user_id' LIMIT 1"); while($row3 = mysql_fetch_array($sql_comment_username)){ $comment_username = $row3["username"];} $post_id = $row2["post_id"]; $commentBody = $row2["comment_body"]; $commentDate = $row2["comment_date"]; $displayCommentList .= '<div>' .$comment_username. ' - ' .$commentBody. ' - ' .$commentDate. '</div>'; } } else { $displayCommentList = ''; } $workoutName = $row["workoutName"]; $workoutDescription = $row["workoutDescription"]; $blogDate = $row["datetime"]; $convertedTime = ($myObject -> convert_datetime($blogDate)); $blogDate = ($myObject -> makeAgo($convertedTime)); $blogDisplay .= '<table width="950px"><tr bgcolor="#DBE4FD"><td><span class="blogName">' .$workoutName. '</span> » <span class="blogDate">' .$blogDate. '</span></td></tr> <tr bgcolor="#F1F4FE"><td><span class="blackText">' .$workoutDescription. '</span></td></tr> <tr bgcolor="#DBE4FD" valign="top"><td>' .$displayCommentList. '</td></tr> <div id="new_comment' .$blogEntryId. '" style="display:none"></div> <tr><td><textarea id="comment' .$blogEntryId. '"></textarea><input type="submit" value="Comment" onclick="javascript:SendComment(\''.$blogEntryId.'\');" /></td></tr>'; if(isset($_SESSION['id'])&&$_SESSION['id']==$id){ $blogDisplay .= '<tr bgcolor="#DBE4FD"><td><a href="editBlogPost.php?id=' .$blogEntryId. '"><span class="blackText">Edit Post</span></a> &#8211; <span class="blackText">Delete Post</span></td></tr></table><br /><br />'; } } } if(isset($_POST['deleteButton'])){ $deleteBlog = mysql_query("DELETE FROM blog WHERE id='$blogEntryId'"); if($deleteBlog){ $successMsg = 'Blog entry deleted successfully'; } else { $errorMsg = 'Could not process your request, please try again later'; } } ?> <?php if (isset($_SESSION['id'])&&$_SESSION['id']==$id) { $blogForm = '<table bgcolor="#DBE4FD" width="950px"> <form action="member_blog.php" method="post" enctype="multipart/form-data"> <tr> <td width="200px"><span class="blackText">Workout Name:</span></td><td width="650px"><input name="workoutName" type="text" id="workoutName" /> <span class="blackText">Date: ' .$date. '</span></td></tr> <tr> <td><span class="blackText">Workout Description:</span></td><td><textarea name="workoutDescription" cols="75" rows="10" id="workoutDescription" /></textarea></td></tr> <tr><td><input name="submitBlog" id="submit" type="submit" value="Blog!" /></td><td><span class="errorMsg">' .$errorMsg. '' .$successMsg. '</span></td> </tr> </form> </table>'; } else { $blogForm = ''; } ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo ("$username"); ?>'s Blog</title> <link href="style/layout.css" rel="stylesheet" type="text/css" /> <link href="style/main.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> function SendComment(blogEntryId){ var comment_txt = $("#comment"+blogEntryId).val(); if(comment_txt == ""){ alert("Please enter a comment"); } else { $.post("scripts/blogComment.php", {comment: comment_txt, blogId: blogEntryId} ,function(data){ $("#new_comment"+blogEntryId).html(data); $("#new_comment"+blogEntryId).slideDown(300); }); } } </script> </head> <body> <div id="container"> <?php include_once ("bannerFiles/bannerTemplate.php"); ?> <?php include_once ("bannerFiles/bannerMenu.php"); ?><br /> <div id="content"> <span class="profileUsername"><?php echo ("$username"); ?>'s Workout Blog</span><br /><br /> <?php echo ("$blogDisplay"); ?><br /><br /> <?php echo ("$blogForm"); ?> </div><br /><br /> <?php include_once ("footerFiles/footerTemplate.php"); ?> </div> </body> </html> ...and here is the code for the blogComment.php page Code: [Select] <?php session_start(); include_once ("connectToMysql.php"); if(isset($_POST['comment'])){ $comment = $_POST['comment']; $blogId = $_POST['blogId']; $comment_user_id = $_SESSION['id']; $username = $_SESSION['username']; $sql = mysql_query("INSERT INTO blog_comments (comment_body, post_id, comment_user_id, comment_date) VALUES ('$comment', '$blogId', '$comment_user_id', now())"); echo '<div>' .$username. ' - ' .$comment. ' - Just Now</div>'; } else { echo "Failure"; } ?> Thanks in advance for any help I have directories containing images. If an Image called front.jpg exists then I want that to display - if it doesn't then I want it to display any random image from the directory. All the bits works individually. but for some reason, even when front.jpg exists - it still displays a random image from the else statement. Can you see an error? Code: [Select] $frontimage = "/hotelimages/". $img_dir . "/" . $front . $ext; ?> <div id="topframe"> <?php if (file_exists($frontimage)) {?><img src="/image.php?width=245&height=245&cropratio=1:1&image=/<?php echo $img_folder.$image ;?>" alt="<?php echo ucwords($row_rs_properties['est_name']);?>" class="fltrt" border="1"/><? ;} else { ?> <img src="/image.php?width=245&height=245&cropratio=1:1&image=<?php echo "/hotelimages/". $img_dir . "/" . $front . $ext; ?>" alt="<?php echo ucwords($row_rs_properties['est_name']);?>" class="fltrt" border="1"/> <?php ;} ?> </div> Hiya peeps! I have built this. <?php class extract { private $link; private $rec; public function __construct() { } public function __init($link, $rec = 0) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$link); curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $this->_data = curl_exec($ch); curl_close($ch); $this->_emails = array(); if($rec == 1) { if(preg_match_all('/((?:http|https):\/\/(?:www\.)*(?:[a-zA-Z0-9_\-]{1,15}\.+[a-zA-Z0-9_]{1,}){1,}(?:[a-zA-Z0-9_\/\.\-\?\&\:\%\,\!\;]*))/', $this->_data, $urls)) { foreach($urls[0] as $k => $v) { $this->__init($v, 1); } } } return $this->emails(); } public function emails() { if(preg_match_all('/(\w+\.)*\w+@(\w+\.)*\w+(\w+\-\w+)*\.\w+/', $this->_data, $emails, PREG_SET_ORDER)) { foreach($emails as $dk => $dv) { foreach($dv as $fk => $fv) { if(preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $fv)) { $this->_emails[] = $fv; } } } } return $this->_emails; } public function multi_unique($array) { foreach ($array as $k => $na) { $new[$k] = serialize($na); $uniq = array_unique($new); } foreach($uniq as $k => $ser) { $new1[$k] = unserialize($ser); } return $new1; } } $go = new extract(); $done = $go->__init($_POST['site'], $_POST['deep']); print_r($done); ?> <center><form action="#" method="post"> Site:<br /><input type="text" name="site"><br /><br /> Go-Deep:<br /><select name="deep"><option value="0" selected>No</option><option value="1">Yes</option></select><br /><br /> <input type="submit" name="submit"> </form></center> It works, but only on one URL, I have setup a html page containing an email address and a link to another page containing an email address, so technically it should return two email addresses. But it doesn't, it only displayed the email address on the url that is inputted. Does anyone have any idea why? Many thanks, James. |