Jump to content

Psycho

Moderators
  • Content Count

    12,013
  • Joined

  • Last visited

  • Days Won

    116

Psycho last won the day on December 2

Psycho had the most liked content!

Community Reputation

565 Excellent

About Psycho

  • Rank
    Move along, nothing to see here

Profile Information

  • Gender
    Not Telling
  • Location
    Canada

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. None of what you described requires the code to be in the same page or not. For small projects, it's fine. But, it is significantly easier to manage code when you have separate files based on separate purposes.
  2. Put the code in your post as text (using the code tags) not as an image. As to your problem. this is NOT doing what you think it is if($Name_Tag = 15) Read this: Comparison Operators
  3. On your gallery page, you have a process to get an array of images which you should ensure has a numerically based index (0, 1, 2, ...). First, you need to take that logic and put it in a separate file that you will include() in your gallery page. You need to do this because you will need to include the same logic on the "enlarged version" script so you always get the exact same array. Never "copy/paste" such logic between multiple pages - especially when those multiple pages are dependent upon the data being the same. Then, on your gallery page, make each image a link to open the image in the "enlarged version" page. That link would look something like this showfull.php?id=3 Lastly, your enlarged version page could look something like this. <?php //Include script to generate the image array include('getImageArray.php'); //Get the passed image id $imageId = isset($_GET['id']) ? int($_GET['id']) : 0; //Check if the image exists if(!array_key_exists($imageId, $images) { //Error handling when the selected image does not exist $output = "Unable to retireve image"; } else { //Detemine if there will be a "prev" button (assumed array is always zero-based $prevId = $imageId-1; $prevLink = (array_key_exists($prevId, $images) ? "<a href='showfull.php?id={$prevId}'>PREV</a>" : ''; //Detemine if there will be a "next" button $nextId = $imageId+1; $nextLink = (array_key_exists($nextId, $images) ? "<a href='showfull.php?id={$nextId}'>NEXT</a>" : ''; //Create the output $output = "SOME CONTENT TO SHOW FULL-SIZE IMAGE<img src='base_path/{$images[$imageId]}' /><br>"; $output .= "{$prevLink} | {$nextLink}"; }
  4. Have you inspected the HTML output to see if the text is there, but maybe is not within proper HTML tags making it 'hidden'? Your code is hard to follow for a number of reasons. But, my guess, is that there is a problem with the structure of the output. So, a couple of suggestions: 1. When checking for multiple error conditions, do not do this if(NOT error_condition_1) { if(NOT error_condition_2) { //Success handling } else { //Error condition 2 handling } } else { //Error condition 1 handling } Instead, structure it so the error condition handling is adjacent tot he error condition check. Plus, try not to have a lot of nested if/else conditions. It makes the code much more readable. if(error_condition_1) { //Error condition 1 handling } elseif (error_condition_2) { //Error condition 2 handling } else { //Success handling } 2. use prepared queries. NEVER use user submitted data directly in a query 3. You aren't checking to see that the user provided the top_text or that you are even getting the value. I.e. if the field name was different between the form and the processing page it would insert an empty string. I'm assuming the problem is here and the value you think is being passed isn't referenced correctly and not getting set in the DB <?php // Include the database configuration file include 'database/dbConfig.php'; $statusMsg = ''; // File upload path $targetDir = "uploads/"; $fileName = isset($_FILES["file"]["name"]) ? basename($_FILES["file"]["name"]) : false; $top_text = filter_input(INPUT_POST, 'top_text'); $targetFilePath = $targetDir . $fileName; $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION); //Create Prepared statement $stmt = $pdo->prepare("INSERT into images (file_name, top_text, uploaded_on) VALUES (?, ?, NOW())"); // Allow certain file formats $allowTypes = array('jpg','png','jpeg','gif','pdf'); //Check if there was an upload if($fileName && $fileName!=''){ $statusMsg = 'Please select a file to upload.'; } //Verify top_text is valid elseif (!$top_text || $top_text=='') { $statusMsg = 'Please provide the text.'; } //Verify valid file type elseif(!in_array($fileType, $allowTypes)) { $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, & PDF files are allowed to upload.'; } //Attempt to upload file elseif (!move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)) { $statusMsg = "Sorry, there was an error uploading your file."; } //Attempt the insert query elseif(!$stmt->execute([$fileName, $top_text]);) { $statusMsg = "The file {$fileName} has been uploaded successfully."; } else { //Insert succeeded $statusMsg = "File upload failed, please try again."; } // Display status message echo $statusMsg; ?> 4. The 2nd block of code is hard to read because of the breaking in and out from PP/HTML repeatedly. Also, there is a TON of style properties in there. You should use a style sheet with classes. The complexity in the structure makes it impossible to see structure errors. After cleaning it up, I see that the closing LI tag for the default slide it outside the else container block for that slider. In other words, that closing LI tag is always outputting to the page - even when the default slider is not used. I don't see that this would cause your issue, but it just shows that such simple problems are hidden in that morass of code. There may be other errors that I can't "see" because of all the style properties, but here is a more readable re-write of that section <!-- Revolution slider --> <section id="slider"> <div class="tp-banner-container "> <div class="tp-banner rev-banner-fullscreen"> <ul> <!-- SLIDES --> <?php // Include the database configuration file include 'database/dbConfig.php'; // Get images from the database $query = $db->query("SELECT * FROM images ORDER BY uploaded_on DESC"); if($query->num_rows = 0) { ?> <!-- DEFAULT SLIDE --> <li data-index="rs-140" data-transition="slideup" data-slotamount="default" data-easein="default" data-easeout="default" data-masterspeed="default" data-thumb="" data-rotate="0" data-saveperformance="off" data-title="1/2" data-description=""> <!-- MAIN IMAGE --> <img src="images/slide/slide-5-bg.jpg" style='background-color:#f4f4f4' alt="" width="482" height="800" data-bgposition="center center" data-bgfit="cover" data-bgrepeat="no-repeat" class="rev-slidebg" data-no-retina> <!-- LAYERS --> <!-- LAYERS 1.2 --> <div class="tp-caption tp-resizeme" id="slide-1-layer-2" data-x="['left','left','left','left']" data-hoffset="['102','102','67','40']" data-y="['top','top','top','top']" data-voffset="['150','150','60','60']" data-fontsize="['18','18','14','14']" data-width="['345','345','345','259']" data-height="none" data-whitespace="normal" data-transform_idle="o:1;" data-transform_in="y:50%;z:0;rX:0deg;rY:0;rZ:0;sX:1;sY:1;skX:0;skY:0;opacity:0;s:900;e:Power4.easeInOut;" data-transform_out="x:-50%;opacity:0;s:800;e:Power2.easeInOut;s:300;e:Power2.easeInOut;" data-start="500" data-splitin="none" data-splitout="none" data-responsive_offset="on" style="z-index: 6; min-width: 345px; max-width: 345px; white-space: normal; color: #3e3e3e; font-family: 'Montserrat'; letter-spacing: 7px;"> New Arrival </div> </li> <!-- /END DEFAULT SLIDE --> <?php } else { while($row = $query->fetch_assoc()){ ?> <!-- DYNAMIC SLIDES --> <li data-index="rs-140" data-transition="slideup" data-slotamount="default" data-easein="default" data-easeout="default" data-masterspeed="default" data-thumb="" data-rotate="0" data-saveperformance="off" data-title="1/2" data-description=""> <!-- MAIN IMAGE --> <img src="uploads/<?php echo $row["file_name"]; ?>" alt="" style='background-color:#f4f4f4' alt="" width="482" height="800" data-bgposition="center center" data-bgfit="cover" data-bgrepeat="no-repeat" class="rev-slidebg" data-no-retina> <!-- LAYERS --> <!-- LAYERS 1.2 --> <div class="tp-caption tp-resizeme" id="slide-1-layer-2" data-x="['left','left','left','left']" data-hoffset="['102','102','67','40']" data-y="['top','top','top','top']" data-voffset="['150','150','60','60']" data-fontsize="['18','18','14','14']" data-width="['345','345','345','259']" data-height="none" data-whitespace="normal" data-transform_idle="o:1;" data-transform_in="y:50%;z:0;rX:0deg;rY:0;rZ:0;sX:1;sY:1;skX:0;skY:0;opacity:0;s:900;e:Power4.easeInOut;" data-transform_out="x:-50%;opacity:0;s:800;e:Power2.easeInOut;s:300;e:Power2.easeInOut;" data-start="500" data-splitin="none" data-splitout="none" data-responsive_offset="on" style="z-index: 6; min-width: 345px; max-width: 345px; white-space: normal; color: #3e3e3e; font-family: 'Montserrat'; letter-spacing: 7px;"> <?php echo $row['top_text']; ?> </div> </li> <!-- /END DYNAMIC SLIDE --> <?php } } ?> </ul> </div> <!-- /tp-banner --> </div> <!-- /tp-banner-container --> </section> <!-- /#Revolution slider -->
  5. To add to @maxxd's response. When a user requests a PHP page from a web server, the web server will first execute any php code in the page. The results after the php code is execute is then sent to the user/browser. If you are having problems in the page rendered in the browser, there is something off in the output (HTML, Javascript, etc.) sent to the browser. It can get confusing when you are using a programming language (PHP) to dynamically create other code (JavaScript) or Markup (HTML).
  6. It's pretty frustrating when someone asks for help and then they change the requirements. It would also be helpful if you provided REAL content instead of something with gibberish. <?php $text = "start 00000000000000000 REMOVE ON FIRST PASS end start 11111111111111111111 XXXXXXX keyword XXXXXXXXXXX end start oidfgoj 11111111111111111111 keyword REMOVE ON 2ND PASS end start abcd keyword efg 2222222222222222222 REMOVE ON 2ND PASS abcd keyword abcd end SOME OTHER TEXT WILL NOT BE REPLACED start 0000000000000000000 REMOVE ON FIRST PASS end start keyword oidfgoj 33333333333333333333333 abcd REMOVE ON 2ND PASS abcd keyword fdsfs keyword pwefkoewfk end"; function replaceTextBlocks($input, $startDelimiter, $endDelimite, $keyword='keyword', $withKeyword=false) { if($keyword!='') { $keyword = "{$keyword}.*?"; } //$pattern = "#^{$startDelimiter}.*?{$keyword}{$endDelimite}#ms"; if(!$withKeyword) { //Remove blocks w/o the keyword $pattern = "#^{$startDelimiter}((?!{$keyword}).)*{$endDelimite}[\n\r]*#ms"; } else { //Remove blocks with the keyword $pattern = "#^{$startDelimiter}.*?{$keyword}.*?{$endDelimite}[\n\r]*#ms"; } //echo $pattern; $newText = preg_replace($pattern, '', $input); return $newText; } echo "Original text: <pre>{$text}</pre><br>\n"; $text = replaceTextBlocks($text, 'start', 'end', 'keyword'); echo "First Pass: <pre>{$text}</pre><br>\n"; $text = replaceTextBlocks($text, 'start', 'end', 'keyword', true); echo "Second Pass: <pre>{$text}</pre><br>\n"; ?>
  7. Pleas explain what you expect that code to do and then describe what it is doing (or not doing) that is contrary to your expectations. Are there errors? FYI: there is nothing in that code that ever calls that function. So, kinda hard to say it isn't working, when it is not used.
  8. Do you understand WHY that last attempt worked and the previous ones failed? If not, you are going to repeat the same errors in the future.
  9. This may work for you. Here is a function that returns the "textblocks" that begin/end with a delimiter string OR (if a keyword is provided, then it only returns "textblocks" that also contain that keyword. As I made the regular expressions programatical, it may be difficult to see how they are constructed. The two formats would look like this: #^smaple.*?smaple#ms and #^smaple.*?keyword.*?smaple#ms <?php $text = "smaple woiefjeowijji oj oiewjfoewijfoiwejfiojewf keyword owiejfioejoij oiewjfioewjf smaple smaple ojioewj fijo oieiojewf keyword owiejfioejoij oiewjfioewjf smaple smaple woiefjeowijji fijo oiewjfoewijfoiwejf owiejfioejoij oiewjfioewjf smaple"; function findTextBlocks($input, $delimiter, $keyword='') { if($keyword!='') { $keyword = "{$keyword}.*?"; } $pattern = "#^{$delimiter}.*?{$keyword}{$delimiter}#ms"; echo $pattern; preg_match_all($pattern, $input, $matches); return $matches; } $textBlocks = findTextBlocks($text, 'smaple'); echo "<pre>".print_r($textBlocks, true)."</pre>"; $textBlocksWithKeyword = findTextBlocks($text, 'smaple', 'keyword'); echo "<pre>".print_r($textBlocksWithKeyword, true)."</pre>"; ?> Output #1 Output #2
  10. I'm not sure I follow what you are exactly trying to find. I see you gave some example input, it would have been helpful to see what you expect to be returned. Specifically, I'm not sure what you mean by "textblock". I *think* you mean where a line starts with 'sample' followed by however many lines until you find a line that ends with 'sample'. However, note that the word "sample" never appears in your text block. There is a word spelled "smaple" - I have no idea what that is. How you word #1 and #2 is confusing as well. Are you saying you want to find the first textblock which starts with "sample" and ends with "sample" and then find the NEXT textblock the same way, but the second one contains the keyword? Or does #2 mean the keyword is supposed to be in the first textblock?
  11. You can turn on error reporting in your script by putting this at the top of the page error_reporting(E_ALL); https://www.php.net/manual/en/function.error-reporting.php
  12. Short fuse? I've taken the time to respond multiple times providing the same information which you ignore because you've got some preconceived notions in your head that you can't get rid of. Think of it this way, someone is taking time out of their day to try and help someone for no reason other than goodwill - there is no compensation for their time. Yet, the person they are trying to help ignores/disregards the help being provided such that the person providing the help invests even more time and energy helping that person. So, who is the "nutter" in this scenario? The person that is attempting to help or the person that won't take the time to try and understand the help being provided? You are "terrible" at this because you are not taking the time to understand the process. Instead you seem to be throwing things at the wall to see what will stick. Let's try one more time: Your requirement is to delete a record three days after the user performs some event (which I assume is a logout). Is this correct? 1) You first need to perform an action when the user selects the option to logout. As stated many times, you would want to set a datetime/timestamp value for the record. STOP HERE. Is there something about that statement that you do not 100% understand? Do you understand why the record would need to be updated and why we would use a datetime/timestamp value for that update? If you are not 100% clear, ask a question about that. You've previously provided info that when this action takes place the user_id is available in the session data. So, we would accomplish the above action like so: //Create a prepared statement with placeholder for the user_id of the record to be updated $stmt = $dbc->prepare("UPDATE users SET logout_datetime = NOW() WHERE user_id = ? "); //Bind the user_id value to the prepared query and execute it $stmt->bind_param('i', $_SESSION['user_id']); $stmt->execute(); STOP HERE. Do you understand all of the code above? If not, ask a question about what you don't understand or look at the manual for any function you don't understand. 2) Now that users will have a datetime/timestamp value set when they log out, there needs to be a separate process that will delete the records after three days. To accomplish this, you would create a separate script which will need to be executed on a regular basis (e.g. daily). You will need to check your host options o how to do this. Typically these will be called CRON jobs. You basically set up a scheduled task to run a script at a predetermined interval. STOP HERE. Do you understand what was just stated? If not ask a specific question. If you don't know how to create a CRON job, you need to go into your hosting options, check help and/or contact support. Once you know how to create a CRON job, you just need to create the script that will run every day (or whatever time interval you choose). Since we have a datetime/timestamp of when users have logged out, a single query can be executed to delete all records where that value is > 3 days (as has been provided previously) $query = "DELETE FROM users WHERE logout_datetime < (DATE(NOW()) - INTERVAL 3 DAY)"; //No user_id $stmt = $pdo->query($query) STOP HERE. Do you understand what that query is doing and why user_id is not needed? This is my last attempt. I hope you will READ the above information and attempt to comprehend it. If you have any questions that show that you have put some energy into trying to trying to figure this out instead of just haphazardly writing new code, I will try to answer. Otherwise, I which you all the best in your endeavors.
  13. I'm trying really hard now not to start using foul language. You are doing exactly what I said before. You aren't reading what is posted - as in looking at it critically and trying to comprehend what is being provided. Instead you seem to be fixated on some erroneous logic and are trying to fit the responses into that. Do you understand that what you want to accomplish has two separate processes (as I've explained multiple times)? If you have a question about what I posted ask a specific question about it instead of coming up with some nonsense question.
  14. I think you are misunderstanding something - why is there a placeholder for id in the delete query? Go back and read my last post and pay attention to the very explicit details I posted for steps #1 and #2. Then go back to the post I made before that where I provided example queries for #2 and neither included a user_id. I think the problem is that you have an incorrect assumption in your head and every new piece of data you are trying to align it with that assumption. You need to read the responses and not assume. It really isn't that difficult. I will try one more time to explain this. 1. When a user selects an option to logout you will run a process to set a logout time for that specific user. In this case you will get their user id from the session and run an UPDATE query similar to what Barand provided using the user_id to determine which records to apply the update to: $stmt = $dbc->prepare("UPDATE users SET logout_datetime = NOW() WHERE user_id = ? "); // prepare query with placeholder (?) for id value $stmt->bind_param('i', $_SESSION['user_id']); $stmt->execute() 2. Run a scheduled task to delete the records of ALL USERS where the logout_datetime is more than 3 days in the past. It will only use the logout_datetime field to determine which records to delete (i.e. no user_id). Also, there is no need to use a prepared statement since this does not use any input variables. $query = "DELETE FROM users WHERE logout_datetime < (DATE(NOW()) - INTERVAL 3 DAY)"; //No user_id $stmt = $pdo->query($query)
  15. As I understand your requirements, there appears to be some process that is initiated by the user that initiates the code you are currently working on. I assume it is a logout process, but you have not explicitly stated. Right now, the code is deleting the record, but you later stated . So, there needs to be TWO separate events: One to set the timer and one to delete the records. 1) Modify your existing code for the event so it sets the datetime/timestamp value for the user initiated action - this will occur for each user individually. 2) Create a process that runs daily (or whatever interval you decide) which will delete the records associated with all users where the applicable time period has elapsed. This is a single query that executes for all applicable records at once. Do NOT name your field datetime. That is a field type in MySQL and is a "reserved word". You would have to take special steps to prevent errors in your query if you have a field named using a reserved word. Give it a name that is representative of what it is: expirationDate, logoutDate, etc.
×
×
  • 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.