Jump to content

radiohomer

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Everything posted by radiohomer

  1. man you are the best i thank you sooo much for everything i will learn this one day
  2. that is perfect im so grateful thank you one last question is there any way to only show 5 results? if not dont worry about it
  3. its still showing them in the wrong order its showing the newest at the bottom
  4. ok so this is the code that im now using from the code generator i have added the field "datetime" to the database and removed all the single time and date fields this is the code i use to add things to the database <form id="FormName" action="added.php" method="post" name="FormName"> <table width="448" border="0" cellspacing="2" cellpadding="0"> <tr> <td><input id="new_news_date" name="new_news_date" type="text" size="25" value="" maxlength="255"></td> </tr> <tr> <td><textarea id="new_news" name="new_news" rows="4" cols="40"></textarea></td> </tr> <tr> <td><input type="submit" name="submitButtonName" value="Add"></td> </tr> </table> </form> then i click on submit and it sends the data to this page <?php include("connect.php"); $new_news_date = trim($_POST['new_news_date']); $new_news = trim($_POST['new_news']); $query = "INSERT INTO new_news (id, new_news_date, new_news) VALUES ('', '$new_news_date', '$new_news')"; $results = mysql_query($query); if ($results) { echo "Details added."; } mysql_close(); ?> the index page which displays all the data is this code <?php include("connect.php"); $query = "SELECT * FROM new_news "; $result = mysql_query($query); $num = mysql_num_rows ($result); mysql_close(); if ($num > 0 ) { $i=0; while ($i < $num) { $new_news_date = mysql_result($result,$i,"new_news_date"); $new_news = mysql_result($result,$i,"new_news"); $id = mysql_result($result,$i,"id"); echo "<b>new_news_date:</b> $new_news_date<br>"; echo "<b>new_news:</b> $new_news<br>"; echo "<br><br>"; ++$i; } } else { echo "Sorry No News"; }?> and here is the sql query CREATE TABLE `new_news` ( `id` int(6) NOT NULL auto_increment, `new_news_date` datetime NOT NULL default '0000-00-00 00:00:00', `new_news` text NOT NULL default '', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) if there is anything else you need Pikachu2000 let me know again i really appreciate your help
  5. The two entries in there are only test data, i will be entering data through a different form
  6. Ok thank you, i will wait till your next reply, also if i dont reply its because my isp has gone down, i dont even have a dial tone on my phone line, im having to use my mobile to reply, Again thank you for helping me
  7. please if you would be so kind to help i will be VERY great full here is the website i used to get the code http://www.turningturnip.co.uk/free-mysql-php-generator/web-code-creator.php
  8. to be totally honest... i used a code generator to give me that code and its working perfect apart from its showing the old at the top and the new at the bottom
  9. hey guys i have this code below that grabs the data from the database <?php include("connect.php"); $query = "SELECT * FROM new_news "; $result = mysql_query($query); $num = mysql_num_rows ($result); mysql_close(); if ($num > 0 ) { $i=0; while ($i < $num) { $new_news_day = mysql_result($result,$i,"new_news_day"); $new_news_month = mysql_result($result,$i,"new_news_month"); $new_news_year = mysql_result($result,$i,"new_news_year"); $new_news_hour = mysql_result($result,$i,"new_news_hour"); $new_news_minute = mysql_result($result,$i,"new_news_minute"); $new_news_am_pm = mysql_result($result,$i,"new_news_am_pm"); $new_news = mysql_result($result,$i,"new_news"); $id = mysql_result($result,$i,"id"); echo "$new_news_day "; echo "$new_news_month "; echo "$new_news_year - "; echo "$new_news_hour:"; echo "$new_news_minute "; echo "$new_news_am_pm<br>"; echo "$new_news"; echo "<br><br>"; ++$i; } } else { echo "No News"; }?> here is the database structure with 2 test entries (please note that there will be more than 2 entries, the code is looped so it will repeat the output) they are sorted via ID here is a basic layout of the database ID new_news_day new_news_month new_news_year new_news_hour new_news_minute new_news_am_pm new_news 1 8th June 2011 10 32 am Testing the news. 2 9th June 2011 2 15 pm Testing the news again. now when it shows on the page its shown like this 8th June 2011 - 10:32 am Testing the news. 9th June 2011 - 2:15 pm Testing the news again. everything works and connects ok ect ect BUT as you can see by the PHP code above it gets the data from the database and repeats to display all the data in the database so if there is only one entry it will only show one entry if there were 200 entries it will show all 200 entries now as you see the code is arranging them in order oldest at the top and newest at the bottom... is there any way to change the code so it shows the newest at the top and oldest at the bottom?? hope people can understand what im after in short the code is showing this 8th June 2011 - 10:32 am Testing the news. 9th June 2011 - 2:15 pm Testing the news again. i want it to show this 9th June 2011 - 2:15 pm Testing the news again. 8th June 2011 - 10:32 am Testing the news. thanks guys
  10. thanks for your input Fugix i have just tried that and it didnt work i have found a different way to do this my whole reason for the code above was because index.php has 3 frames on there and whenever i clicked a link it just opened in that frame and left the rest showing the content from index.php i never thought to use parent.top or target="_top" here is the code i have used and have got working <select> <option>--Choose--</option> <option onclick=parent.top.location="index.php">Index</option> <option onclick=parent.top.location="page1.php">Page 1</option> </select> this gets rid of the frames on the index page and loads page1.php in the full view
  11. ok so its as the title says is there a way to open a new window and close the old one? ok so ill explain a little more on what i want to achieve i have 2 pages index.php page1.php on the index.php page i have a dropdown box with 3 options <select> <option>--Choose--</option> <option onclick="window.open('index.php')">Index</option> <option onclick="window.open('page1.php')">Page 1</option> </select> ok so the dropdown box is doing what i would like by opening a new window but i would like to close the old one. at the moment this is whats happening the user is viewing "index.php" he clicks on the dropdown and selects "Page 1" this opens a new window displaying the content of page1.php but the index.php page is still open. this is what i would like to happen the user is viewing "index.php" he clicks on the dropdown and selects "Page 1" this opens a new window displaying the content of page1.php and also closes index.php. is this possible?? i just cant get it to work... i have seen it done before but cant find the website that i saw it on i have tried using onclick, onchange ect ect if anyone could help me with this that would be great
  12. managed to get it working thanks for the help guys
  13. cant get that working where ever i put it and what ever i do with it
  14. im not fussed on authenticating ect the website is on a local network and not open to the WWW the code is so a select few of the users can access other area's but im wanting this to run off a DB if someone could edit / change the code below to allow it to GET the data from the database that would be great im not bothered about a registration page or anything i just want the code below to connect to the DB so it can login the right user if that makes sense... <?php /* $LOGIN_INFORMATION = array( 'test' => 'testpass', 'admin' => 'passwd' ); <?php include("password_protect.php"); ?> logout link http://www.example.com/path/to/protected/page.php?logout=1 */ ################################################################## # SETTINGS START ################################################################## // Add login/password pairs below, like described above $LOGIN_INFORMATION = array( 'test' => 'testpass', 'admin' => 'passwd' ); // NOTE: all rows except last must have comma "," at the end of line // request login? true - show login and password boxes, false - password box only define('USE_USERNAME', true); // User will be redirected to this page after logout define('LOGOUT_URL', '/'); // time out after NN seconds of inactivity. Set to 0 to not timeout define('TIMEOUT_MINUTES', 1800); // 1m = 60 // 5m = 300 // 10m = 600 // 15m = 900 // 20m = 1200 // 30m = 1800 // 60m = 3600 // This parameter is only useful when TIMEOUT_MINUTES is not zero // true - timeout time from last activity, false - timeout time from login define('TIMEOUT_CHECK_ACTIVITY', true); ################################################################## # SETTINGS END ################################################################## /////////////////////////////////////////////////////// // do not change code below /////////////////////////////////////////////////////// // timeout in seconds $timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES ); // logout? if(isset($_GET['logout'])) { setcookie("verify", '', $timeout, '/'); // clear password; header('Location: ' . LOGOUT_URL); exit(); } if(!function_exists('showLoginPasswordProtect')) { // show login form function showLoginPasswordProtect($error_msg) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><head> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="robots" content="noindex, nofollow"> <title>login</title> <link rel="stylesheet" href="index_files/style_optimized.css" type="text/css"> <!--[if IE]> <style type="text/css"> #mid{ height:300px; } </style> <![endif]--> <meta name="robots" content="noindex, nofollow"> </head><body> <div id="wrap"> <div id="top"></div> <div id="mid" style="height:auto"> <div id="content-wrap" align="center"> <form method="post"> <table class="login" cellpadding="0" cellspacing="0" width="200px"> <tbody><tr> <td colspan="2" align="left"><strong><font size="+1">Login</font></strong></td> </tr> <tr> <td class="login_lines">Username </td> <td class="login_lines"><input type="text" name="access_login" /><br /></td> </tr> <tr class="row2"> <td class="login_lines">Password </td> <td class="login_lines"><input type="password" name="access_password" /></td> </tr> <tr> <td colspan="2" style="text-align: center;"><input value="Login" class="input-button" tabindex="3" type="submit"></td> </tr> </tbody></table> </form><br /> <script type="text/javascript"> //<![CDATA[ document.getElementById("user").focus(); //]]> </script> <br><br></div> </div> <div id="bot"> </div> </div> </body></html> <?php // stop at this point die(); } } // user provided password if (isset($_POST['access_password'])) { $login = isset($_POST['access_login']) ? $_POST['access_login'] : ''; $pass = $_POST['access_password']; if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION) || (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) ) ) { showLoginPasswordProtect("Incorrect password."); } else { // set cookie if password was validated setcookie("verify", ($login.'%'.$pass), $timeout, '/'); // Some programs (like Form1 Bilder) check $_POST array to see if parameters passed // So need to clear password protector variables unset($_POST['access_login']); unset($_POST['access_password']); unset($_POST['Submit']); } } else { // check if password cookie is set if (!isset($_COOKIE['verify'])) { showLoginPasswordProtect(""); } // check if cookie is good $found = false; foreach($LOGIN_INFORMATION as $key=>$val) { $lp = (USE_USERNAME ? $key : '') .'%'.$val; if ($_COOKIE['verify'] == ($lp)) { $found = true; // prolong timeout if (TIMEOUT_CHECK_ACTIVITY) { setcookie("verify", ($lp), $timeout, '/'); } break; } } if (!$found) { showLoginPasswordProtect(""); } } ?>
  15. the original code went like this and wasnt based on mysql it was done with cookies so the code went like this <?php $LOGIN_INFORMATION = array( 'test' => 'testpass', 'admin' => 'passwd' ); ?> i have added the include and the $$ parts and so far it works how it should BUT its only working off the last entry in the DB this is only a simple login form that i INCLUDE i never used to connect to a DB or anything it used to use the above array and ask to login and you had to enter one of those to be able to gain access here is the code to help you understand PLEASE NOTE: if you can change the code below to connect to the DB and be able to login ect please do soo <?php /* $LOGIN_INFORMATION = array( 'test' => 'testpass', 'admin' => 'passwd' ); <?php include("password_protect.php"); ?> logout link http://www.example.com/path/to/protected/page.php?logout=1 */ ################################################################## # SETTINGS START ################################################################## // Add login/password pairs below, like described above $LOGIN_INFORMATION = array( 'test' => 'testpass', 'admin' => 'passwd' ); // NOTE: all rows except last must have comma "," at the end of line // request login? true - show login and password boxes, false - password box only define('USE_USERNAME', true); // User will be redirected to this page after logout define('LOGOUT_URL', '/'); // time out after NN seconds of inactivity. Set to 0 to not timeout define('TIMEOUT_MINUTES', 1800); // 1m = 60 // 5m = 300 // 10m = 600 // 15m = 900 // 20m = 1200 // 30m = 1800 // 60m = 3600 // This parameter is only useful when TIMEOUT_MINUTES is not zero // true - timeout time from last activity, false - timeout time from login define('TIMEOUT_CHECK_ACTIVITY', true); ################################################################## # SETTINGS END ################################################################## /////////////////////////////////////////////////////// // do not change code below /////////////////////////////////////////////////////// // timeout in seconds $timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES ); // logout? if(isset($_GET['logout'])) { setcookie("verify", '', $timeout, '/'); // clear password; header('Location: ' . LOGOUT_URL); exit(); } if(!function_exists('showLoginPasswordProtect')) { // show login form function showLoginPasswordProtect($error_msg) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><head> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="robots" content="noindex, nofollow"> <title>login</title> <link rel="stylesheet" href="index_files/style_optimized.css" type="text/css"> <!--[if IE]> <style type="text/css"> #mid{ height:300px; } </style> <![endif]--> <meta name="robots" content="noindex, nofollow"> </head><body> <div id="wrap"> <div id="top"></div> <div id="mid" style="height:auto"> <div id="content-wrap" align="center"> <form method="post"> <table class="login" cellpadding="0" cellspacing="0" width="200px"> <tbody><tr> <td colspan="2" align="left"><strong><font size="+1">Login</font></strong></td> </tr> <tr> <td class="login_lines">Username </td> <td class="login_lines"><input type="text" name="access_login" /><br /></td> </tr> <tr class="row2"> <td class="login_lines">Password </td> <td class="login_lines"><input type="password" name="access_password" /></td> </tr> <tr> <td colspan="2" style="text-align: center;"><input value="Login" class="input-button" tabindex="3" type="submit"></td> </tr> </tbody></table> </form><br /> <script type="text/javascript"> //<![CDATA[ document.getElementById("user").focus(); //]]> </script> <br><br></div> </div> <div id="bot"> </div> </div> </body></html> <?php // stop at this point die(); } } // user provided password if (isset($_POST['access_password'])) { $login = isset($_POST['access_login']) ? $_POST['access_login'] : ''; $pass = $_POST['access_password']; if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION) || (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) ) ) { showLoginPasswordProtect("Incorrect password."); } else { // set cookie if password was validated setcookie("verify", ($login.'%'.$pass), $timeout, '/'); // Some programs (like Form1 Bilder) check $_POST array to see if parameters passed // So need to clear password protector variables unset($_POST['access_login']); unset($_POST['access_password']); unset($_POST['Submit']); } } else { // check if password cookie is set if (!isset($_COOKIE['verify'])) { showLoginPasswordProtect(""); } // check if cookie is good $found = false; foreach($LOGIN_INFORMATION as $key=>$val) { $lp = (USE_USERNAME ? $key : '') .'%'.$val; if ($_COOKIE['verify'] == ($lp)) { $found = true; // prolong timeout if (TIMEOUT_CHECK_ACTIVITY) { setcookie("verify", ($lp), $timeout, '/'); } break; } } if (!$found) { showLoginPasswordProtect(""); } } ?>
  16. here is "connect.php" <?php $hostname='localhost'; //// specify host, i.e. 'localhost' $user='********'; //// specify username $pass='********'; //// specify password $dbase='********'; //// specify database name $connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL"); $db = mysql_select_db($dbase , $connection) or die ("Can't select database."); ?> and here is the other part "index.php" found in "users/index.php" <?php include("connect.php"); $query = "SELECT * FROM user "; $result = mysql_query($query); $num = mysql_num_rows ($result); mysql_close(); if ($num > 0 ) { $i=0; while ($i < $num) { $user_login_username = mysql_result($result,$i,"user_login_username"); $user_login_password = mysql_result($result,$i,"user_login_password"); $id = mysql_result($result,$i,"id"); ++$i; } } else { echo "The database is empty"; }?> if there is anything else just ask
  17. hey guys i have to following code <?php include("users/index.php"); ?> <?php $LOGIN_INFORMATION = array( $user_login_username => $user_login_password, ); ?> the script connects to the database and fetches the data the problem im having is the table has 3 tables "ID" - "user_login_username" - "user_login_password" in those tables are 2 entries "1" - "test" - "user" "2" - "test1" - "user1" now on the login screen when i enter the username and password "test1" and "user1" it logs me in fine and works how i want it to but when i enter "test" and "user" it doesnt work if i add another entry so the table shows "1" - "test" - "user" "2" - "test1" - "user1" "3" - "test2" - "user2" and i try the to login again with "test" and "user" it fails and so does "test1" and "user1" but "test2" and "user2" works the script is only fetching the last entry from the DB is there anyway to login with any user in the DB?? if this dont make sense or you need more info please ask Thanks
  18. thank you ilovephp i would also like to thank Paul for his comment below sent via PM this helped A LOT and is now working
  19. hey guys i have a script that creates a cookie named "MyLoginPage" now everything works well the cookie is saved and it keeps the user logged in The Question ok so im wanting to create a link that will delete the cookie so when the user clicks the link it will delete the cookie is this possible?? if so, how?? many thanks
  20. ok it doesnt matter i have sorted this out thanks
  21. so how would i place that code onto the file i have again i dont know much about php and im still learning would i just put that code into the update.php or do i need to change / add things to it? it would be very helpful if you could insert the values to check "FName" "LName" "CNumber" or maybe a guide or something i can follow
  22. hey guys i have this code FILE NAME "index.php" <?php // make a connection to the database mysql_connect ("localhost", "root", "vertrigo") or die ('Error: I Failed To Connect To The Database ' . mysql_error()); mysql_select_db ("test"); // Get Data $query = mysql_query("SELECT * FROM TestTable"); // display the data and loop while ($row = mysql_fetch_array($query)) { echo "<br /> ID: ".$row['ID']."<br /> First Name: ".$row['FName']."<br /> Last Name: ".$row['LName']."<br /> Contact Number: ".$row['CNumber']."<br />";} ?> <form method="post" action="update.php"> <table border="1" align="center"> <tr> <td align="right" width="220">ID: </td> <td align="left" width="220"> <input type="text" name="ID" size="30" /></td> </tr> <tr> <td align="right" width="220">First Name: </td> <td align="left" width="220"> <input type="text" name="FName" size="30" /></td> </tr> <tr> <td align="right" width="220">Last Name: </td> <td align="left" width="220"> <input type="text" name="LName" size="30" /></td> </tr> <tr> <td align="right" width="220">Contact Number: </td> <td align="left" width="220"> <input type="text" name="CNumber" size="30" /></td> </tr> <tr> <td align="right" width="220"><input type="reset" value="Reset" /> </td> <td align="left" width="220"> <input type="submit" value="Update Database" /></td> </tr> </table> </form> and i also have this code FILE NAME "update.php" <?php $ID = $_POST['ID']; $FName = $_POST['FName']; $LName = $_POST['LName']; $CNumber = $_POST['CNumber']; mysql_connect ("localhost", "root", "vertrigo") or die ('Error: I Failed To Connect To The Database ' . mysql_error()); mysql_select_db ("test"); $query="INSERT INTO testtable (ID, FName, LName, CNumber)VALUES ('".$ID."','".$FName."', '".$LName."', '".$CNumber."')"; mysql_query($query) or die ('Error Updating Database'); echo "Database Updated Sucsessfully With: ".$ID." ".$FName." ".$LName." ".$CNumber ; ?> ok so the script is working like a charm its sending the data to the database as i want it to. the problem i have is that i want to be able to update the info that is already on the database lets say i want to change a phone/contact number i have typed the ID number into the ID text field and the same first and last name into there correct boxes and then typed in the new phone number i then click submit and i get the error ""Error Updating Database"" i have looked all over the forum and net to see what i have done wrong to not allow this code to update can anyone help me out here please im quite new to the php language and could really do with some pointers thanks Steve
×
×
  • 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.