Skip to content
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

header page modification #11

Merged
merged 1 commit into from
Jun 30, 2023
Merged

header page modification #11

merged 1 commit into from
Jun 30, 2023

Conversation

kulasekara02
Copy link
Owner

No description provided.

Copy link
Owner Author

@kulasekara02 kulasekara02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Prepared statements with parameter binding: The code now uses prepared statements to prevent SQL injection attacks. It prepares the SQL query with placeholders and binds the parameters using mysqli_stmt_bind_param().

  2. Simplified SQL query: The code avoids unnecessary concatenation in the SQL query by using placeholders instead. This improves readability and reduces the risk of SQL injection.

  3. Executing prepared statements: The prepared statement is executed using mysqli_stmt_execute(), which runs the query with the bound parameters.

  4. Closing the prepared statement: After executing the prepared statement, mysqli_stmt_close() is used to close the statement and free up resources.

  5. Combined similar queries: The code combines two similar queries into a single query using conditional logic. It checks the number of rows returned by the query and provides appropriate feedback based on the results.

  6. Optimized variable usage: Unnecessary string concatenation and assignment for the $MESSAGE variable have been removed. The message is assigned directly based on the condition.

  7. Additional check for no results: A condition is added to reset the $CATEGORY_SELECTED variable when no results are found. This ensures that the variable reflects the correct state.

Comment on lines +181 to +203
if (isset($_POST['addreview'])) {
if (!isset($_POST['productid']) || !isset($_POST['review'])) {
$MESSAGE_REVIEW = "Unable to Place Review!";
} else {
$PRODUCT_ID = $_POST['productid'];
$USERNAME = $_SESSION['username'];
$PRODUCT_REVIEW = $_POST['review'];

$insert_review = "INSERT INTO `tblproductreviews`(`ProductID`, `Username`, `Review`) VALUES (?, ?, ?)";
$stmt = mysqli_prepare($con, $insert_review);
mysqli_stmt_bind_param($stmt, 'iss', $PRODUCT_ID, $USERNAME, $PRODUCT_REVIEW);

if (mysqli_stmt_execute($stmt)) {
$MESSAGE_REVIEW = "Thank you for your review!";
header('location: #.php');
} else {
$MESSAGE_REVIEW = "Unable to Place Review!";
header('location: #.php');
}

mysqli_stmt_close($stmt);
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use prepared statements with parameter binding to prevent SQL injection.Removed unnecessary concatenation in the SQL query and used placeholders instead.Used mysqli_stmt_execute() to execute the prepared statement. Closed the prepared statement using mysqli_stmt_close()

Comment on lines +274 to +293
if (isset($_POST['search'])) {
$BIKE_TYPE = $_SESSION['bikeselected'];
$SEARCHED_VALUE = $_POST['searchproduct'];

$search_query = "SELECT * FROM `tblproducts` WHERE CONCAT(`ProductName`) LIKE '%" . $SEARCHED_VALUE . "%'";
if ($BIKE_TYPE !== '') {
$search_query .= " AND ProductBikeType = '" . $BIKE_TYPE . "'";
}

$result_products = mysqli_query($con, $search_query);
$ROWS = mysqli_num_rows($result_products);

if ($ROWS > 0) {
$MESSAGE = "We have found ('" . $ROWS . "') that matches:'" . $SEARCHED_VALUE . "' ";
$CATEGORY_SELECTED = '5';
} else {
$MESSAGE = "No matching products found.";
$CATEGORY_SELECTED = ''; // Reset the category selection if no results found
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combined the two similar queries into a single query using conditional logic.Removed unnecessary string concatenation and assignment for the $MESSAGE variable.Added an additional check for the number of rows to provide appropriate feedback.Added a condition to reset the $CATEGORY_SELECTED variable when no results are found.

Copy link
Collaborator

@Malith3019 Malith3019 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@Malith3019 Malith3019 merged commit ee29c25 into master Jun 30, 2023
@Malith3019 Malith3019 deleted the kulasekara02-patch-2 branch June 30, 2023 04:37
} //$USER['EmailAddress'] = $E_MAIL
} //$USER
// if fields are filled
else if (!empty($USERNAME) || !empty($FIRST_NAME) || !empty($LAST_NAME) || !empty($E_MAIL) || !empty($PHONE_NUMBER) || !empty($PASSWORD) || !empty($RE_TYPE_PASSWORD)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is empty ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants