Jump to content

drayarms

Members
  • Posts

    125
  • Joined

  • Last visited

Everything posted by drayarms

  1. Hello people, well this is not an Ajax question. It's a Javascript/DOM question but I figured I could post it on here since Ajax programmers must be Javacript gurus to begin with, or at least so I think, and since there is no forum on this site specifically for Javascript. I have looked at this code in and out and can't seem to find out what the problem is. I have a link on a webpage with id name comment_stream on which when users click, is supposed to display an otherwise hidden comment box (id name comment_stream_div) and at the same time, hide the comment link, you know the type on facebook and other social networking sites. I am using javascript functions to accomplish this with an onclick event. The idea is to toggle between the display attributes (block and none) of the elements i wish to hide or display with the onclick event. Well, my code seems to work, except that as the topic clearly states, the expected results simply flash for a brief second or two and then dissapear. They don't hang around as expected. I will show the javasscript below, as well as the the html for the elements involved and the css. <script type='text/javascript'> function show_comment_stream_div() { document.getElementById('comment_stream_div').style.display = 'block'; document.getElementById('comment_stream').style.display = 'none'; document.getElementById('comment_stream_div').syle.position = 'relative' ; document.getElementById('comment_stream_div').syle.bottom = '82px' ; document.getElementById('comment_stream_div').syle.left = '123px' ; } </script> //Print the comment link <p id = 'comment_stream' onclick = 'show_comment_stream_div()' > <a href = ''> Comments: </a> </p>"; //Print out the comments div. <div id = 'comment_stream_div' onmouseover = 'show_close_comment_stream_div()' onmouseout = ' hide_close_comment_stream_div()'> <p id = 'close_comment_stream_div' onclick = 'hide_comment_stream_div()'> <a> X </a> </p> <form action = 'status_comment_entry.php'> <input id = 'comment_stream_input' type = 'textarea' rows = '8' cols = '20' value ='' name = 'comment' /> <br/> <input id = 'comment_stream_submit' type = 'submit' value = 'submit!' name = 'submit' /> </form> </div> #comment_stream {position:relative;bottom:70px;left:230px; color:#2d73b9; display:block;} #comment_stream_div { border-style:solid; border-width:1px; border-color:#c0c0c0; display:none;} Well folks, can anyone tell me what I'm doing wrong? Here are screenshots of the elements in question:
  2. @AbraCadave, I noticed that b4 reading your reply. Thanks.
  3. Thanks for all the suggestions. @ AbraCadave Did you mean 'publications' as type and 'images' as type ?? Notice that my table names are publications and images, not publication and image. those are columns that correspond to the respective tables. Thanks for the suggestion anyways.
  4. Hello all, I'm trying to use a union query to fetch rows from unrelated tables, and display all the rows, sorting by some common critarion (in this case, the time the entry was posted/registered/uploaded). The tables are named publications and images. So here is the select statement and associated code: <?php //Connect to database require("config.php"); //Query the database. $query = "SELECT publication AS a, cartegory AS b, pub_time AS c FROM publications UNION ALL SELECT image AS a, image_cartegory AS b, image_time AS c FROM images ORDER BY c DESC"; $result = mysql_query($query); if(!$result) { die('<p>Could not retrieve the data because: <b>' . mysql_error(). '</p>'); // Handle as desired }else{ //If query is valid. if(mysql_num_rows($result) > 0){ while ($row = mysql_fetch_assoc($result)){ echo "<p>".$row['a']."</p>"; }//End of while loop }else{//If no rows were returned echo "no rows returned"; } }//Closes if query is valid statement. ?> Well as expected, all the contents from the image and publication columns are displayed in the order specified. But now my problem is, I want to be able to distinguish between the rows, depending on their table of origin, in order to format them differently. For example, let's say I want the rows from the image table to be printed out with one font style and the rows from the publications table to be printed with a different font style, how do I go about that? So far I have tried things like: //For the sake of simplicity, I won't include the html formatting here while ($row = mysql_fetch_assoc($result)){ if ($row['a'] == $row['publication']){echo $row['publication'];} else{echo $row['image'];} //OR if ('a' == 'publication'){echo $row['a'];} elseif ('a' == 'image'){echo $row['a'];} Well I hope you get the idea what I'm trying to achieve here. So far, these and similar lines I've tried only yield a blank page. I'm starting to wonder if it is even possible to format the rows differently based on their table of origin. So folks, please tell me if there is anyway what I'm trying to do can be done.
  5. Hello all, I'm trying to display the contents of a mysql select query in a particular format. So basically, the result of the query returns 3 rows with values, red, white, and blue. I want to display these result in a single string in the following format: 'red', 'white', 'blue' So I use this code in an attempt to achieve that: $query = "SELECT * FROM table WHERE id = 'someNumber' "; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ $colors = " ' ".$row['color']." ' " . "," ; echo $colors; $col = substr($colors, 0, -1); echo $col; } So the idea is to wrap each of the row values(red white and blue) within single quotes and separate them with commas. Then I try to trim the last comma after the last entry, in this case blue to get my expected result. As expected the $colors variable reads: 'red', 'white', 'blue', But the $col variable reads: 'red' 'white' 'blue' instead of the expected 'red', 'white', 'blue' So the substr() function instead of just removing the last comma from the $colors string, removes the the last comma from each of the components of that string. Now I thought that PHP would treat $colors as just one string but apparently, that's not the case. How I can make it so? Can anyone tell me what to do next? Every other string trimming function I tried yielded the same undesirable result. Thanks.
  6. I'm creating a site where members have to log in in order to access the site's pages. I'm using sessions to log the members in. Each member has a unique session id that grants him access to the site. At the top of each of the sit'es pages, I authenticate the user using the following code. <?php //Start session session_start(); //Check whether the session variable id is present or not if(!isset($_SESSION['id']) || (trim($_SESSION['id']) == '')) { header("location: access_denied.php"); exit(); } ?> So this bit of code basically redirects the user to an access denied page, if the user isn't authenticated otherwise, the user can access the page. Right below that bit of code, I have this code that ends the session after 15 minutes of inactivity. <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //Get the current page url to pass on to the session expired page. $url=urlencode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 900)) { // last request was more than 15 minates ago session_destroy(); // destroy session data in storage session_unset(); // unset $_SESSION variable for the runtime header("location: session_expired.php?url=$url"); } $_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp ?> What do I need to do to keep the session permanently active until either the 15 minutes is reached or I manually sign out ? Often times the page upon refreshing, gets redirected to the access_denied.php which clearly indicates that my session id is not lingering on and gets destroyed prematurely. What do I do??
  7. I must begin by apologizing for the lengthiness of this posting but I really couldn't edit it to be any shorter. Hopefully one of you reading this is quite familiar with both PHP pagination, and displaying search results in rows. Well here's what I'm trying to do. I created a page that displays results from a simple search query. the results displayed are the pictures of a users of a website, alongside their usernames. I'm trying to display the results in rows of 4, as dictated by the $items variable on line 27 of the script i will post below in a minute. Well, the script works just fine as intended. Then when I add the blocks of code that should paginate the results (the pagination blocks of code are indented to the left of the script), I run into a bunch of problems. First of all, oddly enough, when I set the number of rows to be displayed per page to any number order than 4, the page never completes the loading process and the pagination links are not displayed. The page only loads fully and displays the pagination links when $numrows is set to 4 and even then, when I click on the link to take me to the next page, no results get displayed. Instead I get the "No results match this search query' message which is displayed when the query returns no results. It seems to me like there are problems with the pagination code, I'm not quite sure. I have tried about 3 different pagination codes which I found from online tutorials and they all present the same problems. Any help? Here is my page. PS One more problem, when I set the $limit variable(which sets the number of results displayed per row) to 4, the data to be displayed(pictures) get extra padding between them, pushing the last one out of the page. Ironically as explained above, this is the only case where the page loads completely and the pagination links get displayed. To make you picture this easier, I have removed the authentication restrcition off this page and I'll provide the link for you to see what I'm talking about http://mygeneric.info/search_results.php?ethnicity=white <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user require('auth.php'); //Set session timeout require('inactive.php'); //Set the page title before the header file $title = 'Search Results'; //Get variables from previous page, profile_searh.php $ethnicity = $_GET['ethnicity']; //Items to display per row. $items = 4; require ('header.php'); //need the header echo' <div id="content" class=""> <div id="left_content" class=""> </div> <!--closes left content--> <div id="right_content" class=""> <div id= "right_content_inner_border"> '; //Obtain the required page number from the $_GET array. Note that if it is not present it will default to 1. if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // if // Connect to the database. require_once ('config.php'); //Count how many rows will satisfy the current query.. $query = "SELECT* FROM members INNER JOIN images ON members.member_id = images.member_id WHERE members.ethnicity = '$ethnicity' AND images.image_cartegory = 'main' "; $result = mysql_query($query); $numrows = mysql_num_rows($result); //Use the values in $rows_per_page and $numrows in order to identify the number of the last page. $rows_per_page = 4; $lastpage = ceil($numrows/$rows_per_page); //Check that the value of $pageno is an integer between 1 and $lastpage. $pageno = (int)$pageno; if ($pageno > $lastpage) { $pageno = $lastpage; } // if if ($pageno < 1) { $pageno = 1; } // if //Construct the LIMIT clause for the sql SELECT statement. $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; //Now we can issue the database qery and process the result. $query = "SELECT* FROM members INNER JOIN images ON members.member_id = images.member_id WHERE members.ethnicity = '$ethnicity' AND images.image_cartegory = 'main' $limit "; $result = mysql_query($query) or die(mysql_error()); //Check for success here. if(!$result) { die('<p>Could not retrieve the data because: <b>' . mysql_error(). '</p>'); // Handle as desired }else{ //If query is valid. if(mysql_num_rows($result) > 0){ //Start a table to contain the results. echo '<table border= "0" width="100%" cellspacing= "1" cellpadding ="1" align ="center"> '; //Need a counter. $i = 0; //Retrieve each record. while ($row = mysql_fetch_assoc($result)){ //Do we need to start a new row? if($i == 0) {echo "<tr>\n";} //Print the record echo"\t<td align=\"center\"> <div id='search_pic_wrap'> <div id='no_photo'>"; //Define variables to be passed via url. $friend= $row['member_id']; //Make sure an uploaded photo is present. if ($row['image'] !== NULL) { echo"<a href='friend.php?friend=$friend' >"; // Note that we are building our src string using the filename from the database. echo "<img src=\"images/" . $row['image'] . "\" width=\"140\" maxheight=\"154\" />"; echo "</a>"; echo"<h2 style= 'position:relative;bottom:25px;'>" .$row['username']. "</h2> //End of if there is an uploaded pic.} </div> <!--closes no photo--> </div> <!--closes search pic wrap--> </td>\n"; //Icrement the counter. $i++; //Do we need to end the row? if ($i == $items) {echo "</tr>\n"; $i = 0; //Reset counter. } }//End of while loop. if ($i > 0) {//Last row was incomplete. //Print the necessary number of cells. for ($i < $items; $i++ { echo "<td> </td>\n"; } //Complete the row. echo '</tr>'; }//End of if $i is greater than 0 //Close the table. echo '</table>'; echo '<div style= " position:absolute;top:1050px;left:600px;">'; //Construct the hyperlinks which will allow the user to select other pages. We will start with the links for any previous pages. if ($pageno == 1) { echo " FIRST PREV "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> "; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> "; } // if //Inform the user of his current position in the sequence of available pages. echo " ( Page $pageno of $lastpage ) "; //Provide the links for any following pages. if ($pageno == $lastpage) { echo " NEXT LAST "; } else { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> "; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> "; } // if echo'</div>'; }else {//No rows returned. End of if number of rows is greater than 0 loop. echo 'No results match this search query.' ; } }//End of else if query is valid. echo' </div> <!--closes right content inner border--> </div> <!--closes right content--> </div> <!--closes content--> '; require ('footer.php'); //need the footer ?>
  8. Here is a simplified version of a script which I named register.php that processes user input from a registration form. <?php if (isset($_POST['submitted'])) { $firstname = mysql_real_escape_string($_POST['firstname']); $lastname = mysql_real_escape_string($_POST['lastname']); header("Location: register_confirm_page.php?firstname=$firstname&lastname=$lastname"); } ?> As intended, the firstname and lastname posted variables are carried over to a redirected page register_confirm_page.php where the user is supposed to review his registration details before clicking the final submit button to be registered. Below is a simplified version of the register confirm page: So far everything works just fine as intended. <?php //Retrieve variables from previous page $firstname=$_GET['firstname']; $lastname=$_GET['lastname']; //Show user his details echo "Firstname:" .$firstname. "<br/>" ; echo "Lastname:" .$lastname //Show the submit button. echo'<form method="post" action="register_confirm.php?firstname=$firstname&lastname=$lastname"> <input type="submit" name="submit" value="Register!" /> </form> '; ?> Now the intent is to send the first name and last name to yet another page register_confirm.php, where the value is finally submitted into my database. To keep it simple, I won't include this third page, but what I basically did there was use the GET method as above, to retrieve the values again. Well this time around, the first and last names are not sent to the third page. Instead, the literal values '$firstname' and '$lastname' are passed through the url to the third page and I know this because that's what shows up in the url when I click the submit button and that's also what shows up in my database table. Does anyone understand why this may be happening and not what I expected would happen? I have passed variables between more than 2 pages before but this is the first time I am encountering this problem. I really can't see what is being done wrong here. Perhaps someone can.
  9. @skunkbad,,,, are you saying that i should change the line if (isset($_POST['submitted'])) { to if (isset($_GET['submitted'])) { ??
  10. You must all be familiar with those annoying messages that pop up on your screen sometimes when you try to navigate a website backwards on you browser, like this one I get on Safari: Are you sure you want to resend the form again? To reopen this page, Safari must resend a form. this might result in duplicate purchases, comments or other actions. On google chrome, I get this: Confirm Form Resubmission This web page requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed. Press Reload to resend that data and display this page. I pro So basically, I have a form which takes some inputs. Then on a second page, I process those inputs with a select query, and on the same page, display the results of the select query . Then on that display page, I have a few links which take the user to 3rd pages. When I try to hit the previous page button on one of the third pages to get back to the display page, I get those above messages and I'm required to refresh the page before my results are redisplayed. How can I avoid this. My suspicion is that this happens because i'm using the same php script to do both the processing and the displaying of the results. Any insights are appreciated. If it helps, I'll include a simplified version of the page that processes the form and displays the results below. <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user require('auth.php'); echo' <div id="content" class=""> '; if (isset($_POST['submitted'])) { // Connect to the database. require_once ('config.php'); //Query the database. $sql = "SELECT * FROM members INNER JOIN images ON members.member_id = images.member_id WHERE members.ethnicity = '{$_POST['ethnicity']}' AND images.image_cartegory = 'main' "; $query = mysql_query($sql); //Check for success here. if(!$query) { die('<p>Could not retrieve the data because: <b>' . mysql_error(). '</p>'); // Handle as desired }else{ //If query is valid. if(mysql_num_rows($query) > 0){ //Retrieve each record. while ($row = mysql_fetch_assoc($query)){ //Define variables to be passed via url. $friend= $row['member_id']; //Print the records. echo" //Make sure an uploaded photo is present. if ($row['image'] !== NULL) { echo"<a href='friend.php?friend=$friend' >"; // Note that we are building our src string using the filename from the database. echo "<img src=\"images/" . $row['image'] . "\" width=\"140\" maxheight=\"154\" />"; echo "</a>"; echo"<h2 style= 'position:relative;bottom:25px;'>" .$row['username']. "</h2>"; //End of if there is an uploaded pic.} }//End of while loop. }else {//No rows returned. End of if number of rows is greater than 0 loop. echo 'No results match this search query.' ; } }//End of else if query is valid. }//End of if form is submitted statement. echo' </div> <!--closes content--> '; ?>
  11. I have tried the following variations but non works if($row['relation'] = "" ){ if($row['relation'] = '' ){ if($row['relation'] = NULL ){ if($row['relation'] IS NULL ){ if(strlen($row['relation']) = 0 ){ So how would one refer to a cell that is empty?
  12. I wrote the search form below to enable users search other users of a site based on certain criteria like age, race etc. Then I wrote the php script beneath, to execute that search. I decided to make the script very simple, searching only for one criterion for now (ethnicity). So even though I have several fields in the search form, I wrote the script to process only one of those fields(ethnicity). So basically, the script searches all records for members on the site from two tables called images and members(the members table has an "ethnicity column"), who meet the user's ethnicity preference and returns certain columns for all members who meet that preference. Well when I click the submit button, all I get is "Form not submitted". I added that form not submitted clause at the end of the script just after I had tweaked the script in every way possible but got nothing but a blank page every time I submitted the form. So take a look people and tell me what could be going wrong here. Appreciate any help. <form id="search_profiles_form" action= "profile_search.php"> Seeking A: <select name= "sex"> <option value= "man">Man</option> <option value= "woman">Woman</option> <option value= "both">Both</option> <select> <p> <tab> Age Range: <?php print '<select name= "min_age">'; for ($age = 18; $age <= 99; $age++) { print "\n<option value=\"$age\">$age</option>"; } print '</select>'; ?> </tab> <tab> and: <?php print '<select name= "max_age">'; for ($age = 18; $age <= 99; $age++) { print "\n<option value=\"$age\">$age</option>"; } print '</select>'; ?> </tab> </p> <p>Distance: <select name= "distance"> <option name="5">Within 5 Miles</option> <option name="10">Within 10 Miles</option> <option name="50">Within 50 Miles</option> <option name="100">Within 100 Miles</option> <option name="250">Within 250 Miles</option> <option name="any">Beyond 250 Miles</option> </select> </p> <p>Ethnicity: <select name= "ethnicity"> <option name="black">Black/African Descent</option> <option name="white">Caucasian?European Descent</option> <option name="latino">Hispanic Non White</option> <option name="asian">Asian Descent</option> <option name="native_american">Native American</option> <option name="pacific_islander">Pacific Islander</option> <option name="indian">Indian Descent</option> <option name="middle_east">Middle Eastern</option> <option name="other">Other</option> </select> </p> <p>Last Active: <select name= "last_active"> <option name="0">Online Now</option> <option name="1">1 Hr Ago</option> <option name="5">5 Hrs Ago</option> <option name="24">24 Hrs Ago</option> <option name="1wk">1 Week Ago</option> <option name="3wk">Over 3 Weeks Ago</option> </select> </p> <input type="hidden" name="submitted" value="TRUE"/> <p> <input type ="submit" value="Search!"/> </p> </form> And here goes the php script. <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user require('auth.php'); if (isset($_POST['submitted'])) { // Connect to the database. require_once ('config.php'); //Query the database. $sql = "SELECT * FROM members INNER JOIN images ON members.member_id = images_member_id WHERE members.ethnicity = '{$_POST['ethnicity']}' AND images.cartegory = 'main' "; $query = mysql_query($sql); //Check for success here. if(!$query) { trigger_error("SQL query $sql failed: " . mysql_error(), E_ERROR); // Handle as desired }else{ //If query is valid. if(mysql_num_rows($query) > 0){ while ($row = mysql_fetch_assoc($query)){ //Redirect to search results page. echo $_POST['ethnicity']; echo $row['member_id']; echo $_SESSION['id']; echo $row['image']; } }else {//No rows returned. echo 'No results match this search query.' ; } }//End of else if query is valid. }else{ echo "form not submitted";} ?>
  13. After trying all your suggestions, I now get this error message: Parse error: syntax error, unexpected T_VARIABLE in /home/a4993450/public_html/profile_search.php on line 47. Clearly the query is working but the syntax on the redirect line just isnt right.
  14. I want to query a database (search) and pass the desired columns from the search results to another page like so: <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user require('auth.php'); if (isset($_POST['submit'])) { // Connect to the database. require_once ('config.php'); //Query the database. $sql = "SELECT* FROM members INNER JOIN images ON members.member_id = images_member_id WHERE members.ethnicity = '{$_POST['ethnicity']}'"; $query = mysql_query($sql); if(mysql_num_rows($query) > 0){ while(($row = mysql_fetch_assoc($query)) !== false) { //Redirect to search results page. header("Location: search_results.php?friend='.$row['member_id'].'&me='.$_SESSION['id'].' &pic='.$row['image'].'&name='.$row['username'].'"); } } else { //If no results found. echo 'No results match this search query.' ; } } ?> I get the following error when i try to run the page (by submitting a form from another page which executes this page): Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a4993450/public_html/profile_search.php on line 31 The culprit line is this one: header("Location: search_results.php?friend='.$row['member_id'].'&me='.$_SESSION['id'].' &pic='.$row['image'].'&name='.$row['username'].'"); As you can see, I eliminated all white space between the variables and concatenations, thinking that that was the problem but I keep getting the error message. I'm at a loss about what to do next. Any help?
  15. @Pikachu Well I forgot to mention that there are other search parameters besides gender. Take for example lets say I had to search for gender AND interest. That compels me to specify the WHERE clause for both columns right? With that in mind, how would I handle this?
  16. I'm trying to create a search form where members of a site can search other members whose user information is stored in a mysql database. One of the search parameters is gender which searches for records from a column in the database called gender where members can either have the value "man" or "woman". The user can choose between 3 options from a pull down menu named gender (man, woman, both). Then I'm thinking about using a select query to search the database upon submission of the form, which goes something like this: $sql= SELECT* FROM members WHERE gender ='{$_POST['gender']}' ; Now I can easily assign the value "man" for the option man in the pull down menu and "woman for the option woman, to match their corresponding names in the database. The problem lies with the "both" option which has to be either man or woman. I'm thinking about assigning it the value "man OR woman" so that when the form is submitted, the query would read: SELECT*FROM members WHERE gender ='{$_POST[man OR woman']}; I just don't know if this would be a right usage of the OR keyword and if such a query would work. Before trying it out, I'd like to know if this makes any sense and if not, what's an alternative way to work around this?
  17. @cyberrobot. So which character do you suggest I explode the string based on?
  18. I'm trying to display error messages on the same page that submits a form (register_page.php). So in the script that executes the form submission, I create an array to hold all the error messages, and towards the end of the script I include a conditional at the end, which does the following if there are errors: First I convert the $errors array into a string, url encode it, then pass it into the url of the target page (register_page.php). Then on the target page, I retrieve the message through GET, url decode it, reconvert it to an array and try to print it out the contents of the array. So here is the excerpt of the conditional on the execution page: //Display error messages. } else {// if errors array is not empty //Conver the errors array into a string $errors_string = implode(" ", $errors); //Encode the imploded string. $message = urlencode($errors_string); header("Location: register_page.php?message=$message"); } And here is the code for the target page: </div> <!--closes register box--> <div id="error"> <?php if(isset($_GET['message'])) { //Decode the url $errors_string = urldecode($_GET['message']); //Explode the decoded errors string back to an array. $errors = explode(" ", $errors_string); echo '<h3>Error!</h3> The following error(s) occured:<br />'; foreach ($errors as $msg) { echo "$msg<br/>\n"; } } ?> </div> <!--closes error--> Now everything works just fine, except that the error messages are printed one word per line for example Your email is not a valid email address. I can't seem to find the fluke in the code. Any ideas? Also is there any potential security risk for passing error messages in a url? No sensitive information is being transmitted. Just error messages.
  19. I have the following session timeout code which should redirect users of a website to a page (session_expired.php) which prints out a message telling the user that his session has expired. I include this code at the top of every page in the website, that requires user authentication. <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) { // last request was more than 30 minates ago session_destroy(); // destroy session data in storage session_unset(); // unset $_SESSION variable for the runtime header("location: session_expired.php"); } $_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp ?> The session_expired.php page which I will include below, has a login link, which takes the user to a login page (access_denied.php) <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //Set the page title before the header file $title = 'Session Expired'; require ('header.php'); //need the header ?> <div id="content" class=""> <div id="left_content" class=""> </div> <!--closes left content--> <div id="right_content" class=""> <div id= "right_content_inner_border"> <h5 style ="position:relative;left:660px;top:1px;"> <a style="text-decoration:none" href="access_denied.php">[Login]</a> </h5> <h3 style ="position:relative;left:110px;top:100px; font-color:blue;"> You Session Expired Due to Inactivity! </h3> </div> <!--closes right content inner border--> </div> <!--closes right content--> </div> <!--closes content--> <?php require ('footer.php'); //need the footer ?> Now here lies the problem. When i set the session timeout to say 60 seconds to test the code, everything seems to work perfectly. The authenticated page gets redirected to session_expired.php after 1 minute and when the user clicks on the login link, he is taken back to the login page(access_denied.php). However, when I replace the time with 1800 seconds, the page notice that when I leave the page idle for JUST about 5 minutes, it gets redirected NOT even to the expected session_expired.php page but strangely, directly to the login page(access_denied.php). What could be going wrong here? Any hint is appreciated.
  20. Well the topic may not sound very explicit. So I'll do my best to explain it here. I have a pull down menu as part of a form, which contains the months of the year. I'm trying to store the value of this form entry using the $_POST['month'] variable into a database but first, I need to convert the month values into their corresponding integer values( that is 1 for January, 2 for February etc), in order to easily do date calculations later down the road. Any ideas about how to do this? It may be helpful to include the code for the pull down menu. <p><tab> Date of Birth: <?php //Make the month pull down menu. //Array to store months. $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); print '<select name= "month">'; foreach ($months as $key => $value) { print "\n<option value=\"$key\">$value</option>"; } print '</select>'; ?> </tab> <tab> <?php //Make the day pull down menu print '<select name= "day">'; for ($day = 1; $day <= 31; $day++) { print "\n<option value=\"$day\">$day</option>"; } print '</select>'; ?> </tab> <tab><?php //Make the year pull down menu print '<select name= "year">'; $start_year = date('Y'); for ($y = ($start_year - 18); $y >= 1900; $y--) { print "\n<option value=\"$y\">$y</option>"; } print '</select>'; ?> </tab> </p>
  21. Here is one of those purely conceptual questions, which involves no code. I'm trying to create a select query which among other things, allows a user of a website to search other members who fall within a particular age range. I have a column in the table where the members' information are stored which records their ages. Which brings us to the problem. On any given day, a member's age may increase by one year compared to what it was the previous day, hence the need to update this column periodically. I can't think of any way to automatically update this column on a daily basis. So my solution is to run an initial update query every time a member tries to search other members based on age, which updates the age column for all other members, before running the select query which eventually retrieves the desired age range. This leads to the second problem. Imagine there are thousands of users using the website. At any given instance, there could be hundreds of members, trying to search others based on age. This means hundreds of users will be updating a single column (the age column) in one table at the same time. Is this feasible? Can it cause the server to crash? Or is there really a more reasonable way to do all of this? Thank you all for taking your time to read this. Appreciate any responses.
  22. The form below is meant to retrieve the named attribute of a form input called "limitedtextfield" , along side the current date and store those values in a database. The form contains some javascript which can be disregarded for this particular problem. [code] <form name="mymind" style= "position:relative;left:40px;" action="insert_status.php" method="post"> <input name="limitedtextfield" type="text" onKeyDown="limitText(this.form.limitedtextfield,this.form.countdown,55);" onKeyUp="limitText(this.form.limitedtextfield,this.form.countdown,55);" maxlength="55"><br> <font size="1">(Maximum characters: 55)<br> You have <input readonly type="text" name="countdown" size="3" value="55"> characters left.</font> <input type="hidden" name="submitted" value="TRUE"/> <input style="position:relative;left:0px;bottom:0px;" type="submit" name="submit" value="Submit!" /> </form> Here is the php script that processes the form. What it is meant to do is search the database and if no record is found for the authenticated member, input the relevant values into the database. If a record is found, it should update the record. Well every time I hit the submit button, all I get is a blank page. Any clue as to what is going wrong? PS: I checked the database and no values got inserted. <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user require('auth.php'); //Connect to database require ('config.php'); if (isset($_POST['submitted'])) { $query = "SELECT* FROM publications WHERE member_id ='".$_SESSION['id']."' AND cartegory='status'"; $result = @mysql_query($query); $num = @mysql_num_rows($result); if ($num> 0) { $update = mysql_query("UPDATE publications SET publication = '{$_POST['limitedtextfield']}' WHERE member_id = '".$_SESSION['id']."' AND cartegory = 'status'"); header("Location: member.php"); } else { $query = "INSERT INTO publications ( member_id, publication, cartegory, pub_date) VALUES ( '{$_SESSION['id']}','{$_POST['limitedtextfield']}', 'status', NOW() )"; header("Location: member.php"); } } ?>
  23. @ zanus. well i tried your suggestion. I imploded the errors array on page 2 and url encoded it before passing it into the url like so: } else {// if errors array is not empty //Conver the errors array into a string $errors_string = implode(" ", $errors); //Encode the imploded string. $message = urlencode($errors_string); header("Location: register_page.php?message=$message"); } } Then on page 1, I decoded the url and reconverted the string into my original errors arryay. <div id="error"> <?php if(isset($_GET['message'])) { //Decode the url $errors_string = urldecode($message); //Explode the decoded errors string back to an array. $errors = explode(" ", $errors_string); echo '<h3>Error!</h3> The following error(s) occured:<br />'; foreach ($errors as $msg) { echo "$msg<br/>\n"; } } ?> </div> <!--closes error--> Well no error messages got displayed this time, but the register errors didn't get printed either. What am I not doing right this time?
  24. Im trying to create a page that collects personal info from users and registers them. I have a page that contains the registration form which i will call page 1. A second page which I will call page 2, processes the form. A simplified version of page 2 looks like this <?php if (isset($_POST['submitted'])) { $errors = array(); // Connect to the database. require_once ('config.php'); //Check for errors. //Check to ensure that the password is long enough and is of the right format. if (eregi ("^[[:alnum:]]{8,16}$" , $_POST['password'])) { $b = TRUE; } else { $b = FALSE; $errors[] = 'Please enter a password that consists only of letters and numbers between 8 and 16 characters long.'; } //Check to make sure the password matches the confirmed password. if ($_POST['password'] == $_POST['password2']) { $c = TRUE; $password = $_POST['password']; //Encrypt the password. } else { $c = FALSE; $errors[] = 'The password you entered did not match the confirmed password.'; } //Check to make sure they entered their first name and it's of the right format. if (eregi ("^([[:alpha:]]|-|')+$", $_POST['firstname'])) { $d = TRUE; } else { $d = FALSE; $errors[] = 'Please enter a valid first name.'; } //Check to make sure they entered their last name and it's of the right format. if (eregi ("^([[:alpha:]]|-|')+$", $_POST['lastname'])) { $e = TRUE; } else { $e = FALSE; $errors[] = 'Please enter a valid last name.'; } //Insert data into database. if (empty($errors)) { //query the database. for the sake of simplicity, I wont include the code // Show thank you message echo "<h3>Thank You!</h3> You have been registered"; } else { echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>'; } //Display error messages. } else {// if errors array is not empty header("Location: page1.php?message=$errors");//Trying to pass the errors array into the url for page1 } } ?> So the idea is to create an array that contains all the errors. Upon querying the database, if the user completed the fields as required, a thank you message is printed. If not, he is redirected to the page containing the form (page 1) and the array containing the errors is transferred to page 1. Now I will include the relevant section of page 1 whihc is supposed to print the error messages. <?php if(isset($_GET['message']) { echo '<h3>Error!</h3> The following error(s) occured:<br />'; foreach ($errors as $msg) { echo "$msg<br/>\n"; } } ?> I get the following error message when I submit the registration forms with deliberate errors: Error! The following error(s) occured: PHP Error Message Warning: Invalid argument supplied for foreach() in /home/a4993450/public_html/register_page_content.php on line 66 Free Web Hosting Can anyone point out why this error occurs?
  25. I created this code to upload a member's main picture on his member page on website. I'll only include the query part of the code since that's what is relevant to my problem. The idea is basically to upload a new picture onto the database if no picture already exists for that member and display the picture on the page. If a picture already exists, then the script replaces the old picture with the new one upon upload. But for whatever reason I don't understand, when I try to replace the old pic, it gets inserted in a new row on the database instead of replacing the old row, and the new pic gets displayed on the web page alongside the old. $query = "SELECT username FROM images WHERE member_id = '".$_SESSION['id']."' AND image_cartegory = 'main'"; $result = @mysql_query($query); $num = @mysql_num_rows($result); if ($num> 0) { //Update the image $update = mysql_query("UPDATE images SET image = '" . $image['name'] . "' WHERE member_id = '".$_SESSION['id']."' AND image_cartegory = 'main'"); $_SESSION['error'] = "File updated successfully."; //really should be session success message. header("Location: member.php"); exit; } else { // NOTE: This is where a lot of people make mistakes. // We are *not* putting the image into the database; we are putting a reference to the file's location on the server $sql = "insert into images (member_id, image_cartegory, image_date, image) values ('{$_SESSION['id']}', 'main', NOW(), '" . $image['name'] . "')"; $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error()); $_SESSION['error'] = "File uploaded succussfully."; //really should be session success message. header("Location: member.php"); } So can anyone tell me what the problem is? Could the fact that my insert script actually uploads the image onto a folder on my server and only stores the path name in the database have anything to contribute to the mixup? Appreciate your responses in advance.
×
×
  • 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.