-
Notifications
You must be signed in to change notification settings - Fork 227
corrected the database server name and patient's database queries #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request updates the way the application interacts with the database. In Changes
Poem
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 24
🔭 Outside diff range comments (1)
patient/patient.php (1)
376-377:⚠️ Potential issueRepeated Unsanitized Query
As above,$idis being used unsafely in a query.Use prepared statements here as well:
- $sqlmain= "select * from patient where pid='$id'"; - $result= $database->query($sqlmain); + $stmt = $database->prepare("SELECT * FROM patient WHERE pid = ?"); + $stmt->bind_param("i", $id); + $stmt->execute(); + $result = $stmt->get_result();
🧹 Nitpick comments (1)
connection.php (1)
10-10: Add clarity to your error message for better debugging.
Appending the raw$database->connect_errordirectly to “Error! connection failed” may be sufficient, but consider adding punctuation or whitespace. For instance:die("Error! Connection failed: " . $database->connect_error);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
connection.php(1 hunks)patient/appointment.php(2 hunks)patient/booking-complete.php(1 hunks)patient/booking.php(2 hunks)patient/delete-account.php(2 hunks)patient/delete-appointment.php(0 hunks)patient/doctors.php(2 hunks)patient/edit-user.php(2 hunks)patient/index.php(1 hunks)patient/patient.php(3 hunks)patient/schedule.php(2 hunks)patient/settings.php(4 hunks)
💤 Files with no reviewable changes (1)
- patient/delete-appointment.php
🔇 Additional comments (2)
connection.php (1)
2-5:❓ Verification inconclusive
Confirm environment consistency for new DB server and DB name.
Switching from"db"to"localhost"and"edoc"to"sql_database_edoc"may break code outside of Docker-like setups or if the new database name does not exist. Ensure that these changes align with your local/production database environment and that"sql_database_edoc"is set up accordingly.You can verify by checking the actual DB names and environment variables with this script:
🏁 Script executed:
#!/bin/bash # Check if the "sql_database_edoc" DB is present and "localhost" is accessible. # List databases mysql -h localhost -u root -p -e "SHOW DATABASES;" # Verify the presence of 'sql_database_edoc' in the listLength of output: 148
Action Required: Verify New Database Connection Settings
Please ensure that your updated database connection parameters in
connection.php(i.e.,"localhost","root", empty password, and"sql_database_edoc") are consistent with your intended environment. The automated verification script failed because themysqlcommand was not found. Kindly verify manually that:
- The MySQL client is installed and accessible in your environment.
- The
"sql_database_edoc"database exists and is correctly configured for your local/production setups.patient/settings.php (1)
548-548: No Meaningful Change Detected
This appears to be a closing tag without functional changes.
| $stmt->bind_param("s",$useremail); | ||
| $stmt->execute(); | ||
| $userrow = $stmt->get_result(); | ||
| $userrow = $database->query("select * from patient where pemail='$useremail'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reintroduce parameterized queries to avoid SQL injection.
By constructing the query with $useremail directly in the string, you risk SQL injection if $useremail is not fully trusted. It’s safer to use parameter binding:
-$userrow = $database->query("select * from patient where pemail='$useremail'");
+$stmt = $database->prepare("SELECT * FROM patient WHERE pemail = ?");
+$stmt->bind_param("s", $useremail);
+$stmt->execute();
+$userrow = $stmt->get_result();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $userrow = $database->query("select * from patient where pemail='$useremail'"); | |
| $stmt = $database->prepare("SELECT * FROM patient WHERE pemail = ?"); | |
| $stmt->bind_param("s", $useremail); | |
| $stmt->execute(); | |
| $userrow = $stmt->get_result(); |
| $aab="select patient.pid from patient inner join webuser on patient.pemail=webuser.email where webuser.email='$email';"; | ||
| $result= $database->query($aab); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore prepared statements to ensure secure user lookups.
Constructing SQL with '$email' directly eliminates the protection from prepared statements. To prevent SQL injection, use parameter binding:
-$aab="select patient.pid from patient inner join webuser on patient.pemail=webuser.email where webuser.email='$email';";
-$result= $database->query($aab);
+$stmt = $database->prepare("SELECT patient.pid FROM patient
+ INNER JOIN webuser ON patient.pemail = webuser.email
+ WHERE webuser.email = ?");
+$stmt->bind_param("s", $email);
+$stmt->execute();
+$result = $stmt->get_result();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $aab="select patient.pid from patient inner join webuser on patient.pemail=webuser.email where webuser.email='$email';"; | |
| $result= $database->query($aab); | |
| $stmt = $database->prepare("SELECT patient.pid FROM patient | |
| INNER JOIN webuser ON patient.pemail = webuser.email | |
| WHERE webuser.email = ?"); | |
| $stmt->bind_param("s", $email); | |
| $stmt->execute(); | |
| $result = $stmt->get_result(); |
| $userrow = $database->query("select * from patient where pemail='$useremail'"); | ||
| $userfetch=$userrow->fetch_assoc(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid direct string interpolation for user email to prevent SQL injection.
Replace the unbound query with a prepared statement:
-$userrow = $database->query("select * from patient where pemail='$useremail'");
-$userfetch=$userrow->fetch_assoc();
+$stmt = $database->prepare("SELECT * FROM patient WHERE pemail = ?");
+$stmt->bind_param("s", $useremail);
+$stmt->execute();
+$userfetch = $stmt->get_result()->fetch_assoc();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $userrow = $database->query("select * from patient where pemail='$useremail'"); | |
| $userfetch=$userrow->fetch_assoc(); | |
| $stmt = $database->prepare("SELECT * FROM patient WHERE pemail = ?"); | |
| $stmt->bind_param("s", $useremail); | |
| $stmt->execute(); | |
| $userfetch = $stmt->get_result()->fetch_assoc(); |
|
|
||
| $keyword=$_POST["search"]; | ||
| $sqlmain= "select * from schedule inner join doctor on schedule.docid=doctor.docid where schedule.scheduledate>='$today' and (doctor.docname='$keyword' or doctor.docname like '$keyword%' or doctor.docname like '%$keyword' or doctor.docname like '%$keyword%' or schedule.title='$keyword' or schedule.title like '$keyword%' or schedule.title like '%$keyword' or schedule.title like '%$keyword%' or schedule.scheduledate like '$keyword%' or schedule.scheduledate like '%$keyword' or schedule.scheduledate like '%$keyword%' or schedule.scheduledate='$keyword' ) order by schedule.scheduledate asc"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use parameterized queries for keyword-based searching.
Directly concatenating $keyword into your SQL allows malicious input to break your query. Switch to prepared statements:
-$sqlmain= "select * from schedule inner join doctor on schedule.docid=doctor.docid
- where schedule.scheduledate>='$today' and (doctor.docname='$keyword'
- or doctor.docname like '$keyword%' or doctor.docname like '%$keyword'
- or doctor.docname like '%$keyword%' or ... ) order by schedule.scheduledate asc";
+$sqlmain = "SELECT * FROM schedule
+ INNER JOIN doctor ON schedule.docid = doctor.docid
+ WHERE schedule.scheduledate >= ?
+ AND (doctor.docname = ? OR doctor.docname LIKE CONCAT(?,'%')
+ OR doctor.docname LIKE CONCAT('%',?)
+ OR doctor.docname LIKE CONCAT('%',?,'%')
+ OR ... )
+ ORDER BY schedule.scheduledate ASC";
+
+$stmt = $database->prepare($sqlmain);
+$likeKeyword = $keyword;
+$stmt->bind_param("sssss", $today, $keyword, $likeKeyword, $likeKeyword, $likeKeyword);
+$stmt->execute();
+$result = $stmt->get_result();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $keyword=$_POST["search"]; | |
| $sqlmain= "select * from schedule inner join doctor on schedule.docid=doctor.docid where schedule.scheduledate>='$today' and (doctor.docname='$keyword' or doctor.docname like '$keyword%' or doctor.docname like '%$keyword' or doctor.docname like '%$keyword%' or schedule.title='$keyword' or schedule.title like '$keyword%' or schedule.title like '%$keyword' or schedule.title like '%$keyword%' or schedule.scheduledate like '$keyword%' or schedule.scheduledate like '%$keyword' or schedule.scheduledate like '%$keyword%' or schedule.scheduledate='$keyword' ) order by schedule.scheduledate asc"; | |
| $keyword = $_POST["search"]; | |
| $sqlmain = "SELECT * FROM schedule | |
| INNER JOIN doctor ON schedule.docid = doctor.docid | |
| WHERE schedule.scheduledate >= ? | |
| AND (doctor.docname = ? OR doctor.docname LIKE CONCAT(?,'%') | |
| OR doctor.docname LIKE CONCAT('%',?) | |
| OR doctor.docname LIKE CONCAT('%',?,'%') | |
| OR ... ) | |
| ORDER BY schedule.scheduledate ASC"; | |
| $stmt = $database->prepare($sqlmain); | |
| $likeKeyword = $keyword; | |
| $stmt->bind_param("sssss", $today, $keyword, $likeKeyword, $likeKeyword, $likeKeyword); | |
| $stmt->execute(); | |
| $result = $stmt->get_result(); |
| $stmt->bind_param("s",$useremail); | ||
| $stmt->execute(); | ||
| $userrow = $stmt->get_result(); | ||
| $userrow = $database->query("select * from patient where pemail='$useremail'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential SQL injection vulnerability.
Inserting $useremail directly into the SQL string creates a risk of SQL injection if the input is not sanitized. Use prepared statements to ensure security.
-$userrow = $database->query("select * from patient where pemail='$useremail'");
+$stmt = $database->prepare("SELECT * FROM patient WHERE pemail = ?");
+$stmt->bind_param("s", $useremail);
+$stmt->execute();
+$userrow = $stmt->get_result();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $userrow = $database->query("select * from patient where pemail='$useremail'"); | |
| $stmt = $database->prepare("SELECT * FROM patient WHERE pemail = ?"); | |
| $stmt->bind_param("s", $useremail); | |
| $stmt->execute(); | |
| $userrow = $stmt->get_result(); |
| $stmt->bind_param("s",$spe); | ||
| $stmt->execute(); | ||
| $spcil_res = $stmt->get_result(); | ||
| $spcil_res= $database->query("select sname from specialties where id='$spe'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String Interpolation of $spe
$spcil_res= $database->query("select sname from specialties where id='$spe'"); is susceptible to injection if $spe is untrusted.
Proposed fix:
- $spcil_res= $database->query("select sname from specialties where id='$spe'");
+ $stmt = $database->prepare("SELECT sname FROM specialties WHERE id = ?");
+ $stmt->bind_param("i", $spe);
+ $stmt->execute();
+ $spcil_res = $stmt->get_result();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $spcil_res= $database->query("select sname from specialties where id='$spe'"); | |
| $stmt = $database->prepare("SELECT sname FROM specialties WHERE id = ?"); | |
| $stmt->bind_param("i", $spe); | |
| $stmt->execute(); | |
| $spcil_res = $stmt->get_result(); |
| $stmt->bind_param("s",$useremail); | ||
| $stmt->execute(); | ||
| $userrow = $stmt->get_result(); | ||
| $userrow = $database->query("select * from patient where pemail='$useremail'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible SQL Injection:
Directly inserting $useremail into the query string can be exploited.
Consider prepared statements:
- $userrow = $database->query("select * from patient where pemail='$useremail'");
+ $stmt = $database->prepare("SELECT * FROM patient WHERE pemail=?");
+ $stmt->bind_param("s", $useremail);
+ $stmt->execute();
+ $userrow = $stmt->get_result();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $userrow = $database->query("select * from patient where pemail='$useremail'"); | |
| $stmt = $database->prepare("SELECT * FROM patient WHERE pemail=?"); | |
| $stmt->bind_param("s", $useremail); | |
| $stmt->execute(); | |
| $userrow = $stmt->get_result(); |
| $stmt->bind_param("i",$id); | ||
| $stmt->execute(); | ||
| $result001 = $stmt->get_result(); | ||
| $result001= $database->query("select * from patient where pid=$id;"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Severe SQL injection vulnerability
This code introduces a critical SQL injection vulnerability by directly including user input ($id from $_GET["id"]) in an SQL query without any sanitization or parameterization.
Replace with a prepared statement to protect against SQL injection:
-$result001= $database->query("select * from patient where pid=$id;");
+$sqlmain = "select * from patient where pid=?";
+$stmt = $database->prepare($sqlmain);
+$stmt->bind_param("i", $id);
+$stmt->execute();
+$result001 = $stmt->get_result();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $result001= $database->query("select * from patient where pid=$id;"); | |
| $sqlmain = "select * from patient where pid=?"; | |
| $stmt = $database->prepare($sqlmain); | |
| $stmt->bind_param("i", $id); | |
| $stmt->execute(); | |
| $result001 = $stmt->get_result(); |
| $stmt->bind_param("s",$useremail); | ||
| $stmt->execute(); | ||
| $userrow = $stmt->get_result(); | ||
| $userrow = $database->query("select * from patient where pemail='$useremail'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reintroduce prepared statements to prevent SQL injection
This change replaces a secure prepared statement with direct string interpolation in the SQL query. This introduces a significant security vulnerability known as SQL injection.
Replace this line with a prepared statement:
-$userrow = $database->query("select * from patient where pemail='$useremail'");
+$sqlmain = "select * from patient where pemail=?";
+$stmt = $database->prepare($sqlmain);
+$stmt->bind_param("s", $useremail);
+$stmt->execute();
+$userrow = $stmt->get_result();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $userrow = $database->query("select * from patient where pemail='$useremail'"); | |
| $sqlmain = "select * from patient where pemail=?"; | |
| $stmt = $database->prepare($sqlmain); | |
| $stmt->bind_param("s", $useremail); | |
| $stmt->execute(); | |
| $userrow = $stmt->get_result(); |
| $sql= $database->query("delete from webuser where email='$email';"); | ||
| $sql= $database->query("delete from patient where pemail='$email';"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use prepared statements for delete operations
These direct query executions introduce SQL injection vulnerabilities. Even though $email comes from a database query result, it's best practice to use prepared statements for all database operations.
Replace with prepared statements:
-$sql= $database->query("delete from webuser where email='$email';");
-$sql= $database->query("delete from patient where pemail='$email';");
+$sqlmain = "delete from webuser where email=?";
+$stmt = $database->prepare($sqlmain);
+$stmt->bind_param("s", $email);
+$stmt->execute();
+
+$sqlmain = "delete from patient where pemail=?";
+$stmt = $database->prepare($sqlmain);
+$stmt->bind_param("s", $email);
+$stmt->execute();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $sql= $database->query("delete from webuser where email='$email';"); | |
| $sql= $database->query("delete from patient where pemail='$email';"); | |
| $sqlmain = "delete from webuser where email=?"; | |
| $stmt = $database->prepare($sqlmain); | |
| $stmt->bind_param("s", $email); | |
| $stmt->execute(); | |
| $sqlmain = "delete from patient where pemail=?"; | |
| $stmt = $database->prepare($sqlmain); | |
| $stmt->bind_param("s", $email); | |
| $stmt->execute(); |
The database server name was suppose to be localhost, while the patients database queries was suppose to have the changes as shown below.
Summary by CodeRabbit