Jump to content

Superman702

Members
  • Posts

    29
  • Joined

  • Last visited

    Never

Everything posted by Superman702

  1. Worked like a charm. I read it on PHP, but I thought since it was already an existing variable, I couldn't plug it into a date() command. Guess I was wrong. Thanks for your help!
  2. Newbie question... I have a form in which I submit time() into an INT on MySQL. After I retrieve that table with the old UNIX Timestamp on it, how do I convert it from .$info['timestamper'] . (which holds the timestamp) into a date and time output? (i.e. 01:05:05 PM 12/25/2010) My Current Code: $mins = time()-60*60*24*3; //Last 72 hours $result = mysql_query("SELECT * FROM messages WHERE `timestamper` > '$mins'"); $num_rows = mysql_num_rows($result); echo "<CENTER><table border cellpadding=3><TR><TH>Message</TH><TH>Sent By</TH><TH>Time</TH></TR>"; while($info = mysql_fetch_assoc($result)){ Print "<tr><TH>".$info['display'] . "</th> <th>".$info['username'] ."<TH>".$info['timestamper'] ."</TH></TR>"; }
  3. I don't know if it was just an error with my code or what....I copy and pasted your code and it worked exactly as it should. I also renamed my database and tables. Perhaps the code was confused with multiple same names of databases or tables. I'll work on a process or a purge php page for admins to access to delete prior messages is need be. Thanks again for your help!
  4. I don't think anyone gives this forum enough credit. Thank you for all you do for us newbie programmers/web page designers out there. At all hours of the day it seems like at least one of you are online to always help us with any question or problem we have. I feel like I learn more here than in any classroom! Again, thank you to everyone who contributes. People really do appreciate it.
  5. The Timestamper field is a INT field. It is taking time() exactly as it is when it is submitted. <HTML> <HEAD> <meta http-equiv="REFRESH" content="6;url=interface.php"> </HEAD> <BODY> <? $Main=$_POST['Main']; $Timestamper=time(); mysql_connect("localhost", "root", "******") or die(mysql_error()); mysql_select_db("message") or die(mysql_error()); mysql_query("INSERT INTO `main` VALUES ('$Main', '$Timestamper')"); Print "Your message will now be broadcasted."; ?> </BODY> </HTML> My database is set up with the same name a lot. Just to clear the air: Database Name: message Table Name: main Field Names (in order): Main varchar(200) and Timestamper int(11). I will update the field names, but I was just trying to get something up and running. I'm sorry for the same name field if it confuses anyone. This is the whole interface.php file that holds the form that submits the information: <? session_start(); if(!session_is_registered(myusername)){ header("location:main_login.html"); } $host="localhost"; // Host name $username="root"; // Mysql username $password="******"; // Mysql password $db_name="calltracker"; // Database name $tbl_name="members"; // Table name mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $data = mysql_query("SELECT * FROM main"); $adminstatus=$_SESSION['admin']; ?> <html> <head> <style type="text/css"> body { font: 14px/1.3 verdana, arial, helvetica, sans-serif } h1 { font-size:1.3em } h2 { font-size:1.2em } a:link { color:#33c } a:visited { color:#339 } #buffer { position:absolute; visibility:hidden; left:0; top:0 } div#display { margin: 2em 1em 2em 0; border: none; padding:6px 8px; display:none; /* until loaded */ } </style> <title>Main Menu</title> <BODY BACKGROUND="background.jpg" STYLE="background-repeat:no-repeat;"> <script src="dw_loader.js" type="text/javascript"></script> </head> <body> <BR> <div id="display"></div> <iframe id="buffer" name="buffer" src="top.php" onload="dw_displayExternal()"></iframe> <? if($adminstatus == 1){ echo "Welcome " .$_SESSION['nickname']. " | Standard Member "; echo "<a href=\"logout.php\">Logout</A>"; } if($adminstatus == 2){ echo "Welcome " .$_SESSION['nickname']. " | Supervisor "; echo "<a href=\"logout.php\">Logout</A>"; echo "<BR><BR><B><CENTER>Main Menu Alert System</CENTER></B><BR>"; echo " <form action=\"process.php\" method=\"post\">"; echo " Message to Display: <input type=\"text\" name=\"Main\"> <input type=\"submit\" value=\"Submit\"> <BR></form>"; } if($adminstatus == 3){ echo "Welcome " .$_SESSION['nickname']. " | Manager"; echo "<a href=\"logout.php\">Logout</A>"; echo "<BR><BR><B><CENTER>Main Menu Alert System</CENTER></B><BR>"; echo " <form action=\"process.php\" method=\"post\">"; echo " Message to Display: <input type=\"text\" name=\"Main\"> <input type=\"submit\" value=\"Submit\"> <BR></form>"; echo " <a href=\"add.php\">Add User</A>"; } ?> <BR> </body> </html> This is top.php, which displays the message submitted. This is the main file I believe I am having problems with. I am unsure how to display messages within the database that were submitted only 60 seconds ago (or whatever time I set in the future.) <HTML> <HEAD> <TITLE>v2.0</TITLE> <meta http-equiv="refresh" content="20"> </head> <BODY> <?php // Connects to your Database $link = mysql_connect("localhost", "root", "******"); mysql_select_db("message", $link); $mins = time()-60; mysql_query("DELETE FROM `main` WHERE `Timestamper` < '$mins'"); $result = mysql_query("SELECT * FROM main", $link); $num_rows = mysql_num_rows($result); if($num_rows == 0){ echo "<table width=\"100%\" border=\"0\"> "; echo "<tr><td width=\"10%\"><CENTER></CENTER></td>"; echo "<td width=\"80%\"><CENTER>Main Menu</CENTER></td>"; echo "<td><CENTER></CENTER></td>"; echo "</TR></table>"; } else{ $info = mysql_fetch_assoc($result); echo "<table width=\"100%\" border=\"0\"> "; echo "<tr><td width=\"10%\" bgcolor=\"yellow\"><CENTER><font color=\"RED\"><B>ALERT</B></FONT></CENTER></td>"; echo "<td width=\"80%\" bgcolor=\"red\"><marquee behavior=\"scroll\" direction=\"left\"><B><font color=\"white\">Message: </B>".$info['Main'] . "</marquee></font></td>"; echo "<td width=\"10%\" bgcolor=\"yellow\"><CENTER><font color=\"RED\"><B>ALERT</B></FONT></CENTER></td>";; echo "</TR></table>"; } ?> </BODY> </HTML> I am making somewhat of an Emergency Alert System type ticker. A message is displayed when there has been one submitted within a certain amount of time ago. After the message is X number of minutes old, it will stay in the database (rather than deleted like at the start of the discussion...but I was convinced to try to keep the messages for record keeping purposes, which makes more sence) but not be displayed. I figured the code out on how to delete it if it is after a certain amount of time, but I don't know how to select only the ones in the database that are X number of minutes old. I tried several different type of codes (seen above) and looked at the PHP site, but I am still not doing something right. I think it may be within my logic somewhere. This works just fine: mysql_query("DELETE FROM `main` WHERE `Timestamper` < '$mins'"); But when I remove the code above and replace it with this, nothing is ever displayed: $result = mysql_query("SELECT * FROM main WHERE `Timestamper` < '$mins'", $link);
  6. $mins = time()-60; $result = mysql_query("SELECT * FROM main WHERE Timestamper <= '$mins'", $link); $num_rows = mysql_num_rows($result); if($num_rows == 0){ echo "<table width=\"100%\" border=\"0\"> "; echo "<tr><td width=\"10%\"><CENTER></CENTER></td>"; echo "<td width=\"80%\"><CENTER>Main Menu</CENTER></td>"; echo "<td><CENTER></CENTER></td>"; echo "</TR></table>"; } else{ $info = mysql_fetch_assoc($result); echo "<table width=\"100%\" border=\"0\"> "; echo "<tr><td width=\"10%\" bgcolor=\"yellow\"><CENTER><font color=\"RED\"><B>ALERT</B></FONT></CENTER></td>"; echo "<td width=\"80%\" bgcolor=\"red\"><marquee behavior=\"scroll\" direction=\"left\"><B><font color=\"white\">Special Message: </B>".$info['Main'] . "</marquee></font></td>"; echo "<td width=\"10%\" bgcolor=\"yellow\"><CENTER><font color=\"RED\"><B>ALERT</B></FONT></CENTER></td>";; echo "</TR></table>"; Tried this one and the message doesn't go away now. I can't win...haha
  7. So I tried to change: $result = mysql_query("SELECT * FROM Message", $link); $mins = time()-60; mysql_query("DELETE FROM `Message` WHERE `Timestamper` < '$mins'"); $num_rows = mysql_num_rows($result); to $mins = time()-60; $result = mysql_query("SELECT * FROM main WHERE `Timestamper` < '$mins'", $link); $num_rows = mysql_num_rows($result); and the message is not going across being displayed anymore. Is there a different way I should be doing this to be selecting rows that were created within the last 60 seconds? It works great when I delete the rows after 60 seconds, but I don't know how to just use the messages within the last 60 seconds, rather then deleting them.
  8. So should I have the form submit to a 2nd page that verifies the information instead of using PHP_SELF?
  9. MySQL: 2.11.4 I currently have a database set up with a table called "users". I have three columns "ID" "username" and "password" I want to add a column to the database called "Admin" I want this column to be an INT with only one number in it. 1 (obviously for true) and 0 (for obviously false). I would use this column to establish if a user is just a member or an admin so the Admin can see certain areas that normal users can not see if this field is "1". The problem is, I didn't think this through when I first started working on my script. It might be because I'm tired as *$#&, but I don't know where to go with it now. login.php <?php mysql_connect("*****", "*****", "*****") or die(mysql_error()); mysql_select_db("a7405553_test") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: members.php"); } } } if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); header("Location: members.php"); } } } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> members.php <?php mysql_connect("****", "*****", "*****") or die(mysql_error()); mysql_select_db("a7405553_test") or die(mysql_error()); if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { header("Location: login.php"); } { echo "Admin Area<p>"; echo "Member Content<p>"; echo "<a href=logout.php>Logout</a>"; } } } else { header("Location: login.php"); } ?> Any idea how to make the Admin Area show up for only user names with a "1" in the "admin" part of the row in MySQL?
  10. That does make more sence and I see your point. This is going to be used at a place of business as well and keeping track of the message could be benfical. I'm going to try to change my code to include that...It may take me an hour or so to figure it out. I'll post again soon....
  11. yeah, I just uploaded that file and it just made the same statement over and over and over again....I am shocked my computer didn't crash...haha Here is my main file that I have. What I am trying to do is make a ticker for a page of mine. Kind of like an emergency broadcast system. When a new message has been added to the database to broadcast, then it will replace the current "echo". <HTML> <HEAD> <TITLE>v2.0</TITLE> <meta http-equiv="refresh" content="20"> </head> <BODY> <?php // Connects to your Database $link = mysql_connect("*****", "*****", "*****"); mysql_select_db("a7405553_test", $link); $result = mysql_query("SELECT * FROM Message", $link); $mins = time()-60; mysql_query("DELETE FROM `Message` WHERE `Timestamper` < '$mins'"); $num_rows = mysql_num_rows($result); if($num_rows == 0){ echo "<table width=\"100%\" border=\"0\"> "; echo "<tr><td width=\"10%\"><CENTER></CENTER></td>"; echo "<td width=\"80%\"><CENTER>Main Menu</CENTER></td>"; echo "<td><CENTER></CENTER></td>"; echo "</TR></table>"; } else{ $info = mysql_fetch_assoc($result); echo "<table width=\"100%\" border=\"0\"> "; echo "<tr><td width=\"10%\"><CENTER></CENTER></td>"; echo "<td width=\"80%\" bgcolor=\"red\"><marquee behavior=\"scroll\" direction=\"left\"><B><font color=\"white\">Alert: </B>".$info['Main'] . "</marquee></font></td>"; echo "<td><CENTER></CENTER></td>"; echo "</TR></table>"; } ?> </BODY> </HTML>
  12. So I should have my page select only those entries that I want displayed, rather than going thru and delete them then? It isn't going to cause a memory issue or take longer to pull the information from the database...is it?
  13. Another question from the newbie! Is there a way to fresh a variable from a MySQL database without refreshing the page? I was thinking of setting up a loop such as: while ($num_rows == 0){ $num_rows = mysql_num_rows($result); echo "No change yet!"; } Is that the right was of doing it, or is there a different way?
  14. OH! Okay! I will try that. I got to get to bed, because I've been up all night doing this. But that makes sence though! I'll take a look at that tomorrow to see if it works. Thanks for all your help WebStyles!!!
  15. So it turns out that when you use the time() function, it creates a int. rather than the timestamping code. So when I changed Timestamper to an INT rather then TIMESTAMP, I got a value. I think I found exactly what I needed. How do I get a value for TIMESTAMP I guess is what I am really trying to ask.
  16. That is how I have it....I think my MySQL database is just broken! haha
  17. I forgot to delete that other var. I got rid of it now I changed the Timestamper column to Timestamper timestamp ON UPDATE CURRENT_TIMESTAMP No CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP. It still stills the default at all zeros. I am going to log into my other computer to take a print screen. I don't have that button on my labtop. Until then though, this is my new process.php file.
  18. wait...I think I have something going here....just got it to go thru with this <? $Main=$_POST['Main']; $Timestamper=time(); $gettime=time(); mysql_connect("****", "****", "****") or die(mysql_error()); mysql_select_db("a7405553_test") or die(mysql_error()); mysql_query("INSERT INTO `Message` VALUES ('$Main', '$Timestamper')"); Print "Your message will now be broadcasted."; ?> But the value comes up with all zeros in the table. I think I am close though!!!
  19. When I submit the form, no entry is created. The form seems to have went thru with no errors, but when I check the table it says: However, if I remove the Timestamper column, the form does submit and an entry is created. Just of course, with no timestamp though. :-\
  20. Okay. Thanks to other who helped me so far. I am almost done, but totally confused with this timestamp issue and MySQL. I haven't used HTML in awhile and decided to jump into PHP. I like PHP because it reminds me of C++, but please bare with me with the newbie questions. I have three files: test php: <html> <head> <title>PHP Test Page</title> </head> <body> <form action="process.php" method="post"> Message: <input type="text" name="Main"><br> <input type="submit" value="Submit"> </form> </body> </html> process.php <? $Main=$_POST['Main']; mysql_connect("*****", "*****", "*****") or die(mysql_error()); mysql_select_db("*****_test") or die(mysql_error()); mysql_query("INSERT INTO `Message` VALUES ('$Main')"); Print "Your message will now be broadcasted."; ?> admin.php <HTML> <HEAD> <TITLE>v2.0</TITLE> <meta http-equiv="refresh" content="20"> </head> <BODY> <?php // Connects to your Database $link = mysql_connect("*****", "*****", "*****"); mysql_select_db("*****_test", $link); $result = mysql_query("SELECT * FROM Message", $link); $num_rows = mysql_num_rows($result); if($num_rows == 0){ echo "<table width=\"100%\" border=\"0\"> "; echo "<tr><td width=\"10%\"><CENTER>LA</CENTER></td>"; echo "<td width=\"80%\"><CENTER>Order Menu</CENTER></td>"; echo "<td><CENTER>Blank</CENTER></td>"; echo "</TR></table>"; } else{ $info = mysql_fetch_assoc($result); echo "<table width=\"100%\" border=\"0\"> "; echo "<tr><td width=\"10%\"><CENTER>LA</CENTER></td>"; echo "<td width=\"80%\" bgcolor=\"red\"><marquee behavior=\"scroll\" direction=\"left\"><B>IMPORTANT MESSAGE: </B>".$info['Main'] . "</marquee></td>"; echo "<td><CENTER>Blank</CENTER></td>"; echo "</TR></table>"; } ?> </BODY> </HTML> MySQL 2.11.4 Message = Table Name Main varchar(500) = column #1 TimeStamper (datetime) = column #2 I want the current time of the submission of the form to be included with process.php, but I have no idea what I am doing with this whole time() function. I don't have it in the example above, but it was a mess and I guess I made up a lot of stuff that MySQL hasn't heard of before. What do I need to add to process.php to include a datetime value for Timestamper?
  21. I copied and pasted your code and it worked perfectly. Thank you so much for your help! As for the timestamp idea...yeah I could add a timestamp. How would I set up the DELETE ROW command for PHP to read it to MySQL?
  22. yeah, I kind of caught that after I went back to it. So I ended up changing it to: if($num_rows = 0) So if there are no rows, it would display normal text. Else would display the message. But it still comes up blank. I think I have a type-o somewhere.
  23. I'm still working on that one site. I'm not getting the data to come out right it looks like. It's not pulling the data from the MySQL right I think. Right after IMPORTANT MESSAGE: it comes up blank. Plus I was looking for help with this too:
×
×
  • 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.