Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. Rather depends on your database setup. If you have a timestamp field, you could do something like: <?php $today = time(); $next_week = $today+60*60*24*7; $sql = mysql_query("SELECT * FROM `yourtable` WHERE `datefield` BETWEEN $today and $next_week") or die(mysql_error()); ?> If you have a date/datetime field, you could apply the UNIX_TIMESTAMP() mysql function to the field before the comparison.
  2. Not trying to steal unsuspecting user's passwords by getting them to login to a spoof/help site are we?
  3. Well i for one have absolutely no idea what you are trying to achieve. Perhaps you could tell us exactly what you want to do?
  4. You want the date() and strtotime() functions: <?php //today echo date('d/m/Y').'<br />'; //last thursday echo date('d/m/Y',strtotime('last thursday')); ?>
  5. Well, you dont close your image tag. Try: <a href="user_images/<? echo $image_name; ?>"><img src=" <? echo $image_path; ?> " /></a>
  6. Well, presumably you have an ending time for each item in the database? You'd then simply order by this value: <?php $sql = mysql_query("SELECT * FROM `yourtable` WHERE `somefield`='somevalue' ORDER BY `ending` DESC") or die(mysql_error()); ?>
  7. There's a whole topic on the subject here: http://www.phpfreaks.com/forums/index.php/topic,54859.0.html
  8. What are you actually trying to achieve? Are you just trying to check each element of array 1 to see if it exists in array 2?
  9. Well, if you did want to just check against a list of possible values, you could use the in_array() function. However, it would probably be easier to treat the input as a number, and just check it is within whatever parameters you want.
  10. Php only parses strings for variables that are contained within double quotes. If you place them inside single quotes, they are treated as litterals - that is you, litterally want to echo $var, rather than it's value.
  11. Ah ok, didn't realise we were just looking for the <a href> tag. A pattern like: "<.*href=.*>" Should do.
  12. Well, you read wrong You MUST call session_start(); before any use of the $_SESSION superglobal. And it MUST be called before any output to the browser. Otherwise, you'll get an error (or a blank page as seems to be the case - im getting display_errors is turned off in your php setup).
  13. The general idea of me typing that out is that you try it!
  14. Well, in your given example, id is the id of the post, whilst rid is the parent id. Assuming you set a default on the rid field of 0, you could do something like: <?php $sql = "SELECT * FROM `forum` WHERE `fid`='$forumnumber'"; $result = mysql_query($sql) or die(mysql_error()); $array = array(); while($row = mysql_fetch_assoc($result)){ $parent_id = $row['rid']; $post_id = $row['id']; $user= $row['user']; $array[$parent_id][$post_id] = $user; } ?> That would generate the array i typed out.
  15. Try: <?php /********************************************************************************** // Refill Verification Script * // Coded by DevXTech * // This script consists of two major parts. The first part of it is the functions * // that are called upon to verify the integrity of the information contained in * // the form itself. This form will throw an error if <a href=></a> tags are in the* // comments box and check that a certain field has been filled in and meets the * // requirements. * // * // The second part of the script is to call the functions and verify the content. * // Once we have verified the content if any errors our found we will display them * // to the end user so they can fix the error and resubmit the form again. * **********************************************************************************/ // Grab the values from the form and create variables. $fname = $_POST['fname']; $lname = $_POST['lname']; $phone = $_POST['phone']; $comments = $_POST['comments']; $error = '0'; // Check if the first name was supplied if not throw an error. function val_fname ($fname){ if (strlen($fname) < 2) return TRUE; else return FALSE; } // Check if the last name was supplied if not throw an error. function val_lname ($lname){ if (strlen($lname) < 2) return TRUE; else return FALSE; } // Check for the phone number for 7 to 10 digits with no letters. function val_phone ($phone){ if (!ereg("^[0-9,\-]{7,14}$", $phone)) return TRUE; else return FALSE; } // Check the comment field for an href tag and if found throw an error. function clean_comment ($comments){ strip_tags($comments); } // If all the functions pass then out put a message stating the refill has been submitted to the queue. // If the functions do not pass then output the form again and show the errors they made at the top of the form // as well as reinput the values they originally entered into the form. Then recheck the form again. // Run if statements here to see if variables pass functions if (val_fname($fname)){ echo "Invalid input of $fname for first name. Your first name must contain at least 2 characters.<br>"; $error++; //Add one to error } if (val_lname($lname)){ echo "Invalid input of $lname for last name. Your last name must contain at least 2 characters.<br>"; $error++; //Add one to error } if (val_phone($phone)){ echo "Invalid input of $phone for your phone number. Your phone number must be at least 7 digits.<br>"; $error++; //Add one to error } clean_comment($comments); // Run another if to check the count on the errors and then determine we can proceed. if($error == 0) { echo 'We made it past validation!'; /*require_once( "DSI_email.php" ); $_POST['date'] = date("F j, Y, g:i a"); $cons = new DSI_Email_Cust( "www.bob.com" ); $cons->SetupContactsFor( "Refill" ); $cons->GenerateEmailFromTemplate( "refill.tmp", $_POST ); $cons->SendEmail( "Refill Request", "refills@pharmacy.com" ); $cons->RedirectToThankYou( $_SERVER['HTTP_REFERER'] ); */ }else{ echo "Number of errors: $error <br>"; echo "Please use the back button to go back and fix the errors."; unset ($fname,$lname,$phone,$comments,$error); } ?> Changes made: Removed negation of if statment inside length checks on first and last names. Flawed logic. Removed delimiters for ereg patterns - those are a feature of preg_match patters. Changed pattern for phone number to: (!ereg("^[0-9,\-]{7,14}$", $phone)) You must escape the second - in your character set, since it has a special meaning. Added start and end characters (^ and $ respectively) to prevent input such as 012312242abcd. Changed the val_comments function to one just to clean them up. Its much easier to remove any html tags than to find them and throw an error. (However, if you're entering this into a database, you'll want further protection from malicious input e.g. mysql_real_escape_string)
  16. You'll probably want mysql full text searching. Here's a tutorial to get you on your way: http://www.phpfreaks.com/tutorials/129/0.php
  17. Well, where do you apply the md5() function in your login script?
  18. You can make life a lot easier in the way you set up your array. The way i approach this is with a two dimensional array. For each post, the first dimension is the id of the parent post, and second is the id of the current post. You therefore set a top level id (which in the following example was 0): <?php $array = array(); $array[0][6] = 'Jim'; $array[6][8] = 'Bob'; $array[0][7] = 'Tom'; $array[0][1] = 'Dick'; $array[1][3] = 'Harry'; $array[3][4] = 'Fred'; $array[4][5] = 'George'; $array[1][2] = 'Run out out names'; function recursive($array,$index=0){ foreach($array[$index] as $k => $v){ echo "<li>Reply $k - $v</li>"; if(is_array($array[$k])){ echo '<ul>'; recursive($array,$k); echo '</ul>'; } } } echo '<ul>'; recursive($array); echo '</ul>'; ?> Of course, this isn't going to work as-is, but it might give you an idea of how these things work. Here's another example(which is largely identical to the one above, but for a breadcrumb menu): http://www.phpfreaks.com/forums/index.php/topic,156551.msg680172.html#msg680172 Again, might just help you on your way. And one further example that i wrote, which was for generating a listing of the number of files within a directory and all sub directories: http://www.phpfreaks.com/forums/index.php/topic,157389.msg684881.html#msg684881
  19. Well that just doesn't make sense. Are you 100% sure you're entering the same password? Perhaps there's an extra character in one of them somewhere? The string 'password' generates your first hash - 5f4dcc3b5aa765d61d8327deb882cf99 - so the register appears to be working ok; perhaps there is an issue with your login script.
  20. There are quite a few errors in this script. Firstly: <?php $_POST['fname'] = $fname; $_POST['lname'] = $lname; $_POST['phone'] = $phone; $_POST['comments'] = $comments; ?> These have been assigned the wrong way around. You should do: <?php $fname = $_POST['fname']; ?> Second, this kind of thing: <?php if (!strlen($fname < 2)) ?> Should be: <?php if (!strlen($fname) < 2) ?> The strlen function takes the parameter of the string which you want to find the length of. You then need to test the result of the function to see if the length is what you want. Next, your regular expressions are usnig the ereg() function syntax, rather than preg_match(). You'll need to change those. And lastly, your functions making use of regular expressions have a logic error. You are returning true for those values which are valid, whilst you increase the error count and show an error if they return true.
  21. The reason why you simply get more records showing on each page is because you're not using the LIMIT clause in your mysql statement correctly. You have the parameters the wrong way round. Try changing this line: $max = 'limit '.$page_rows.','.($pagenum-1) * $page_rows; To: $max = 'limit '.($pagenum-1) * $page_rows.','.$page_rows;
  22. I dont believe this is anything to do with your php. You need to set the height to 100%: height="100%"
  23. Well, i could be wrong, but im not sure this is possible. As far as im aware, clicking the back button would retrieve the last page from the browser's cache, therefore there would be no opportunity for you to redirect them at any point.
  24. You'll be wanting to look into using cURL with php for this kind of thing.
  25. You'll be wanting to do a loop. From what you've said, im assuming savedbusinessid is an auto increment field in your table, whilst businessid is the id which identifies each individual business. In which case, you'll probably have an array containing each of the businessids. The query would look something like: <?php foreach($businessid as $v){ mysql_query("INSERT INTO `yourtable` (savidbusinessid,businessid,userid) VALUES('','$v',$userid)") or die(mysql_error()); } ?> Edit: Perhaps the issue is also about creating the array of ids to save. When you output the checkboxes, you should do something like: <?php //am assuming you have some sort of loop to echo all the businesses while($row=mysql_fetch_array($result)){ //other code in the loop echo '<input type="checkbox" name="businessid['.$row['businessid'].']" />' ; } ?> Assuming your form method was POST, you'd then have an array in the $_POST arrray containing all of the business id's selected. I've had to make lots of assumptions here, so dont expect anything to work as is.
×
×
  • 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.