Jump to content

thefortrees

Members
  • Posts

    88
  • Joined

  • Last visited

    Never

Everything posted by thefortrees

  1. Howdy. Is it necessary to use mysql_real_escape_string on form elements such as radio buttons or checkboxes?
  2. Hi all - Is there any way to check to see if an object is an instance of a specific class? For example, in Java there is an instanceof operator... if (myObject instanceof classThatCreatesObject) //do cool stuff here Thanks
  3. Hi all - The application I am developing requires user authentication. Currently, for a user to login, I run an authentication function that verifies username and password against values in the database. The password is then is converted into a password digest from the md5 hash algorithm. I set several session variables upon authentication - user type (ie - admin), and login username. Is it good practice to query the database and check for the proper user type and username values at every page that needs to be protected by the authentication framework? Should I introduce any other / other types of session variables to provide better security? I have read a bit about recording the login IP address and storing that in a session variable, but that does not seem like a good idea to me, as there are several issues with IP addresses (ie - AOL users having changing IP addresses for each request??). Is this true? Any other suggestions? Thanks!
  4. It is a one way hash - you can't recover it. http://us.php.net/manual/en/function.crypt.php
  5. Is it possible to compare several cases at once. Instead of having this: //Body Style $bodyStyle=$vehicle->vehicletype; switch ($bodyStyle){ case '': $bodyStyle = 'UNAVAIL'; break; case '2 Door Cab': $bodyStyle = 'TRUCK'; break; case '2 Dr Reg Cab': $bodyStyle = 'TRUCK'; break; case '4 Door Cab': $bodyStyle = 'TRUCK'; break; case '2 Door Convertible': $bodyStyle = 'CONVERTIBLE'; break; case '2 Door Coupe': $bodyStyle = 'COUPE'; break; case '2 Door Hatchback': $bodyStyle = 'HATCHBACK'; break; case '2 Door Wagon': $bodyStyle = 'WAGON'; break; case '3 Door Van': $bodyStyle = 'VAN'; break; case '4 Door Coupe': $bodyStyle = 'COUPE'; break; case '4 Door Hatchback': $bodyStyle = 'HATCHBACK'; break; case '4 Door Sedan': $bodyStyle = 'SEDAN'; break; case '4 Door Van': $bodyStyle = 'VAN'; break; case '4 Door Wagon': $bodyStyle = 'WAGON'; break; } Is there some way to simplify the statements so that the 3 cases where $bodyStyle = 'TRUCK' can be combined into 1 case? (without using an array)
  6. Hi all - I would like to retrieve the current document name and store it in a variable. Example: I am at page http://www.home.com/currentinfo.php. I would like to take the string 'currentinfo.php' and assign it to a variable. Is there any PHP function or global variable that can do that? Thanks, T
  7. If I understand what you want to do correctly, then just nest the for loop within the while loop and increment a counter variable. //Need to keep track of how many times you have looped in the while. $count = 0; for ($c=0; $c<mysql_num_fields($result); $c++) { print "<th>".mysql_field_name($result, $c)."</th>"; } // print table rows while( $record = mysql_fetch_array( $result )){ $count++; if ( $count == 20){ for ($c=0; $c<mysql_num_fields($result); $c++) print "<th>".mysql_field_name($result, $c)."</th>"; //Reset $count to 0 so headers will be printed after another 20 iterations $count = 0; } //$colors = array("#DCE1E7", "#E9EBEF"); $i = 0; if($i%2) { $color="#DCE1E7"; } else { $color="#E9EBEF"; } $colors = array($color, $i); print "<tr bgcolor=$color>"; for( $c=0; $c<mysql_num_fields( $result ); $c++ ) { print "<td align='center'>".$record[$c]."</td>"; } print "</tr>"; }}
  8. Hi all - I am trying to populate a drop down list from values in an array, and compare a $_REQUEST or $_SESSION value to each of the array values. If they are equal, then the option in the drop down menu will be selected. Can't get it to work... Here is my code. Any help is appreciated! Thanks. //Select menu for each type of user. echo "<td>Sort by:<select name='displayUsers' align='center'>"; //$option holds the option values. $text holds the text of each option. $option = array('all', 'admin', 'business', 'personal',); $text = array('All', 'Administrators', 'Business Administrators', 'Personal Users',); //$count will be used to print each element of $text. $count = 0; //Loop to create each option element. foreach ($option as $value){ //If displayUsers == value selected fromdrop down, select that option. Else, do not select. if ($_REQUEST['displayUsers'] == $value || $_SESSION['displayUsers'] == $value){ echo "<option selected value='" . $value . "'>" . $text[$count] . "</option>"; $count++; } else{ echo "<option value='" . $value . "'>" . $text[$count] . "</option>"; $count++; } }
  9. Hi all - Is there an alternative to crypt(), md5(), or sha1() that is two-way? Would it be a good idea to implement two-way encryption for passwords? I am creating a site in which it would be nice if the admin could login and be able to retrieve the passwords for each user. Thanks!
  10. Hi all - I am trying to figure out how to click an option in a select menu and have that option act as a hyperlink/form submit without a submit button. Here is an example of what I am trying to do: echo "<select align='center'>" . "<option value='all' onChange='home.php?displayUsers='all'>All</option>" . "<option value='admin' onChange='home.php?displayUsers='admin'>Admin</option>" . "<option value='business' onChange='home.php?displayUsers='business'>Business</option>" . "<option value='personal' onChange='home.php?displayUsers='personal'>Personal</option>" . "</table>"; Any suggestions?
  11. Create a table that stores the 'checked' values and that is linked to each user with some sort of id. Then, in your HTML code after your query, you could do something like this while ($row = mysql_fetch_assoc($result)) {//mysql_fetch_assoc is identical to mysql_fetch_array(resultresource, MYSQL_ASSOC but with less typing $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['name'] . '</td> <td align="left">Present <input type ="radio" name="attend['.$row['user_id'].']" value="Present" checked="' . if ( $row['checked'] == "Present") echo 'checked'; .'">> Excused <input type ="radio" name="attend['.$row['user_id'].']" value="Excused" checked=' . if ( $row['checked'] == "Excused") echo 'checked';/> Unexcused <input type ="radio" name="attend['.$row['user_id'].']" value="Unexcused" checked=' . if ( $row['checked'] == "Unexcused") echo 'checked';/></td> </tr> '; }
  12. Scratch that - I spent all that time doing that loop. All the select option needs is selected='selected', so the code will probably look like this to pre-select a value: echo "<td><select name='lob'>"; foreach ($array as $value){ if ($value == $row['value']){ echo "option value='" . $value . "' checked='checked' } else{ echo "<option value='" . $value . "' selected='selected'>" . $value; } }
  13. I am trying to figure out this as well... Yesterday, to solve that problem, I created a loop that would be the last selected option (or value from DB) first in the list. The only problem with my loop is that it leaves one value out.. I'm not sure why, still working on that one. Here is my code - $temp = array(); $val = array_search($row['value'], $array); $temp[] = $array[$val]; $count = 0; echo "<td><select name='lob'>"; foreach ($array as $value){ if ($value == $row['value']){ continue; } else{ $temp[] = $value; echo "<option value='" . $temp[$count] . "'>" . $temp[$count]; } $count++; } What this code does is take the values from an $array that holds previous values (ie - the values in the drop down list or values stored in the db). It then finds the desired value to be first in the drop down list with array_search, then puts it first in temp[]. Once in the loop, if the current value in $array == the value I ALREADY stored in $temp[], then it skips over it and starts at the top of the loop. Like I said, it leaves one element out, so it doesn't work perfectly yet, but it does put the desired value first.
  14. Hi all - I am writing a dynamic customer service application that generates questions based on the kind of business, customer, etc and I have a functions.php that contains at least 15 functions, but they are all mysql queries. I return the result of the query in each of tehse functions. Is it good practice to to return results of queries in functions?
  15. Sure thing! It's just a while loop with mysql_fetch_array. //Display each question. while($row = mysql_fetch_array($result)){ echo "<form>" . "<tr><td><input type='text' name='question' value='" . $row['question'] . "'></td>" . "<input type='hidden' name='questions_id' value='" . $row['questions_id'] . "'>" . //Create drop down menu for LoB for each question. "<td><select name='lob'>"; $temp = array(); $val = array_search($row['lob'], $businessArray); $temp[] = $businessArray[$val]; $count = 0; //for ($i = 0; $i < sizeof($businessArray); $i++){ foreach ($businessArray as $value){ //$value = $businessArray[$i]; if ($value == $row['lob']){ continue; } else{ $temp[] = $value; echo "<option value='" . $temp[$count] . "'>" . $temp[$count]; $count++; } } echo "</select></td>" . "<td><h6><input type='submit' name='updateQuestion' value='Update'></h6></td>" . "<td><h6><input type='submit' name='deleteQuestion' value='Delete'></a></h6></td></tr>" . "</form>"; } }
  16. Read up on it - its pretty straightforward - http://us.php.net/urlencode
  17. Make sure that the header function is before any HTML code or echo statements or any information sent to the browser, for that matter.
  18. I am creating a survey that pulls questions and responses from a DB. When I query the DB for each question and response from the mysql command line, all the desired data are returned. As soon as the query is implemented into the PHP code below, the first response that should have been retrieved from the DB is not. (There are multiple responses to each question - it does not retrieve the first response for the first question, but all responses after that are retrieved. $query = "SELECT question, response, position FROM questions, responses, survey_instances " . "WHERE questions.questions_id = responses.questions_questions_id " . "AND questions.questions_id = survey_instances.questions_questions_id ORDER BY position"; $result = mysql_query($query); $row = mysql_fetch_array($result); $responses = array(); //Print out questions. If position/question has already been echoed, do not echo again //so that one question is not echoed multiple times. while ($row = mysql_fetch_array($result)){ if ( !in_array($row['question'], $responses) ){ echo "<table>" . "<tr>" . $row['position'] . ") " . $row['question'] . "</tr>" . "<tr><td>" . $row['response'] . "</tr></td>"; $responses[] = $row['question']; } echo "<tr><td>" . $row['response'] . "</td>" . "</table><br>"; }
  19. post the code and we will try and help.
  20. I appreciate your response Corona. The element $row['lob'] is not the last element in the array. In the select menu, $row['lob] is displayed first (this loop is nested in another loop) multiple times. If I remove the conditional continue, then $row['lob'] is repeated twice in the loop....
  21. Hi all - In this loop, the last element isn't being echoed with the html option the last time through. I put an echo statement before the if-else to debug, and it echoed every value. So, for some reason, the loop is breaking before it gets to the echo HTML the last time through. Any ideas? $temp = array(); $val = array_search($row['lob'], $businessArray); $temp[] = $businessArray[$val]; $count = 0; //for ($i = 0; $i < sizeof($businessArray); $i++){ foreach ($businessArray as $value){ //$value = $businessArray[$i]; if ($value == $row['lob']){ continue; } else{ $temp[] = $value; echo "<option value='" . $temp[$count] . "'>" . $temp[$count]; $count++; } }
  22. If you use header() you need to be sure that the header function is called BEFORE any HTML is sent to the browser, otherwise it won't work.
  23. The empty() function checks to see if a variable is empty.
×
×
  • 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.