
3raser
Members-
Posts
815 -
Joined
-
Last visited
Everything posted by 3raser
-
Sorry if I'm wording this in a way it's hard to understand. I'm going to update the users table and set the lastpost field using microseconds when they make a new post/topic. When they go to make a new post/topic, I need to compare their lastpost to the flood limit time using some simple subtraction. Where should I store the time interval (flood limit time)? A file or database.
-
I want to make a time limit in-between posts on my forum. Should I make a table in the database to store the seconds, or read it/write via a file?
-
Thank you kicken! I really appreciate the help. Gaining more knowledge of SQL is fun. ^.^
-
Hi there! I'm still getting use to using multiple rows when ordering in SQL, but I have a question. How can I display topics that are stickied first, then display all the threads below ordered by lastpost? I tried: //thread details $query = mysql_query("SELECT `date`,`lock`,`sticky`,`status`,`title`,`username`,`id`,`lastposter`,`lastpost` FROM threads WHERE parent = '{$_GET['forum']}' ORDER BY lastpost, sticky DESC LIMIT $start,$per_page") or die(mysql_error()); And the stickies do show up first, but all the regular threads aren't showing ordered by laspost DESC. Why is that? :/ Lastpost = datetime
-
Thank you for that bit of information. Solved
-
UPDATE: If I remove lastedit = NOW() from the query, and just leave SET content = $var, it works. :/ If already double checked to see if a user would make it to this point in the code, and they do. And the variable $pid IS assigned a value. I've also done a quick check and changed the UPDATE queries to SELECT queries, and then echoed out the number of rows and it returned a successful result. Yet, people still can't seem to have their posts updated...why? My code: //if it's a thread, update the thread, if it's a post, update the post if($type == 2) { //update thread mysql_query("UPDATE threads SET lastedit = NOW() AND content = '{$content}' WHERE id = {$id}") or die(mysql_error()); //send them to their post redirect('viewthread.php?forum='. $forum_id .'&id='. $id .'&page='. $page); } else { //update post mysql_query("UPDATE posts SET lastedit = NOW() AND content = '{$content}' WHERE id = {$pid}") or die(mysql_error()); //send them to their post redirect('viewthread.php?forum='. $forum_id .'&id='. $id .'&page='. $page .'&post='. $post); }
-
MySQL will actually be able to sort via date? Edit: Got it.
-
I want my forum to sort through the threads from youngest to oldest. How would I go about doing this? I originally used the NOW() function when inserting a new thread, but I had no clue how to make the threads sort via the date. I could use the time() function, but all users would see for the date would be numbers. Each time someone posts, the field "lastpost" is updated to send it to the top of the forum (suppose to). Any ideas? :-\ - I'm just learning the ropes for time and dates with PHP.
-
Thanks for the reply Pikachu.
-
If I check and make sure a variable is numeric with the is_numeric function, and it passes the in_numeric function, can it still be a security risk if I don't escape it with mysql_real_escape_string()?
-
I've never bothered to really look into the preg_match function, but I thought it could be a very useful function. I've read the PHP manual, but what's with the random characters such as /^def/ (an example in the PHP manual). I want to create a function that only allows letters, numbers, and underscores in the username. How would I go about doing so?
-
Alright, thanks for the information. That basically sums up my question.
-
I've been meaning to move on to OOP for a while now that I've grasped the concept of OOP in java quite well and I'm doing good so far in PHP OOP. One question that I have floating around though is: When would protected be of any use? I understand what protected does, it's just I don't see how it could ever stop an error from happening. Is there an example for how it would be able to stop an interference from occurring?
-
Forgot the error: Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/content/63/8895563/html/index.php on line 6
-
$file = 'includes/views.txt'; $f = fopen($file, 'w+'); $views = fread($f, filesize($file)); fwrite($f, $views+1); fclose($f); The contents of views.txt is: 1 Why is it returning it needs to be greater than 0?...The file isn't empty.
-
It does the same thing as calling php's date() as you did but uses a mysql function instead. It doesn't. But it is a good habit to get into as it can come in handy when debugging. Thank you for the information.
-
Thank you, this is greatly appreciated. And may I ask you why you put now()? Also, how does separating the query into a variable make it more efficient?
-
I made a small editing system for my news page, and I need to update three columns within my table "announcements" in the database. I tried a method of updating all of them with one MySQL query instead of using three as it just isn't neat. I've searched several methods via google and I've tried all of them, but just can't seem to get it to work. Is this MySQL query correct? mysql_query("UPDATE announcements SET title = {$title} WHERE id = '$id', content = {$content} WHERE id = '$id', lastmodified = ". date('M-d-Y') ." WHERE id = '$id'");
-
No code to show really. I type a message into a textbox with the HTML link tags, send it to the database, then just display it with PHP.
-
Everytime I make an announcement/post with a link like so: "This is an announcement with the following link: <a href="http://www.blah.asp">link</a>" It never goes to the actual webpage. It always goes to a "not found" page on my website like so: http://mywebsite.com/"http://www.blah.asp/"
-
Is there a way to only output the first, say, 30 words of a variable? I have a way to do it in mind, but seems like it's messy and not practical. Any suggestions? E.g: WITHOUT LIMIT: Welcome to my store. Would you like to buy something? We have really good noodles and fishes in doodle pools. WITH LIMIT: Welcome to my store. Would you like... Sort of like a short preview.
-
Thanks guys. I've managed to move around some stuff and I now only echo out through variables. All PHP is at the top of the page (most, just to make the header errors go away).
-
I attempted to add exit() right after header(), but still the same error: Warning: Cannot modify header information - headers already sent by (output started at /www/zxq.net/w/e/b/webaskius/htdocs/index.php:5) in /www/zxq.net/w/e/b/webaskius/htdocs/functions.php on line 6 Warning: Cannot modify header information - headers already sent by (output started at /www/zxq.net/w/e/b/webaskius/htdocs/index.php:5) in /www/zxq.net/w/e/b/webaskius/htdocs/functions.php on line 11
-
I checked and there is no whitespace before my first <?php tags where I include the functions Here you go, my whole index.php: <?php include('functions.php'); ?> <link href="style.css" rel="stylesheet" type="TEXT/CSS"> <img src="logo.png" border="0"> <div id="maincontent"> <?php //connect to the database mysql_connect('localhost', '', ''); mysql_select_db(''); //check if logged in with a cookie if(isset($_COOKIE['user'])) { //if not set, show them the textarea to post in if(!$_POST['submit_new_question']) { ?> <form action="index.php" method="POST"> <textarea name="question" maxlength="450"></textarea><br/> <input type="submit" value="WebASK!"> </form> <hr> <?php } else { //secure the data for database input, strip any possible html tags, and make nl2br turn to break tags $question = mysql_real_escape_string(strip_tags(nl2br($_POST['question']))); if(strlen($question) <= 40) { echo 'Your question needs to be at least fourty characters! Please go back in your browser via your browser back button.'; } else { //sumbit to database mysql_query("INSERT INTO questions VALUES (null, '{$question}', '{$username}', '". date('M-D-Y') ."', '". $_SERVER['REMOTE_ADDR'] ."')"); echo 'Thanks. Your question has been posted!'; } ?> <hr> <?php } } else { if(isset($_GET['login']) || isset($_POST['login'])) { //if they have already clicked the login button, let's process it if(isset($_POST['login'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5($_POST['password']); //query to check if username/password combination exists $query_verify_login = mysql_query("SELECT * FROM accounts WHERE username = '{$username}' AND password = '{$password}' LIMIT 1"); if(mysql_num_rows($query_verify_login) > 0) { create_cookie(10000, 'user', $username); redirect('index.php'); } else { echo 'Woops! You\'ve entered in the wrong username and password combination!'; } } else { ?> <table> <form action="index.php" method="POST"> <input type="hidden" name="login" value="1"> <tr><td>Username</td><td><input type="text" name="username" maxlength="25"></td></tr> <tr><td>Password</td><td><input type="password" name="password" maxlength="32"></td></tr> <tr><td><input type="submit" value="Login"></td></tr> </form> </table> <?php } } elseif(isset($_GET['register']) || isset($_POST['register'])) { if(isset($_POST['register'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5($_POST['password']); //query to check if username exists $query_verify_no_duplicates = mysql_query("SELECT * FROM accounts WHERE username = '{$username}' LIMIT 1"); if(mysql_num_rows($query_verify_no_duplicates) > 0) { echo 'Sorry! An account already exists with that username.'; } else { if(strlen($password) < 4) { echo 'You\'re password needs to be at least five characters.'; } else { //create account in the database mysql_query("INSERT INTO accounts VALUES (null, '{$username}', '{$password}', '". date('M-D-Y') ."', '". $_SERVER['REMOTE_ADDR'] ."', 0, 0)"); echo 'Congratulations! You\'ve successfully registered!'; } } } else { ?> <table> <form action="index.php" method="POST"> <input type="hidden" name="register" value="1"> <tr><td>Username</td><td><input type="text" name="username" maxlength="25"></td></tr> <tr><td>Password</td><td><input type="password" name="password" maxlength="32"></td></tr> <tr><td><input type="submit" value="Register"></td></tr> </form> </table> <?php } } else { } ?> <br/><br/><a href="index.php?login=true">Login</a> or <a href="index.php?register=true">Register</a> to post a question!<hr> <?php } //a query to run while extracing questions $query_extract_questions = mysql_query("SELECT * FROM questions ORDER BY id DESC"); //extract our questions/post data while($row = mysql_fetch_assoc($query_extract_questions)) { ?> <table> <tr><td>Posted by <? echo $row['username']; ?></td><td>Posted on <? echo $row['date']; ?></td><td><? get_replies($row['id']); ?></td></tr> <tr><td><div id="question"><? echo $row['question']; ?></div></td></tr> </table> <?php } ?>