Jump to content

jcbones

Staff Alumni
  • Posts

    2,653
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by jcbones

  1. <?php require_once('access.php'); $conn = mssql_connect ("localhost", "bbpublic", "hdyet65e42") or die ('I cannot connect to the database because: ' . mssql_error()); mssql_select_db("********"); $vals = $_POST; $id = $_SESSION['id']; $sql = "UPDATE trinitySBteam SET homephone='$vals[homephone]',cellphone='$vals[cellphone]',email='$vals[email]',position1='$vals[position1]',position2='$vals[position2]',position3='$vals[position3]',comments='$vals[comments]' WHERE player_id = $id"; mssql_query($sql, $conn); mssql_close($conn); //Update Session Variables $_SESSION['homephone'] = $vals['homephone']; $_SESSION['cellphone'] = $vals['cellphone']; $_SESSION['email'] = $vals['email']; $_SESSION['position1'] = $vals['position1']; $_SESSION['position2'] = $vals['position2']; $_SESSION['position3'] = $vals['position3']; $_SESSION['comments'] = $vals['comments']; header("Location: viewplayer.php"); ?>
  2. I would put the value into a COOKIE, instead of a SESSION. That way they will see the same color each time they visit your site.
  3. I get no parse errors on that file.
  4. Try this: I made a few changes, don't know if they will affect the script behavior or not. <?php //# Include the connections script to make a database connection. include("inc/connect.inc"); //# The form should post to itself. if ( $_POST['submit'] ) { $valid = 1; $venue_name = $_POST['venue_name']; if ( empty($venue_name) ) { $valid = 0; $venue_name_error = '<div class="formerror">Please Enter your Fishery Venue Name.</div>'; } $address_1 = $_POST['address_1']; if ( empty($address_1) ) { $valid = 0; $address_1_error = 'Please enter the first line of your address'; } $address_2 = $_POST['address_2']; $address_3 = $_POST['address_3']; $town = $_POST['town']; if ( empty($town) ) { $valid = 0; $town_error = 'Please enter your town/city'; } $county = $_POST['county']; if ( empty($county) ) { $valid = 0; $county_error = 'Please select your county'; } $postcode = $_POST['postcode']; if ( empty($postcode) ) { $valid = 0; $postcode_error = 'Please Enter your Postcode'; } $email = $_POST['email']; $telephone_1 = $_POST['telephone_1']; if ( empty($telephone1) ) { $valid = 0; $telephone1_error = 'Please Enter your Main Contact Number'; } $telephone_2 = $_POST['telephone_2']; $fax = $_POST['fax']; // End of error checking, all fields covered. if ( $valid == 1 ) { # setup SQL statement $SQL = " INSERT INTO dbtable "; $SQL .= " (venue_name, address_1, address_2, address_3, town, county, postcode, email, telephone_1, telephone_2, fax) VALUES "; $SQL .= " ('$venue_name', '$address_1', '$address_2', '$address_3', '$town', '$county', '$postcode', '$email', '$telephone_1', '$telephone_2', '$fax') "; #execute SQL statement $result = mysql_query( $SQL,$connection ); # check for error if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } else { header("Location: http://www.domain.com/admin/admin.html"); exit; } } } ?>
  5. http://www.iopus.com/guides/winscheduler.htm
  6. This line should be: echo "<td class='style1' align='center' valign='middle'><input type='checkbox' name='entry[]' value='" . $row[5] . "' id='check" . $row[5] . "'/></td>"; And the PHP should be. <?php if (isset($_POST['delete'])){ if(is_array($_POST['entry'])) { foreach ($_POST['entry'] as $id) { $sql = "DELETE FROM customer_order WHERE id='$id'"; $query = mysql_query($sql); } } } ?>
  7. I suppose you are using preg_replace() to change your bbcode to HTML? If so, add the i modifier for case insensitive matching. EX. $str = 'FOO'; $pattern = '/foo/i'; if(preg_match($pattern,$str)) //true
  8. In order to remove them without them submitting a page is a two fold answer. You could run your delete query: $logout = time() - 900; $sql = "DELETE FROM `online` WHERE `lastonline` < '$logout'"; This will delete all users that haven't accessed any pages within 15 minutes (I currently use this method). The other involves crontab. http://adminschoice.com/crontab-quick-reference
  9. Try it like this: $month = 'april'; $year = 2010; echo date('d',strtotime('+0 week thursday ' . $month . ' ' . $year));
  10. This may help you out. http://php.net/manual/en/function.money-format.php
  11. <?php $result2 = mysql_query("SELECT * FROM sponsored_ads WHERE keywords2 LIKE '$keyword' LIMIT 3"); if(mysql_num_rows($result2) > 0) { while($r = mysql_fetch_assoc($result2)) { //call the rows. $domain = $r['domain']; } } else { echo 'There are no rows to print to the page!'; } ?>
  12. Try something like this: <?php $splitdate = explode(" ",trim($date)); echo str_replace(',','',$splitdate[1]); // prints "Day"; echo "<br />"; // prints space; echo $splitdate[0]; // prints "Month"; ?>
  13. You could also use: unset($arr[2]); sort($arr); print_r($arr);
  14. I would save the return of the function to a variable, so I wouldn't have to call it more than once. Not only that, but using num_rows() to return the amount of friends is flawed logic, unless you are specifically limiting your users to 12 friends (The LIMIT from your query). Other than that, if the query returns 0 results, the WHILE loop will NOT run.
  15. Moving back a year makes it count the leap year, so dropping a day is correct. As the extra day is counted in the leap year. The only problem I'm encountering right now, is it is losing 1 hour, if the start date is in a certain range. Although I understand your mistake on this one, as I tried 4 hours to get it to quit dropping the day. Then I got a calendar out, and started counting it up.
  16. Try: In Login: if($row['Activated'] > 0) { $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['s_name'] = $row['Name']; $time = time(); $_SESSION['lastonline'] = $time; $insertuser="INSERT INTO online(Username,lastonline) values('$username','$time')"; mysql_query($insertuser) or die("Could not login insert user"); header("Location: index.php"); } else { header("Location: l_error.php"); } each page: //else else { $username = $_SESSION['s_username']; $time = time(); $updateonline = (isset($_SESSION['lastonline'])) ? "Update online set lastonline='$lastonline' WHERE username='$username'" : "INSERT INTO online(Username, lastonline) VALUES('$username','$time')"; $_SESSION['lastonline'] = $time; mysql_query($updateonline) or die("Could not update online"); }
  17. Try this, and pay attention to the note above $start, as any other format will not work. <?php //set real dates for start and end, otherwise *nix the strtotime() lines. //$return 'days' will return days/hours/minutes/seconds. //$return 'hours' will return hours/minutes/seconds. //$return 'minutes' will return minutes/seconds. //$return 'seconds' will return seconds. function timeDifference($start,$end,$return='decade') { $ex = explode('-',$start); $m = ($ex[1] < 10) ? (int)substr($ex[1],1,1) : (int)$ex[1]; $y = (int)$ex[0]; $months = array(1 => 2678400, 2=>2419200, 3=>2678400, 4=>2592000, 5=>2678400, 6=>2592000, 7=>2678400, 8=>2678400, 9=>2592000, 10=>2678400, 11=>2592000, 12=>2678400); $lyears = array(2000,2004,2008,2012,2016,2020,2024,2028,2032,2036,2040, 2044,2048,2052,2056,2060,2064,2068,2072,2076,2080,2084, 2088,2092,2096); $start = strtotime($start); $end = strtotime($end); $difference = max($end, $start) - min($end,$start); $time = NULL; //calculate time difference. switch($return) { case 'decade': $dy = $y; $decade = NULL; for($i = 1; $i <= 10; $i++) { @$dyear += (in_array($dy,$lyears)) ? 31622400 : 31536000; ++$dy; } $decade = floor($difference/$dyear); $difference = $difference % $dyear; $time['decade'] = $decade; case 'year': $ty = $y; $tm = $m; $year = NULL; while($difference >= 31536000) { @$tyear = (in_array($ty,$lyears)) ? 31622400 : 31536000; if($difference >= $tyear) { @$year++; $difference = $difference - $tyear; } ++$ty; } $time['year'] = $year; case 'month': $month = NULL; while($difference > 2419200 || (!in_array($y,$lyears) && $m == 2 && $difference == 2419200)) { if(in_array($y,$lyears, true) && $m === 2) { @$month += ($difference >= 2505600) ? 1 : 0; $difference = $difference - 2505600; } else { @$month += ($difference >= $months[$m]) ? 1 : 0; $difference = $difference - $months[$m]; } $y = ($m == 12) ? ++$y : $y; $m = ($m == 12) ? 1 : ++$m; } $time['month'] = $month; case 'week': $week = floor($difference/604800); $difference = $difference % 604800; $time['week'] = $week; case 'days': $days = floor($difference/86400); $difference = $difference % 86400; $time['day'] = $days; case 'hours': $hours = floor($difference/3600); $difference = $difference % 3600; $time['hour'] = $hours; case 'minutes': $minutes = floor($difference/60); $difference = $difference % 60; $time['minute'] = $minutes; case 'seconds': $seconds = $difference; $time['second'] = $seconds; } if(is_array($time)) { if($start > $end) { foreach($time as $key => $value) { if($value > 0) { if($value > 1) { $key = $key . 's'; } return $value . ' ' . $key . ' '; } } } elseif($end > $start) { foreach($time as $key => $value) { if($value > 0) { if($value > 1) { $key = $key . 's'; } @$output .= $value . ' ' . $key . ' '; } } } } return $output; } //Time MUST be in format YYYY-MM-DD (optional) H:M:S (hours:minutes:seconds); $start = '2009-09-19'; echo timeDifference($start,date('Y-m-d H:i:s')); ?>
  18. The reason you are seeing this difference, is the function sets a months time as 30 and one-half days. So, it only returns a close approx. amount of time. I will get the function dead accurate just for you. Give me a second.
  19. At the top of the script: $timezone = 'America/Los_Angeles'; //Change to your timezone. date_default_timezone_set($timezone); Timezones accepted. http://www.php.net/manual/en/timezones.php
  20. The @ suppresses any errors or notices that you may get. Originally I was't pre-declaring the variable, so you would get a notice. It is not needed now. The $$ = http://php.net/manual/en/language.variables.variable.php
  21. At the bottom of the script, change the value of $start. It will do the rest.
  22. Javascript is browser based, PHP is server based. You cannot call a PHP function with Javascript. However you can stop the active link with Javascript. <script type="text/javascript"> <!-- function confirmSubmit() { var agree=confirm("Are you sure you wish to delete?"); if (agree) return true ; else return false ; } //--> </script> <a onclick="return confirmSubmit();" href="?delete=<?php echo $id; ?>">Delete</a>
  23. I added some comments to help you out. Moreover, if you aren't using a good text editor: I suggest Notepad++. It will highlight the syntax for you and help with brackets, and parenth. <?php //Check to make sure the submit button was clicked. if (isset($_POST['submit'])) { //boolean logic (0/false or 1/true) //reads as $this_variable = (this_condition) ? is_true : is_false; //Same as: //if(isset($_POST['score_1'])) { $score_1 = $_POST['score_1']; } //else { $score_1 = ''; } $score_1 = (isset($_POST['score_1'])) ? $_POST['score_1'] : ''; $score_2 = (isset($_POST['score_2'])) ? $_POST['score_2'] : ''; $score_3 = (isset($_POST['score_3'])) ? $_POST['score_3'] : ''; //if scores are all empty return this clause; if (($score_1 == "") || ($score_2 =="") || ($score_3 =="")) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Go play some more freegumph! Need at least three scores to calculate a handicap.</b></font><br>"); } //A if/else clause conditions are placed in parenth. You can also group things inside of //the clause condition with parenth. //If($user == 'Sam' || ($role == 'admin' && $banned != 1)) = if the user's name is sam, or they are and admin that isn't banned. //I spaced out the next line, so you can see how the parenth. match up. elseif ( ( !ereg("[0-9]",$score_1) ) || ( !ereg("[0-9]",$score_2) ) || ( !ereg("[0-9]",$score_3) ) ) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>You must be a new player. Freegumph scores only consist of numeric values.</b></font><br>"); } elseif (($score_1 < 0) || ($score_2 < 0) || ($score_3 < 0)) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#006600\"><b>Error! Perhaps the lowest possible score is 0.</b></font><br>"); } else { $avg=($score_1 + $score_2 + $score_3)/3; if ($avg >= 27) { $total = 0; } else { $total = ((27- $avg) * (7/10)); } print(" The freegumpher handicap is: ". $total); } } ?>
  24. If you look at the dates I passed that function, then yes, 1 year ago would be the correct answer for what you are asking according to your first post. Try putting in the dates that YOU want to check. <?php //set real dates for start and end, otherwise *nix the strtotime() lines. //$return 'days' will return days/hours/minutes/seconds. //$return 'hours' will return hours/minutes/seconds. //$return 'minutes' will return minutes/seconds. //$return 'seconds' will return seconds. function timeDifference($start,$end,$return='decade') { $start = strtotime($start); $end = strtotime($end); $difference = max($end, $start) - min($end,$start); $time = NULL; //calculate time difference. switch($return) { case 'decade': $decade = floor($difference/315705600); $difference = $difference % 315705600; $time['decade'] = $decade; case 'year': $year = floor($difference/31570560); $difference = $difference % 31570560; $time['year'] = $year; case 'month': $month = floor($difference/2630880); $difference = $difference % 2630880; $time['month'] = $month; // case 'week': // $week = floor($difference/604800); // $difference = $difference % 604800; // $time['week'] = $week; case 'days': $days = floor($difference/86400); $difference = $difference % 86400; $time['day'] = $days; // case 'hours': // $hours = floor($difference/3600); // $difference = $difference % 3600; // $time['hour'] = $hours; // case 'minutes': // $minutes = floor($difference/60); // $difference = $difference % 60; // $time['minute'] = $minutes; // case 'seconds': // $seconds = $difference; // $time['second'] = $seconds; } if(is_array($time)) { if($start > $end) { foreach($time as $key => $value) { if($value > 0) { if($value > 1) { $key = $key . 's'; } return $value . ' ' . $key . ' '; } } } elseif($end > $start) { foreach($time as $key => $value) { if($value > 0) { if($value > 1) { $key = $key . 's'; } @$output .= $value . ' ' . $key . ' '; } } } } return $output; } $start = 'September 19th, 2009'; echo timeDifference($start,date('Y-m-d')); ?> September 9 2009 until now = 6 months 14 days <?php //set real dates for start and end, otherwise *nix the strtotime() lines. //$return 'days' will return days/hours/minutes/seconds. //$return 'hours' will return hours/minutes/seconds. //$return 'minutes' will return minutes/seconds. //$return 'seconds' will return seconds. function timeDifference($start,$end,$return='decade') { $start = strtotime($start); $end = strtotime($end); $difference = max($end, $start) - min($end,$start); $time = NULL; //calculate time difference. switch($return) { case 'decade': $decade = floor($difference/315705600); $difference = $difference % 315705600; $time['decade'] = $decade; case 'year': $year = floor($difference/31570560); $difference = $difference % 31570560; $time['year'] = $year; case 'month': $month = floor($difference/2630880); $difference = $difference % 2630880; $time['month'] = $month; case 'week': $week = floor($difference/604800); $difference = $difference % 604800; $time['week'] = $week; case 'days': $days = floor($difference/86400); $difference = $difference % 86400; $time['day'] = $days; case 'hours': $hours = floor($difference/3600); $difference = $difference % 3600; $time['hour'] = $hours; case 'minutes': $minutes = floor($difference/60); $difference = $difference % 60; $time['minute'] = $minutes; case 'seconds': $seconds = $difference; $time['second'] = $seconds; } if(is_array($time)) { if($start > $end) { foreach($time as $key => $value) { if($value > 0) { if($value > 1) { $key = $key . 's'; } return $value . ' ' . $key . ' '; } } } elseif($end > $start) { foreach($time as $key => $value) { if($value > 0) { if($value > 1) { $key = $key . 's'; } @$output .= $value . ' ' . $key . ' '; } } } } return $output; } $start = 'September 19th, 2009'; echo timeDifference($start,date('Y-m-d H:i:s')); ?> Same code with sections un-commented. 6 months 2 weeks 3 hours 48 minutes 55 seconds ?> [/code]
  25. I'm in a hurry. Just adding to the mix, may need some more editing. <?php //set real dates for start and end, otherwise *nix the strtotime() lines. //$return 'days' will return days/hours/minutes/seconds. //$return 'hours' will return hours/minutes/seconds. //$return 'minutes' will return minutes/seconds. //$return 'seconds' will return seconds. function timeDifference($start,$end,$return='decade') { $start = strtotime($start); $end = strtotime($end); $difference = max($end, $start) - min($end,$start); $time = NULL; //calculate time difference. switch($return) { case 'decade': $decade = floor($difference/315705600); $difference = $difference % 315705600; $time['decade'] = $decade; case 'year': $year = floor($difference/31570560); $difference = $difference % 31570560; $time['year'] = $year; case 'month': $month = floor($difference/2630880); $difference = $difference % 2630880; $time['month'] = $month; // case 'week': // $week = floor($difference/604800); // $difference = $difference % 604800; // $time['week'] = $week; case 'days': $days = floor($difference/86400); $difference = $difference % 86400; $time['day'] = $days; // case 'hours': // $hours = floor($difference/3600); // $difference = $difference % 3600; // $time['hour'] = $hours; // case 'minutes': // $minutes = floor($difference/60); // $difference = $difference % 60; // $time['minute'] = $minutes; // case 'seconds': // $seconds = $difference; // $time['second'] = $seconds; } if(is_array($time)) { if($start > $end) { foreach($time as $key => $value) { if($value > 0) { if($value > 1) { $key = $key . 's'; } return $value . ' ' . $key . ' ago.'; } } } elseif($end > $start) { foreach($time as $key => $value) { if($value > 0) { if($value > 1) { $key = $key . 's'; } $output .= $value . ' ' . $key . ' until.'; } } } } return $output; } $start = 'September 19th, 2009'; echo timeDifference($start,'2008-02-01 16:32:09'); ?>
×
×
  • 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.