
EarthDay
Members-
Posts
42 -
Joined
-
Last visited
Everything posted by EarthDay
-
Show database entries by todays date plus 7 days
EarthDay replied to EarthDay's topic in PHP Coding Help
Hi All, Thank you all for your help on this I have figured this out by using the below code $stmt = $pdo->query("SELECT * FROM care_plan_review WHERE reminder_date between now() and now() + INTERVAL 7 DAY"); Cheers, ED. -
Show database entries by todays date plus 7 days
EarthDay replied to EarthDay's topic in PHP Coding Help
The full code is $now = date("Y-m-d h:i:sa"); $stmt = $pdo->prepare('SELECT * FROM care_plan_review where reminder_date > ? order by id desc'); $stmt->execute([$now]); $allReview = $stmt->fetchAll(PDO::FETCH_ASSOC); $now = date("Y-m-d h:i:sa"); $stmt = $pdo->prepare('SELECT * FROM care_plan_review where reminder_date > ? order by id desc'); $stmt->execute([$now]); $allReview = $stmt->fetchAll(PDO::FETCH_ASSOC); -
Show database entries by todays date plus 7 days
EarthDay replied to EarthDay's topic in PHP Coding Help
Hi Barand, Thank you for this. I have updated my code and get the following error message; Any ideas? Cheers, ED. -
Hi there, I am trying to show entries in my database that have todays date plus seven days. My code is currently $stmt = $pdo->prepare('SELECT * FROM care_plan_review where reminder_date > ? order by id desc'); This does not work sadly. Any thoughts? Cheers, ED.
-
Hi All, cyberRobot - thanks for your advice, the expected outputs were been returned. I have managed to resolve this by adding (INT); Example: $minutes = (INT)$hour + (INT)$record['minute']; Thanks, ED.
-
Hi All, I have upgraded my test server to PHP 8 and I am having an issue with my yearly staff holiday script (works out how many hours / minutes have been taken and how many left) and firstly gave me the below error message; Fatal error: Uncaught TypeError: Unsupported operand types: int - string in After a bit of Google and SO, I think that this has been solved by adding (int) to the - string. I am now getting the below error message; Fatal error: Uncaught TypeError: Unsupported operand types: string / int in Anything that I have tried from SO and Google does not appear to be working. Original Code <?php $time = $holiday_remain_time['total_year_holiday_hours_complete']; $total_year_holiday_hours = $holiday_remain_time['total_year_holiday_hours'] * 60; $remaining = ($total_year_holiday_hours - $holiday_remain_time['total_year_holiday_hours_complete']); $minutes = $holiday_remain_time['total_year_holiday_hours_complete']; $hours = floor($minutes/60).'.'. ($minutes % 60); $showHours = floor($minutes/60).' Hour '. ($minutes % 60) . ' Minute'; $reminutes = $remaining; $reshowHours = floor($reminutes/60).' Hour '. ($reminutes % 60) . ' Minute'; ?> Modified Code <?php $time = $holiday_remain_time['total_year_holiday_hours_complete']; $total_year_holiday_hours = $holiday_remain_time['total_year_holiday_hours'] * 60; $remaining = ((int)$total_year_holiday_hours - (int)$holiday_remain_time['total_year_holiday_hours_complete']); $minutes = $holiday_remain_time['total_year_holiday_hours_complete']; $hours = floor($minutes/60).'.'. ($minutes % 60); $showHours = floor($minutes/60).' Hour '. ($minutes % 60) . ' Minute'; $reminutes = $remaining; $reshowHours = floor($reminutes/60).' Hour '. ($reminutes % 60) . ' Minute'; ?> Database `id` int(11) NOT NULL, `user_id` int(100) DEFAULT NULL, `total_year_holiday_hours` varchar(100) DEFAULT NULL, `total_year_holiday_hours_complete` varchar(100) DEFAULT NULL Output Example Yearly Holiday : 40 Hours Already Holiday Taken : 15 Hours Remaining Holiday Hour: 25 Hours Display code <tbody> <?php foreach($holiday_activity as $record){ $hour = $record['hour'] * 60; $minutes = $hour + $record['minute']; $hours = intdiv($minutes, 60).' Hour '. ($minutes % 60) . ' Minute'; ?> <tr> <td><?php $date = $record['date']; $bits = explode('-', $date); $date = $bits[2] . '/' . $bits[1] . '/' . $bits[0]; echo $date; ?></td> <td><?php $date = $record['end_date']; $bits = explode('-', $date); $date = $bits[2] . '/' . $bits[1] . '/' . $bits[0]; echo $date; ?></td> <td><?= $hours; ?></td> <td><?php echo $record['status']; ?></td> <td> <?php if($record['status'] == 'active'){ echo 'cannot change'; } else{ ?> <a href="" class="btn btn-primary" data-toggle="modal" data-target="#staticBackdrop<?php echo $record['id']; ?>"> Edit </a> <!-- <a href="delete.php" class="btn btn-warning">Cancel</a> --> <?php } ?> </td> </tr> I have changed the database columns to INT and ran var_dump($hours); which shows NULL before the Modified Code above. If I run var_dump($hours); after the Modified Code, it shows nothing. Thanks, ED.
-
Hi there, So sorry for the late reply, I have had a week off from work and just got back today. Thank you all so much for the information, I have solved this by removing the else{ statement and changed the insert query to $path and works fine. Cheers, ED.
-
Hi there, I have just upgraded to PHP8 on my test server a few days ago and I am testing the referral form and it's giving me the below error message when submitting with or without an image inn the upload box; "Warning: Undefined variable $imageSource in /var/www/vhosts/site/form/index.php on line 119" I have checked my variables and as far as I understand (still learning PHP) have been set correctly. I have also read some other articles on here but nothing seems to work :( The images no longer upload. This was working fine in PHP 7. if (!empty($_POST)) { $folder ="uploads/"; $image = $_FILES['image']['name']; $path = $folder . uniqid().$image ; $target_file=$folder.basename($_FILES["image"]["name"]); $imageFileType=pathinfo($target_file,PATHINFO_EXTENSION); $allowed=array('jpeg','png' ,'jpg','gif'); $filename=$_FILES['image']['name']; $ext=pathinfo($filename, PATHINFO_EXTENSION); if(!in_array($ext,$allowed) ) { $msg = "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; } else{ move_uploaded_file( $_FILES['image'] ['tmp_name'], $path); $imageSource = $path; } Line 119; $image = $imageSource; Cheers, ED.
-
Unable to display username from another table
EarthDay replied to EarthDay's topic in PHP Coding Help
Hi, thanks for this. I was trying c.id to see if I could get it working. I've set $stmt->execute([$_GET['id']]); to ID as requested and gives me the same error message. Warning: Undefined array key "id" Thanks, ED. -
Unable to display username from another table
EarthDay replied to EarthDay's topic in PHP Coding Help
Hi All, Thank you for your replies. I have enabled PHP 8 on my server and it giving me a lot better error messages now, thanks for that. The error message that I am getting is "Warning: Undefined array key "id" or Warning: Undefined array key "c.id". I have read a few tutorials about this now and can't see where I am going wrong assoc mode has also been set on the query. $stmt = $pdo->prepare('SELECT c.id , c.name , c.last_name , c.mobile_number , c.status , a.username as mentorname FROM contacts c LEFT JOIN accounts a ON c.mentor = a.id WHERE c.id = ?;'); $stmt->execute([$_GET['c.id']]); $fullContactInfo = $stmt->fetchAll(PDO::FETCH_ASSOC); Thanks, ED. -
Unable to display username from another table
EarthDay replied to EarthDay's topic in PHP Coding Help
Hi Barand, Many thanks for this. My code now reads $stmt = $pdo->prepare('SELECT c.id , c.name , c.last_name , c.mobile_number , c.status , a.username as mentorname FROM contacts c LEFT JOIN accounts a ON c.mentor = a.id WHERE c.id = 1;'); $stmt->execute([$_GET['c.id']]); $fullContactInfo = $stmt->fetchAll(PDO::FETCH_ASSOC); <?php if($fullContactInfo == null){ echo "<tr><td>No Record Found!</td></tr>"; }else{ foreach($fullContactInfo as $info){ ?> <tr> <td><?php echo $info['name']; ?> <?php echo $info['last_name']; ?></td> <td><?php echo $info['mobile_number']; ?></td> <td><?php echo $info['status']; ?></td> <td><?php echo $info['mentorname']; ?></td <td><img src="<?php echo $info['image']; ?>" alt="" style="height: 30px; width:30px;"></td> <td> The info is not showing anything now, is there something I am missing please? Cheers -
Hi there - I currently am able to view a list of contacts with no issues and would like to be able to view the mentors / tutors for the clients. The username is stored in another table to the contact information and the mentor ID is stored in the contacts table. I have followed a tutorial on how to do this but can't get it to work. The information for the contacts table appears fine but does not display the username from the accounts table. Error reporting is on but not giving me any error messages. Code; $stmt = $pdo->prepare('SELECT id,name,last_name,mobile_number,status,dob,mentor,image FROM contacts'); $stmt->execute([$_GET['id']]); $fullContactInfo = $stmt->fetchAll(PDO::FETCH_ASSOC); if($fullContactInfo == true){ $stmt = $pdo->prepare('SELECT username FROM accounts WHERE id = ?'); $stmt->execute([ $fullContactInfo['mentor'] ]); $fullContactInfo1 = $stmt->fetch(PDO::FETCH_ASSOC); } Display code <?php if($fullContactInfo == null){ echo "<tr><td>No Record Found!</td></tr>"; }else{ foreach($fullContactInfo as $info){ ?> <tr> <td><?php echo $info['name']; ?> <?php echo $info['last_name']; ?></td> <td><?php echo $info['mobile_number']; ?></td> <td><?php echo $info['status']; ?></td> <td><?= $fullContactInfo1['username']; ?></td> Table examples Contacts ID:1 Name: Joe Blogs Mobile: 1889454 Status: Current Mentor: 25 Accounts ID: 25 Username: jbloggs Many thanks.
-
Many thanks for your help guys, I worked out that the code was very buggy and used another code from the internet which worked perfectly. Many thanks again Physco - thanks for info about validation, I have used the principles in my new code.
-
The GET is to get fetch the information from the database and the POST is to store the information.
-
Hi Everyone, I have modified a working form that works fine on my system but the changes that I have made are not working on the new form. I have error and PDO error reporting switched on and it's not giving me any error messages. I have checked and triple checked everything and matches the database fine. I am scratching my head now and can't see the issue. Many thanks, ED. <?php include '../../main.php'; check_loggedin($pdo); $msg = null; $date = new DateTime(); $totay_date = $date->format('Y-m-d\TH:i:s'); if (isset($_GET['id'])) { $stmt = $pdo->prepare('SELECT * FROM contacts WHERE id = ?'); $stmt->execute([$_GET['id']]); $contact = $stmt->fetch(PDO::FETCH_ASSOC); $stmt = $pdo->prepare('SELECT id,username FROM accounts'); $stmt->execute(); $all_account_info = $stmt->fetchAll(PDO::FETCH_ASSOC); if(isset($_POST['learning_actual_end_date']) == null || isset($_POST['partcipant_complete_course']) == null || isset($_POST['withdrawal_reason']) == null || isset($_POST['participant_intended_learning']) == null || isset($_POST['pcp_education']) == null || isset($_POST['coursestart_date']) == null || isset($_POST['education_provider_name']) == null || isset($_POST['course_title']) == null || isset($_POST['course_level']) == null || isset($_POST['planned_glh']) == null || isset($_POST['in_paid_employment']) == null || isset($_POST['in_paid_employment_start_date']) == null || isset($_POST['in_paid_employer_name_address']) == null || isset($_POST['in_paid_job_title']) == null || isset($_POST['in_paid_contracted_hour']) == null || isset($_POST['not_in_paid_employment']) == null || isset($_POST['pcp_gap_year']) == null || isset($_POST['pcp_others']) == null || isset($_POST['pcp_voluntary_work']) == null || isset($_POST['destination_progression_date']) == null || isset($_POST['destination_progression_collecton_date']) == null || isset($_POST['project_officer_name']) == null || isset($_POST['project_officer_date']) == null || isset($_POST['project_officer_date']) == null || isset($_POST['participant__name']) == null || isset($_POST['participant__signature']) == null || isset($_POST['participant__date']) == null || isset($_POST['final_assessment_progress_you_made']) == null || isset($_POST['final_assessment_progress_your_goal']) == null || isset($_POST['final_assessment_progress_your_reach_goal']) == null || isset($_POST['final_assessment_progress_overall']) == null || isset($_POST['final_assessment_participat_name']) == null || isset($_POST['final_assessment_participat_signature']) == null || isset($_POST['final_assessment_participat_date']) == null || isset($_POST['final_assessment_project_worker_name']) == null || isset($_POST['final_assessment_project_worker_signature']) == null || isset($_POST['final_assessment_project_worker_date']) == null){ $msg = ''; }else{ $id = isset($_POST['id']) && !empty($_POST['id']) && $_POST['id'] != 'auto' ? $_POST['id'] : auto; $stmt = $pdo->prepare('INSERT INTO esf_completed VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); $result = $stmt->execute([$id, $_GET['id'], $_POST['learning_actual_end_date'], $_POST['partcipant_complete_course'], $_POST['withdrawal_reason'], $_POST['participant_intended_learning'], $_POST['pcp_education'], $_POST['coursestart_date'], $_POST['education_provider_name'], $_POST['course_title'], $_POST['course_level'], $_POST['planned_glh'], $_POST['in_paid_employment'], $_POST['in_paid_employment_start_date'], $_POST['in_paid_employer_name_address'], $_POST['in_paid_job_title'], $_POST['in_paid_contracted_hour'], $_POST['not_in_paid_employment'], $_POST['pcp_gap_year'], $_POST['pcp_others'], $_POST['pcp_voluntary_work'], $_POST['destination_progression_date'], $_POST['destination_progression_collection_date'], $_POST['project_officer_name'], $_POST['project_officer_signature'], $_POST['project_officer_date'], $_POST['participant__name'], $_POST['participant__signature'], $_POST['participant__date'], $_POST['final_assessment_progress_you_made'], $_POST['final_assessment_progress_your_goal'], $_POST['final_asessment_progress_your_reach_goal'], $_POST['final_assessment_progress_overall'], $_POST['final_assessment_participat_name'], $_POST['final_assessment_participat_signature'], $_POST['final_assessment_participat_date'], $_POST['final_assessment_project_worker_name'], $_POST['final_assessment_project_worker_signature'], $_POST['final_assessment_project_worker_date']]); $msg = "New Soft Skills Entry Added"; } if (!$contact) { exit('No contact with that ID!'); } } else { exit('No ID specified!'); } ?>
-
Duplicate ID issue when trying to copy table row
EarthDay replied to EarthDay's topic in PHP Coding Help
Hi Barand, Sorry for the late reply to this message. Thank you so much, this has help me massively and got the script working. 🙂 -
Hello all, I am trying to create a script to allow me to copy a table row from one database to another but I am having an issue creating new ID's when a duplicate is found. It just tells me that the ID has already been copied if found in the second database. This is also a safety feature to avoid data been over written. URL is page.php?id=12 The column for ID is set to AI. $mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName); $id = $_GET['id']; $sql="select * from db2.contacts where ($id = intval($id));";// check id is already copied $res=mysqli_query($mysqli,$sql); if (mysqli_num_rows($res) > 0) { $row = mysqli_fetch_assoc($res); if($id==$row['id']) { echo "Already copied"; //error message if already copied } } else{ $query=mysqli_query($mysqli,"INSERT INTO db2.contacts SELECT * FROM db1.contacts WHERE id =$id"); echo "Successfully copied"; } Any help would be gratefully appreciated as I am banging my head against the table lol Cheers.