Jump to content

hadoob024

Members
  • Posts

    192
  • Joined

  • Last visited

Everything posted by hadoob024

  1. Good call! I think the BlackBerry just doesn't send $_POST stuff properly.  Like if a field isn't filled out, I think it might just not be adding it to the $_POST array (instead of just assigning a NULL value).  I added (isset($_FILES['picture'])) to my "if" statement, and this solved the problem! Sweet! It works on the BlackBerry now. Thanks everyone!!!
  2. I can't seem to figure this one out. On my site, I have a real estate listing form. One of the fields is for the user to be able to upload a picture. Now, when I access this page on my PC at home, I have no problems. The error handling and security checks work fine. Regardless of whether I input info for this picture field, the form processor works. However, whenever I try and submit this form using a BlackBerry, I keep getting the following error message: "Error Message: Undefined index: picture" And apparently this line of code is the culprit: PHP Code: [code]if (($_FILES['picture']['size'] != 0) && ($_FILES['picture']['tmp_name'] != ''))[/code] I just can't figure out why this works perfectly on my PC, but causes an error on my BlackBerry. Any thoughts?
  3. Good call. I was leaning in that direction too. Their service is kind of expensive too. It starts at like $600 per server per year. That is kind of steep, and I guess it's really not worth it since I know how to maintain the db. Besides, I'll be making backups constantly, so worse case scenario, all I have to do copy over a backup. Thanks for the advice!
  4. Does anyone have any experience with this? I'm trying to see if the service provided with the "MySQL Network with MySQL Pro Certified Server" version is worth the costs involved. I'm making a real estate website that's basically going to be a listing service. You can do searches on the listings for free, and it costs to add your listing. Our listings are only going to be active for 30 days, and we really don't expect to have more than maybe a thousand or so listings at a time tops. I'm just wondering if this is something that should be manageable for me, even though I really don't have any prior DBA experience. I've played around with phpMyAdmin for a bit, so I know how to backup/replace/repair/etc., and am just wondering if this is enough. Any thoughts?
  5. OK. I think I understand what you're saying. The only thing I'm not sure of is how to handle the links for previous/next pages. Can I get it to load a separate page instead? Right now, if I try to reload my "searchresults.php" page, I think my security/error handler won't allow for it. I guess I want to know if I can somehow use a separate page to handle the pagination instead of my main "searchresults.php" page?
  6. I've read several tutorials and a ton of posts, and the code for implementing pagination seems to be pretty similar (the methodology at least). Anyway, I see how the code works, but I'm not sure how to apply it to my site in particular. I have a page "search.php", that has all the form information and creates sessions and passes this information as hidden tokens (to prevent against abuse of my forms). It passes the info to "searchresults.php". "searchresults.php" has the following structure: 1) check SESSION variables (to prevent against CSR, session hijacking, and session fixation) 2) initialize my variables which will store the info passed from the form 3) check/screen info passed through POST and set my variables equal to these values 4) validate information 5) connect to db 6) create and format results of SQL search string based on form information and by using SQL ORDER command 7) query db 8) if results found, display them, if not, then display generic message 9) free resultset 10) clean up SESSION, close tables, end script So this layout works fine right now, but I want to add pagination and I guess my question is where/how to implement the pagination code given the layout of my "searchresults.php" page? Will all the SESSION stuff that I have mess this up? Will my form variables keep getting reset in between pages? Will the query be able to be passed ok?
  7. yeah. isn't that weird. i still have no idea why it's happening. i just changed the logic so that i don't need to perform an UPDATE anymore. and yeah, i have no idea why it was failing because i didn't have the SELECT priviledge. i wasn't even doing anything across multiple tables. it was all within the same main table.
  8. So I guess you're saying that primarily it helps with response time, right? Hmmm... interesting. I guess that's reason enough to implement it. What if I want to have a "print search results" link at the end of my search results. I would I get that link to print the entire contents and not just the "paginated" section? Would I have to re-run the query?
  9. really??? that's weird, cuz when i changed that line to check for errors on the UPDATE command, i got an email with the error that said "user blahblah does not have the SELECT permission to perform this operation" or something like that. you see my UPDATE statement. what do you think caused that error message?
  10. I've read all the posts regarding getting help with setting up and implementing pagination. The one thing that I haven't found is why people use it at all? Does it help with bandwidth usage? Is it just to help organize search results? I'm just curious as to the reasons pro/con for implementing it. Thanks!
  11. Cool. I tested it out and turns out that the user didn't have the SELECT priviledge and that's why it kept failing. But when I was logged into phpMyAdmin, I was logged in as Admin, so I did have the priviledge. Interesting. I didn't know you needed the SELECT priviledge when you want to UPDATE. Thanks for solving my problem!!!
  12. hmmmm... i can't find an emoticon to represent feeling like an embarrassed a$$... :) anyways, thanks. i changed it up now, and am getting an error which pretty much just solved my problem. actually, i'm sure it will. just gotta test it out. thanks!!!!
  13. This is weird. I just noticed that if I take the resulting string from this: [code] $update_query = "UPDATE ofrelistings SET ofrelistings.picture='$newpath' WHERE ofrelistings.uniqueid='$basename'"; echo $update_query; [/code] Like the last one I ran generated: UPDATE ofrelistings SET ofrelistings.picture='listingpics/9.jpg' WHERE ofrelistings.uniqueid='9' When this is executed in my script, nothing gets updated. However, if I go into phpMyAdmin, and run this query through the SQL command line, the record gets updated correctly. Any thoughts?
  14. On my site, a user enters in listing information (for a real estate property). My script takes in the information, INSERTs it into my db (which it's doing properly), then I get the value of the uniqueid (UNSIGNED INT(11), primary key, set to auto_increment) using mysql_insert_id(), then move the uploaded file and rename it using the value returned from mysql_insert_id() as the base of the filename, and the variable $ext as the extension. Once I move the file, I then try and UPDATE the previous entry with the new value for the picture's path. However, the UPDATE seems to run no problem, but nothing seems to get UPDATEd. I think it might have to do with how I'm checking it, but cannot tell. Here's my code: [code] //this variable is initialized as an emptry string because we do not yet have the // //correct filename yet $picpath = ''; $insert_query = "INSERT INTO ofrelistings(firstname, lastname, emailaddress, phonenumber, companyname, askingprice, listingtype, location, city, listingdescription, picture, dateadded) VALUES('$firstname', '$lastname', '$phonenumber', '$emailaddress', '$companyname', '$askingprice', '$listingtype', '$location', '$city', '$listingdescription', '$picpath', 'Date()')"; $insert_query_result = mysql_query($insert_query); if (!$insert_query_result) {     $problemtext = 'Error INSERT-ing information into main table in addlistingprocess.php.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } //else the query passed and the record was INSERT-ed successfully else {     //to help with the creation of a unique file name for the uploaded pic.     $basename = strval(mysql_insert_id());          //if we're here, then the SQL string was INSERT-ed properly.  send a                     //message that says that the main info was added.  we'll send a final         //message after we UPDATE the db with the picture file information.     $subject = 'OFRE.com New Listing Alert (part 2): '.date("F j, Y, g:i a");     $body = "The new listing was successfully added to the db. \r\n\r\nListing Number: $basename \r\nWas Picture Uploaded (1 for YES, 0 for NO): $uploadsuccess \r\n";     mail($adminrecipient, $subject, $body);     //this means that a file was uploaded successfully, so now we need to find     //the value of the primary key value for the record, so that we can create     //a unique filename for this record, using the value from mysql_insert_id()     //as the base and the value from $ext as the extension.     if ($uploadsuccess === 1)     {         //pathname for where we're moving file         $picture = 'listingpics/'.$_FILES['picture']['name'];         //moving file to location specified by $picture         if (!move_uploaded_file($_FILES['picture']['tmp_name'], $picture))         {             //just a quick alert that a listing was not moved successfully             $subject = 'OFRE.com New Listing Alert (part 3): '.date("F j, Y, g:i a");             $body = "The picture for the new listing was NOT moved successfully. \r\nListing Number: $basename \r\nPicture Path: $picture\r\n";             mail($adminrecipient, $subject, $body);         }         //else we successfully moved the picture to its new location         else         {             $newpath = 'listingpics/'.$basename.'.'.$ext;             rename ($picture, $newpath);             $basename = intval($basename);             $newpath = mysql_real_escape_string($newpath);             $update_query = "UPDATE ofrelistings SET picture='$newpath' WHERE ofrelistings.uniqueid='$basename'";             echo $update_query;             $update_result = mysql_query($update_query);             if (!$insert_query_result)             {                 $problemtext = 'Error UPDATE-ing picture information in main tables in addlistingprocess.php. \r\n'.mysql_error($connresult);                 trigger_error($problemtext, E_USER_ERROR);             }             //else the query was executed successfully             else             {                 //just a quick alert that a listing was updated successfully with the                 //path of the uploaded picture                 $subject = 'OFRE.com New Listing Alert (part 3): '.date("F j, Y, g:i a");                 $body = "The db was successfully updated with the picture path info. \r\nListing Number: $basename \r\nPath to Picture: $newpath \r\n";                 mail($adminrecipient, $subject, $body);             }         }     } } [/code] However, although the UPDATE seems to execute without error, nothing gets updated. I think it has to do with how I do my comparison. Like I check the following: [code] WHERE ofrelistings.uniqueid='$basename' [/code] But I know that uniqueid is stored as a UNSIGNED INT(11). Could this be why the record's not being updated properly?
  15. Cool. That's what I thought. It's like you know stuff "should" happen, but it doesn't mean that it will. I'll go ahead and add the code to unlock the tables. Thanks again for all your help!
  16. Oh yeah. You're right. So I guess I don't really need transactions at all. That's good to know. And it seems that once this script runs to completion, the tables get unlocked, right? Or should I explicitly add an UNLOCK TABLES after all my archiving code?
  17. Hmm. That's an interesting point. Yeah, you're right. Basically, the first 3 transactions backup the main table to a backup table, then delete from the main table, and then verify (using the SELECT statement) that this was done successfully (yeah, I know I should be able to trust that the first 2 go through ok, but I'm just trying to be overly cautious here). But yeah, what you're saying makes sense. Instead of having these transactions called everytime someone uses our "search listings" page, I'll just create a cron job to run once a day. Hmm... This being the case, I guess I don't need to use the InnoDB engine and can just stick with MyISAM, right? Because I really won't have to use transactions/rollbacks/commits and such, right? Or should I still use InnoDB, so that I can use transactions with my cron job? Thanks!
  18. Here's a follow-up. Do I also need to use LOCK TABLES and UNLOCK TABLES?
  19. How do you pass an error message to your custom error handler using trigger_error()? I read the docs and did some searches, and I thought it was pretty straightforward, but I can't seem to get it to work. I have the following code: [code] //opening connection to db $connresult = mysql_connect('localhost', $searchdbuser, $searchdbpass); if (!$connresult) {     $problemtext = 'Error opening a db connection in searchlistingsprocess.php.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } [/code] And right now, this line: [code] $connresult = mysql_connect('localhost', $searchdbuser, $searchdbpass); [/code] generates the following error message: "mysql_connect(): Access denied for user: 'searchuser@localhost' (Using password: YES)" And not the error message that I've defined in $problemtext. I can see that my custom error handler is being called, but the error message that I've defined in $problemtext never gets passed thru to the custom error handler. Here's the code for my custom error handler: [code] function my_error_handler($error_type, $error_string, $errFile, $errLine) {     $userip = $_SERVER['REMOTE_ADDR'];     $userhostname = $_SERVER['REMOTE_HOST'];     $subject = 'Unexpected OFRE.com Error: '.date("F j, Y, g:i a");     $body = "Error Message: $error_string\r\n"."Error Code: $error_type\r\n"."ErrFile: $errFile\r\n"."ErrLine: $errLine\r\n"."User IP Address: $userip\r\n"."User Host Name: $userhostname\r\n"."Variable Dump: $dumpresults\r\n"."========================================================\r\n";     mail("[email protected]", $subject, $body); } [/code] I receive an email with the error. But the message that I pass along thru $problemtext never comes thru. Do I even need to include this part: [code] if (!$connresult) {     $problemtext = 'Error opening a db connection in searchlistingsprocess.php.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } [/code] Or if an error is generated by: [code] $connresult = mysql_connect('localhost', $searchdbuser, $searchdbpass); [/code] Does my customer error handler get called automatically? And how can I get it to pass thru the message that I've defined? Thanks!
  20. Cool! Thanks a bunch. You answered all my questions.
  21. Cool. Thanks. I get now what you were saying. And my tables have to be something like InnoDB and not MyISAM if I want to use transactions, right? And in is: [code] //If no errors occurred, then commit transactions $commit_transaction = "COMMIT"; $commit_result = mysql_query($commit_transaction); if (!$commit_result) {     $problemtext = 'Error with Commit.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } [/code] Is this overkill to call a ROLLBACK if the COMMIT fails?
  22. Oh right. Good call. So change: [code] //If no errors occurred, then commit transactions $commit_transaction = "COMMIT"; $commit_result = mysql_query($commit_transaction); if (!$commit_result) {     $problemtext = 'Error with Commit.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } [/code] to this instead: [code] //If no errors occurred, then commit transactions $commit_transaction = "COMMIT"; $commit_result = mysql_query($commit_transaction); if (!$commit_result) {      $rollback_transaction = "ROLLBACK";      $rollback_result = mysql_query($rollback_transaction);      if (!$rollback_result)      {          $problemtext = 'Error with Rollback.\r\n'.mysql_error($connresult);          trigger_error($problemtext, E_USER_ERROR);      }     $problemtext = 'Error with Commit.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } [/code] And this is what I have in my customer error handler: [code] function my_error_handler($error_type, $error_string, $errFile, $errLine) {     $userip = $_SERVER['REMOTE_ADDR'];     $userhostname = $_SERVER['REMOTE_HOST'];     $subject = 'Unexpected OFRE.com Error: '.date("F j, Y, g:i a");     $body = "Error Message: $error_string\r\n"."Error Code: $error_type\r\n"."ErrFile: $errFile\r\n"."ErrLine: $errLine\r\n"."User IP Address: $userip\r\n"."User Host Name: $userhostname\r\n"."========================================================\r\n";     //Notify site administrator by email.     mail("[email protected]", $subject, $body);     //Write same subject line and body of the email to the error log     error_log("$subject \r\n $body \r\n");     echo '<div align="center"><B><font size="+2">System down for maintenance.</font><BR />Please try again later.  Thank you and sorry for the inconvenience.</B></div><BR /><BR />';     require('/home/virtual/ofre.com/var/www/includes/copyright.php');     require('/home/virtual/ofre.com/var/www/includes/closetables.php');     echo '</body></html>';     exit; } [/code] Is that what you were talking about? Does it look thorough enough? Thanks!
  23. cool. so maybe something like: [code] $connresult = @mysql_connect("myDatabase","myUser","myPassword"); if (!$connresult) {     $problemtext = 'Error opening a db connection.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } $db_selected = @mysql_select_db('ownersfinancingrealestate_com_-_listingsdb', $connresult); if (!db_selected) {     $problemtext = 'Error selecting MySQL db.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } //For MySQL 4.0.11 and higher $start_transaction = "START TRANSACTION"; $start_transaction_result = mysql_query($start_transaction); if (!$start_transaction_result) {     $problemtext = 'Error Starting MySQL Transaction.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } $insert_query = "INSERT INTO `ofrearchive`      SELECT * FROM `ofrelistings` LEFT JOIN `ofrearchive` USING(uniqueid)      WHERE `ofrearchive.uniqueid` IS NULL AND DATEDIFF(`ofrelistings.dateadded`, now())>30"; $insert_result = mysql_query($insert_query); if (!insert_result) {      $rollback_transaction = "ROLLBACK";      $rollback_result = mysql_query($rollback_transaction);      if (!$rollback_result)      {          $problemtext = 'Error with Rollback.\r\n'.mysql_error($connresult);          trigger_error($problemtext, E_USER_ERROR);      }     $problemtext = 'Error INSERT-ing information into archive table.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } $delete_query = "DELETE `ofrelistings.*` FROM `ofrelistings` INNER JOIN `ofrearchive` USING(uniqueid)"; $delete_result = mysql_query($delete_query); if (!$delete_result) {      $rollback_transaction = "ROLLBACK";      $rollback_result = mysql_query($rollback_transaction);      if (!$rollback_result)      {          $problemtext = 'Error with Rollback.\r\n'.mysql_error($connresult);          trigger_error($problemtext, E_USER_ERROR);      }     $problemtext = 'Error DELETE-ing information from main table.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } $select_query = "SELECT * FROM `ofrelistings` INNER JOIN `ofrearchive` USING(uniqueid)"; $select_result = mysql_query($select_query); if (!select_result) {         echo 'Backup worked successfully'; } else {      $rollback_transaction = "ROLLBACK";      $rollback_result = mysql_query($rollback_transaction);      if (!$rollback_result)      {          $problemtext = 'Error with Rollback.\r\n'.mysql_error($connresult);          trigger_error($problemtext, E_USER_ERROR);      }     $problemtext = 'Error completing the backing up of information from main table to archive table.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } $searchstring = "SELECT * FROM `ofrelistings` WHERE blahblahblahblah"; $searchresults = mysql_query($searchstring); if (!$searchresults) {      $rollback_transaction = "ROLLBACK";      $rollback_result = mysql_query($rollback_transaction);      if (!$rollback_result)      {          $problemtext = 'Error with Rollback.\r\n'.mysql_error($connresult);          trigger_error($problemtext, E_USER_ERROR);      }     $problemtext = 'Error searching OFRE listings db.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } //If no errors occurred, then commit transactions $commit_transaction = "COMMIT"; $commit_result = mysql_query($commit_transaction); if (!$commit_result) {     $problemtext = 'Error with Commit.\r\n'.mysql_error($connresult);     trigger_error($problemtext, E_USER_ERROR); } $numrows = mysql_num_rows($searchresults); if ($numrows == 0) {     echo "No results matched your search criteria";     require('/home/virtual/ofre.com/var/www/includes/copyright.php');     require('/home/virtual/ofre.com/var/www/includes/closetables.php');     exit; } //Retrieve, check, and print results while ($row = mysql_fetch_assoc($searchresults)) {     //echo out results in a table including handling pics } //free up result memory mysql_free_result($searchresults); [/code]
  24. Like in my PHP script suppose I have to perform a SELECT, then an INSERT, then a DELETE, then maybe another SELECT or DELETE. Now suppose this script somehow fails on the DELETE or INSERT or the last SELECT. How do I get it to disregard the other queries unless everything goes through? Do I need to use something like transactions, commits, and rollbacks?
  25. You could probably just use the Modulus operator. This basically divides 2 numbers and tells you what the remainder is. So you could test and see if it's equal to 0, and if so, then you know that one number is a multiple of another. Here's an example using the numbers from your example: [code] $a = 1033343; $b = 3; $result = $a % $b; if ($result == 0)        echo 'the two numbers are evenly divisible'; else        echo 'the two numbers are not evenly divisible'; [/code]
×
×
  • 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.