Jump to content

El Chupacodra

Members
  • Posts

    63
  • Joined

  • Last visited

    Never

Everything posted by El Chupacodra

  1. I tried a number of different things but it won't update the table. I set an echo to show if the code even reaches the 12 month update and it does. I changed to update an empty table called test to see if it was a data type error but it wasn't - it wouldn't insert there either. Then I let the query run in a brand new variable but it still refuses to run. I add and take away quotation marks....still nada. Why won't my (well Pikachu's) script run? Actually I think it's not his fault since my simpler queries won't run either. Going crazy here.
  2. That is an elegant solution! I just woke up and typed it in but it still leaves the paidTo date at 0000-00-00 (with a zero timestamp after if I use datatypes Timestamp or Datetime). Maybe I'll send you the entire code and you will spot what I missed. Thanks for the suggestion anyway, second time you help me with dates in PHP. Here is the entire page (except the include to the connection document): $query = "SELECT paid_days FROM user_data WHERE user='$user'"; $result = mysql_query($query); $row = mysql_fetch_row($result); $validTo = $row[0]; $now = time(); $now=(date("Y-m-d H:i:s")); $fromDate='0000-00-00 00:00:00'; if ($validTo>$now) { $fromDate = $paidTo; } if ($now>$validTo){ $fromDate = $now; } else $fromDate = $fromDate; if (isset($_POST['buy'])) { $buy = sanitizeString($_POST['buy']); if ($buy==1) { $newdate = strtotime ( '+ 1 month' , strtotime ($fromDate) ) ; $newdate = date ( 'Y-m-d' , $newdate ); $query = "UPDATE TABLE user_data SET validTo=$newdate WHERE user = $user"; } if ($buy==3) { $newdate = strtotime ( '+3 months' , strtotime ($fromDate) ) ; $newdate = date ( 'Y-m-d H:i:s' , $newdate ); $query = "UPDATE TABLE user_data SET validTo=$newdate WHERE user = $user"; } if ($buy==6) { $newdate = strtotime ( '+6 months' , strtotime ($fromDate) ) ; $newdate = date ( 'Y-m-d H:i:s' , $newdate ); $query = "UPDATE TABLE user_data SET validTo= DATE_ADD($fromDate INTERVAL 12 MONTH) WHERE user = $user"; } if ($buy==12) { $query = "UPDATE TABLE user_data SET valid_days = DATE_ADD( "; $query .= $validTo > $now ? "'$validTo'" : 'NOW()'; $query .= ", INTERVAL 12 MONTH ) WHERE user='$user'"; mysql_query($query); } } $testdate = strtotime ( '+1 month' , strtotime ( $fromDate ) ) ; $testdate = date ( 'Y-m-j' , $testdate ); echo " Testdate = $testdate"; echo " validTo = $validTo"; //three variable just to see if they work echo " Now = $now"; echo " FromDate = $fromDate"; //it DOES work to figure out whether to count from today or the current validTo date echo <<<_END <br /> <p>Your account is currently VIP until $validTo</p> <form method='post' action='account.php'> <table><tr><td> 1 Month<input type='radio' name='buy' value='1' /></td><td> 3 Months<input type='radio' name='buy' value='3' /></td><td> 6 Months<input type='radio' name='buy' value='6' /></td><td> 12 Months<input type='radio' name='buy' value='12' /></td><td></tr><tr><td> 100<br />100/month</td><td>270<br /> 90/month</td><td>450<br />75/month</td><td>600<br />50/month</td></tr></table> <input name='submitted' type='hidden' value='true' /> <input type='submit' value='Buy VIP Status'></form> _END; ?>
  3. $fromDate is a variable thats just sets where to start counting - from today's date or from the registered ValidTo date, whichever is more recent. The variable $validTo is taken straight from the DB (Timestamp format, normal sql query). Code here: $fromDate='0000-00-00 00:00:00'; if ($validTo>$now) { $fromDate = $validTo; } if ($now>$validTo){ $fromDate = $now; } else $fromDate = $fromDate; EDIT: Echoed variables: Newdate = 2013-01-10 22:20:00 Testdate = 2012-02-10 PaidTo = 2012-01-09 00:00:00 Now = 2012-01-10 22:20:00 FromDate = 2012-01-10 22:20:00 Your account is currently VIP until 2012-01-09 00:00:00 That part seems to work since I get the correct date and time when I echo $newdate. It looks just right to me, it just won't appear in my DB.
  4. I have this code to change the validity date of an account. I do a check against timestamp and current validity which works fine. Then I have radio buttons you can check to choose to extend with one, three, six or 12 months through a form and a post variable - they work too. When I write the variables out they look fine but when I want it in my database - nothing happens! I mean the original data is never changed. Can you see what is wrong? I tried changing the data type from date to datetime to timestamp with the same result. I suppose I will learn something new from phpfreaks today again. Code is here for the 12 month radio button: $newdate = strtotime ( '+12 months' , strtotime ($fromDate) ) ; $newdate = date ('Y-m-d H:i:s', $newdate ); echo "$newdate"; $query = "UPDATE TABLE user_data SET paid_days='$newdate' WHERE user='$user'"; mysql_query($query); When I write the variable $newdate it shows up as 2013-01-10 21:55 (right now) which seems like a valid format to me. Do I need to convert it somehow?
  5. I might use the same in my current log in script if you don't mind. Looks great. Thanks for sharing Paul.
  6. Still working on the same project. I had a function to upload a photo and you could use it as a profile picture. Now I wanted to expand on it and decided you can upload more than one photo, creating a gallery. I figured I could use the same script to create two images (one original size and one thumbnail for browsing) and went about it in two different ways, both failed miserably. First I figured my upload code could take the indata and make TWO photos at once with different name. I guess it can only keep on image in mind at once - or I did something else wrong. I used the same code to create $user.jpg and $user_tn.jpg and move them to the user's image folder. So try number two was to make two folders for the photo, one named after the user (for thumb) and another in a folder named big. That isn't working for me either. Anyone who likes to chime in with ideas or facepalms is very welcome. Here is the generic code I set out with: if ($view == $user) { mkdir("grafik/users/$user"); mkdir("grafik/users/$user/big/"); if (isset($_FILES['image']['name'])) { $saveto = "grafik/users/$user/big/$user.jpg"; move_uploaded_file($_FILES['image']['tmp_name'], $saveto); $typeok = TRUE; switch($_FILES['image']['type']) { case "image/gif": $src = imagecreatefromgif($saveto); break; case "image/jpeg": case "image/pjpeg": $src = imagecreatefromjpeg($saveto); break; case "image/png": $src = imagecreatefrompng($saveto); break; default: $typeok = FALSE; break; } if ($typeok) { list($w, $h) = getimagesize($saveto); $max = 200; $tw = $w; $th = $h; if ($w > $h && $max < $w) { $th = $max / $w * $h; $tw = $max; } elseif ($h > $w && $max < $h) { $tw = $max / $h *$w; $th = $max;} elseif ($max < $w) { $tw = $th = $max;} $tmp = imagecreatetruecolor($tw,$th); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $tw, $th, $w, $h); imageconvolution($tmp, array( array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1) ), 8, 0); imagejpeg($tmp, $saveto); imagedestroy($tmp); imagedestroy($src); } } echo <<<_END <div id='main'> <form method='post' action='profile.php' enctype='multipart/form-data'> Image: <input type='file' name='image' size='14' maxlength='32' /> <input type='submit' value='Save Profile' /> </form> </div> _END; } It is the page in minimalist form and it still contains the big folder version. Thanks for putting up with my nooby questions.
  7. Thank you! That worked like a charm! And you were lightning fast too.
  8. This is why I love this forum. I never heard of that interval before - I will go try it out right away. Thanks!
  9. Hi, I just want to see what way you guys think is best. On this little community I'm building I have decided to implement a function to see who were active within the last 15 minutes. I made a table (just user and timestamp) to register the last activity of any logged on user. Then I have a variable to take off 15 minutes from that but I can't get them to compare. Googling the issue I found people are solving this in very different ways. I wanted to see what phpfreaks recommend as the next step. Here is some code (that doesn't work properly - no results found as I compare to different timestamps): include_once'header.php'; $now=time(); $now=(date("Y-m-d H:i:s")); //$mins = mktime(0,$now-15,0, date("Y"), date("m"),date("d")); $mins = time(); $mins15 = $mins-(60*15); $mins15 = (date("Y-m-d H:i:s", $mins15)); $online="SELECT * FROM user_online" WHERE last_activity > mins15; $result = mysql_query($online); if (!$result) die ("Database access failed: " . mysql_error()); $rows = mysql_num_rows($result); echo <<< _END <div id='statusbar'> <h4>Online now: $rows</h4>
  10. Well usually you'll write a function and include it in your php. Like this for instance: function sanitize($var) { $var = strip_tags($var); $var = htmlentities($var); $var = stripslashes($var); return mysql_real_escape_string($var); } ...so when you write sanitize php performs all those steps on the variable you enter. Ie, sanitize($userInput) means $userInput goes through all the steps in the function. You can add or take away all you want from it depending on what you need to do. My version above is useless if you want the input to be HTML so you would modify that to leave the HTML intact.
  11. Matt you don't have to change anything to insert the backslashes. PHP does that for you and that is what we mean by escaping it. It disarms the potentially dangerous SQL Code that can be abused to enter your DB. SQL injection is how hackers get into a lot of sites so it's important to protect yourself.
  12. Hello and thanks for helping. I need checkboxes for the user to select multiple criteria more easily. Then again I might look at those again. The implode idea is good , I think I had a version of it at some point. As you can tell I'm in a very early stage with this.
  13. Hi gang, new to posting but I've read the forum on and off. I'm coding a small community and will have a lot of questions for you over time. The first one is about a search function. We'll have users of different nationalities and languages and you will be able to search, only I was thinking there could be a better way. They'll enter those posts through a dropdown list and when you search it you will use checkboxes. I just don't see the results I want when I pick the array for info. Like I have this right now as the form (which is sent to the php page itself as POST): Nationality: <br /> <input type="checkbox"" name="natBox[]" size="30" value="all"/> All<br /> <input type="checkbox"" name="natBox[]" size="30" value="weuro"/> W Europe<br /> <input type="checkbox"" name="natBox[]" size="30" value="eeuro"/> E Europe<br /> <input type="checkbox"" name="natBox[]" size="30" value="wafrica"/> W Africa<br /> And the thing I was doing was to check the boxes with if (isset) and then make the query longer and longer, butI figure there could be a smarter way. Like if I was going to enter 200 countries I can't really check for all can I? After the check (now deleted) it sets the query to this: $query = "SELECT * FROM user_criteria WHERE (age BETWEEN '$ageFr' AND '$ageTo') AND nationality='$nationality'"; ...and the part I don't have now is to pick the array natBox and add every value so @nationality becomes for instance weuro OR wafrica etc. Got a more elegant approach?
×
×
  • 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.