eRott
Members-
Posts
206 -
Joined
-
Last visited
Never
About eRott
- Birthday 11/28/1988
Profile Information
-
Gender
Male
-
Location
Toronto, ON
eRott's Achievements
Member (2/5)
0
Reputation
-
I need to insert a value into a pre-existing row in a table. Here's the basic break-down: 1) User fills out a form. 2) A thread is created in [table A] (MyBB) with data gathered from the form 3) Insert portions of the data gathered from the form into [table B] as well I need a means of linking both the item in [table A] and the item in [table B] together for future queries. I opted for creating a new field in [table A] and inserting the ID number of the item inserted into [table B]. The problem is, I need to insert the ID number from the item in [table B] into the correct item in [table A]. It is proving to be difficult since there really isn't any pre-existing unique value which I could use to link the item in [table A] to the one in [table B]. I think I may just end up generating a random salt, throwing it in each upon creation and linking them that way. Unless of course you see a solution to the problem I mentioned earlier. Oh my... its 12:00. I have to get up in 5 hours for work. I'll check back here tomorrow.
-
<?php mysql_connect ("localhost", "username", "password") or die (mysql_error()); mysql_selectdb ("Corrupshun") or die (mysql_error()); $title = $_POST['title']; $side = $_POST['side']; $path = $_POST['path']; $check = mysql_query("SELECT * FROM games WHERE title='$title' AND side='$side' AND path='$path'"); $numrows = mysql_num_rows($check); if ($numrows >= 1) { echo 'Game already exists.'; } else { mysql_query("INSERT INTO games (title, side, path) VALUES ('$title','$side','$path')"); echo 'Successfully inserted '.$title.' into the database.'; } ?>
-
Hey guys, I keep getting this error: Its from this query: mysql_query("INSERT INTO mybb_threads (appid) VALUES ('$appid') WHERE subject='Application: $char_name'") or die(mysql_error()); Does anyone know what is wrong with it? Thanks.
-
Couldn't you use \n for the line break? mail($to, $subject, "Hello,\n\nThis.\n\nGoodbye.", $headers) Result: Hello, This. Goodbye.
-
Ohhhh okay. I see what you've done to accomplish it. Suddenly, this task didn't seem so hard in the first place. You simply subtract the current timestamp from the event timestamp to get the number of seconds remaining (since timestamps are just the number of seconds since 01/01/1970). Then you up each unit of time by 1 accordingly based on the number of seconds until that unit has reached its maximum at which point it ups the next unit of time by 1. Although, I am unsure exactly what these little tidbits do: $secs -= 60; After checking, the -= operand is the equivalent of saying x=x-y. Wait a minute, alright, I understand it. So that line is basically saying: The number of seconds = the number of seconds - 60 but only when the maximum value of that unit has been reached and the next unit of time is upped by one. So in other words, once the minutes count has reached 60, you up the hours by one and reset the minutes count to 0. Same thing applies to the hours except the count is 24, not 60. Alright, I'm fairly confident I understand how this function works now. Thank you kindly for your assistance. Take it easy.
-
Hey, new problem I could use some help with. What I am looking to do is obtain the remaining time until a future event occurs. Say for example, I have a lunch meeting on May 26 @ 12:00 PM and today's date is May 24 @ 2:00 PM. I want to calculate and display the remaining time until that event is scheduled to take place; which is 2 days and 2 hours (I think :-\). As it stands I have the event date stored as a UNIX timestamp in a database. I was experimenting and came up with this: index.php $finalTime = timeLeft(date("H", $event['start']), date("i", $event['start']), date("s", $event['start']), date("n", $event['start']), date("j", $event['start']), date("Y", $event['start'])); $remainingTime = explode(',', $finalTime); echo "Hours => ".$remainingTime[0]."<br />"; echo "Minutes => ".$remainingTime[1]."<br />"; echo "Seoonds => ".$remainingTime[2]."<br />"; echo "Months => ".$remainingTime[3]."<br />"; echo "Days => ".$remainingTime[4]."<br />"; echo "Years => ".$remainingTime[5]; timeLeft() function timeLeft($hours, $minutes, $seconds, $months, $days, $years) { // mktime(hour, minute, second, month, day, year) // mktime (H, i, s, n, j, Y) // mktime(23, 00, 00, 5, 23, 2009) // H = 24-hour format of an hour with leading zeros // i = Minutes with leading zeros // s = Seconds, with leading zeros // n = Numeric representation of a month, without leading zeros // j = Day of the month without leading zeros // Y = A full numeric representation of a year, 4 digits $totalHours = $hours - date("H"); $totalMinutes = $minutes - date("i"); $totalSeconds = $seconds - date("s"); $totalMonths = $months - date("n"); $totalDays = $days - date("j"); $totalYears = $years - date("Y"); $finalTime = $totalHours.",".$totalMinutes.",".$totalSeconds.",".$totalMonths.",".$totalDays.",".$totalYears; return $finalTime; } Its very basic and flawed as it will work only under a very strict set of circumstances. Notably: [*]The event day is the same as the current day [*]The event hour is greater then the current hour [*]The event minute is greater then the current minute So obviously it isn't going to work. Which is where you, the PHPFreaks community, steps in yet again to hopefully shed some light on this problem. With that said, are there PHP functions already in existence to accomplish this? Do you know of any resources I could read? Thanks.
-
Your missing the fact that use cannot use double quotes inside of an echo which uses double quotes unless you escape them first using \.
-
<tr> <td><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#000000">Choose Password: *</font></b></td> <td><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#000000"> <?php if ($errorMsg == AFF_SI_USEREXISTS) { echo '<input type="text" name="ausername" maxlength="12" size="30" background-color="#FA1B00" value="'.$_POST['ausername'].'">'; } else { echo '<input type="text" name="ausername" maxlength="12" size="30" value="'.$_POST['ausername'].'">'; } ?> </font></b></td> </tr> EDIT: By the way, what is AFF_SI_USEREXISTS? Is that supposed to be a function?
-
Aye. Thanks. I didn't realize I was using the wrong variable. I should have been using $event_date as it is the one which stores the date in the "dd-mm-yyyy" format (which is passed from a form a user fills out). So it should be: // $event_date is a date in the format of "dd-mm-yyyy" $timestamp_date = explode('-', $event_date); // [0] => day [1] => month [2] => year Thanks mate. Take it easy.
-
Hey, I am having a bit of troubles with this function: function event_add($date, $event_date, $time_start_hh, $time_start_mm, $time_end_hh, $time_end_mm, $event_type, $event_more) { // $date is a date in the format of "dd-mm-yyyy" $timestamp_date = explode('-', $date); // [0] => day [1] => month [2] => year $timestamp_start = mktime($time_start_hh, $time_start_mm, 0, $timestamp_date[1], $timestamp_date[0], $timestamp_date[3]); // mktime(hour, minute, second, month, day, year) $timestamp_end = mktime($time_end_hh, $time_end_mm, 0, $timestamp_date[1], $timestamp_date[0], $timestamp_date[3]); // mktime(hour, minute, second, month, day, year) $query = "INSERT INTO events (date, event_date, start, end, time_start_hh, time_start_mm, time_end_hh, time_end_mm, type, more)"; $query .= "VALUES ('$date', '$event_date', '$timestamp_start', '$timestamp_end', "; $query .= "'$time_start_hh', '$time_start_mm', '$time_end_hh', '$time_end_mm', '$event_type', '$event_more')"; mysql_query($query) or die (mysql_error()); } For some reason, the timestamp isn't being written to the database in the appropriate fields, "start" and "end" while everything else is. I have already checked to ensure neither are reserved MySQL words. I believe it has something to do with my use of the array: $timestamp_date. $date = time(); event_add($date, $_POST['event_date'], $_POST['time_start_hh'], $_POST['time_start_mm'], $_POST['time_end_hh'], $_POST['time_end_mm'], $_POST['event_type'], $_POST['event_more']); Any ideas?
-
Changing: $numrows = mysql_num_rows($info) or die(mysql_error()); To: $numrows = mysql_num_rows($info); Solves the problem. I believe what was happening was when a set of incorrect login information is passed the the function, nothing is returned / selected from the database because the user obviously doesn't exist. As a result, I'm guessing mysql_num_rows() either simply doesn't fire or returns some invalid value.. or something. Either way, using die() resulted in the script termination (for whatever reason) which prevented (obviously) the error message and anything else from being displayed. EDIT: Working user_login() function user_login($username, $password) { // Grab the salt from the database using the username $salt = mysql_query("SELECT salt FROM users WHERE username = '".$username."' LIMIT 1") or die(mysql_error()); $user = mysql_fetch_array($salt); // Using the salt, encrypt the given password to see if it // matches the one in the database $encrypted_pass = md5(md5($password).$user['salt']); // Grab the user information that matches the username & encrypted password $info = mysql_query("SELECT userid, username, usergroup FROM users WHERE username = '".$username."' AND password = '".$encrypted_pass."' LIMIT 1") or die(mysql_error()); $user = mysql_fetch_array($info); $numrows = mysql_num_rows($info); if ($numrows > 0) { // Store the data in the session $_SESSION['userid'] = $user['userid']; $_SESSION['username'] = $user['username']; $_SESSION['usergroup'] = $user['usergroup']; return TRUE; } else { return FALSE; } } Thank you waynewex and Maq. Take it easy.
-
Two things which may be the cause: [1] Possible incorrect database information. Are you trying to connect to a remote database? [2] The passwords are not being stored upon register in md5 format. Otherwise, the problem doesn't pop out at me. I've gone ahead and cleaned up your code a bit. <?php mysql_connect("*****.net", "database1", "*****") or die(mysql_error()); mysql_select_db("database1") or die(mysql_error()); //Checks if there is a login cookie //if there is, it logs you in and directes you to the members page if(isset($_COOKIE['SiteName'])) { $username = $_COOKIE['SiteName']; $pass = $_COOKIE['SiteName2']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error()); $info = mysql_fetch_assoc($check); if ($pass == $info['password']) { header("Location: members.php"); } } // If the login form is submitted if (isset($_POST['submit'])) { // Verifies the form has been filled in if(empty($_POST['username']) || empty($_POST['pass'])) { die('You did not fill in a required field.'); } if (!get_magic_quotes_gpc()) { $email = addslashes($_POST['email']); } $query = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'") or die(mysql_error()); $check = mysql_num_rows($query); // Returns and error if user dosen't exist if ($check == 0) { die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>'); } while($info = mysql_fetch_array($query)) { $post_pass = md5(stripslashes($_POST['pass'])); $stored_pass = stripslashes($info['password']); // Returns an error if the password is wrong if ($post_pass != $stored_pass) { die('Incorrect password, please try again.'); } else { // If login is ok then we add a cookie $username = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(StrictlyGirlz, $username, $hour); setcookie(StrictlyGirlz2, $post_pass, $hour); } } } ?>
-
$index=strpos(substr($data[0]['long_descr'],0,20),'same_as');
eRott replied to M477HEW's topic in PHP Coding Help
For beginners, even the documentation can be confusing. First off, let's break it down. The line of code you posted uses two functions. strpos() and substr(). The strpos() function is used to find the first occurrence of a string within another string. Take the below as an example. The resulting value of the variable $pos would be 0 because a is the very first character in the string (it starts at 0, not 1). $mystring = 'abc'; $findme = 'a'; $pos = strpos($mystring, $findme); The substr() function returns a specific section of a string which you tell to find by providing where in that string to start and where to end. Take the below code as an example. The resulting value of $return would be Hello because you are telling it to return only the part of the string starting from 0, (the beginning), and ending at 4, (the letter "o" is in the fourth position where the letter "H" would be position zero). $mystring = 'Hello my name is Matt!'; $return = substr($mystring, 0, 4); With that in mind, the line of code you posted grabs the first 21 characters of a string which is, from the looks of it, a description of something ($data[0]['long_descr']). (Note, spaces count as a character). It then searches for the first occurrence of "same_as" in that string and stores the position of that first occurance in the variable $index. The following bit of code make make it a little easier to read. $haystack = substr($data[0]['long_descr'],0,20); $index = strpos($haystack,'same_as'); Correct me if I am wrong, but I am fairly certain that is what that line of code does. -
shameful bump incoming... The solution to the date() notices was to surround the format in single quotations. $month = date('n'); $year = date('Y'); $today = date('j'); Other then that, does anyone have any thoughts as to what's causing my problem as explained in this previous post? I will continue my debugging efforts in the meantime. Thanks.
-
[SOLVED] WHY WONT <? session_start(); session_destroy(); ?> log me out?
eRott replied to emopoops's topic in PHP Coding Help
Aye. Sorry, I probably should have clarified that. Yes, I know it needs to be initialized first. Myself, I use it as a function. function user_logout() { // End the session and unset all vars session_unset(); session_destroy(); } The session is already started elsewhere on the page. Sorry for the confusion.