Jump to content

Search the Community

Showing results for tags 'mysqli'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. Hello Coders, wanted to know if anybody could help to validate modal form based on the query below please? Appreciate your help if possible. Thank you so much! MODAL FORM FORM <div class="modal fade" id="exampleModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="staticBackdrop" aria-hidden="true"> > <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Add user</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <i aria-hidden="true" class="ki ki-close"></i> </button> </div> <div class="modal-body"> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" class="needs-validation" novalidate id="adduser"> <div class="form-row"> <div class="form-group col-md-6 mb-3"> <label for="inputState">Select a name</label><br> <select class="form-control select2 <?php echo (!empty($fullname_err)) ? 'is-invalid' : ''; ?>" id="kt_select2_1" name="fullname" required> <option value="" selected>Select a name</option> <?php require_once('./conn/inc.php'); $sql = mysqli_query($link,"SELECT * FROM members ORDER BY fullname ASC"); while($row=mysqli_fetch_array($sql)) { $mid = $row['mid']; $fullname = $row['fullname']; echo '<option value="'.$mid.'">'.$fullname.'</option>'; } ?> </select> <span class="invalid-feedback"><?php echo $fullname_err; ?></span> </div> <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-sm-12 mb-3"> <label for="username">Username</label> <input type="text" class="form-control <?php echo (!empty($uname_err)) ? 'is-invalid' : ''; ?>" placeholder="username" name="uname" required> <span class="invalid-feedback"><?php echo $uname_err; ?></span> </div> <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-sm-12 mb-3"> <label for="showpass">Password</label> <input type="password" class="form-control <?php echo (!empty($password_err)) ? 'is-invalid' : ''; ?>" id="showpass" placeholder="Password" name="password" required> <span class="invalid-feedback"><?php echo $password_err; ?></span> </div> <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-sm-12 mb-3"> <label for="showpass2">Confirm Password</label> <input type="password" name="confirm_password" class="form-control <?php echo (!empty($confirm_password_err)) ? 'is-invalid' : ''; ?>" id="showpass2" placeholder="Confirm password" required> <span class="invalid-feedback"><?php echo $confirm_password_err; ?></span> </div> </div> </div> <div class="modal-footer"> <div class="checkbox-inline mr-2"> <label class="checkbox"> <input type="checkbox" onclick="myFunction()" class="form-check-input" id="exampleCheck1"> <span></span> Show password </label> </div> <button type="reset" class="btn btn-secondary">Clear</button> <button type="submit" class="btn btn-primary">Submit</button> </div> </form> </div> </div> </div> VALIDATION QUERY <?php // Define variables and initialize with empty values $fullname = $uname = $password = $confirm_password = ""; $fullname_err = $uname_err = $password_err = $confirm_password_err = ""; // Processing form data when form is submitted if($_SERVER["REQUEST_METHOD"] == "POST"){ // Validate username if(empty(trim($_POST["uname"]))){ $uname_err = "Please enter a username."; } elseif(!preg_match('/^[a-zA-Z0-9_]+$/', trim($_POST["uname"]))){ $uname_err = "Username can only contain letters, numbers, and underscores."; } else{ // Prepare a select statement $sql = "SELECT id FROM users WHERE uname = ?"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "s", $param_username); // Set parameters $param_username = trim($_POST["uname"]); // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ /* store result */ mysqli_stmt_store_result($stmt); if(mysqli_stmt_num_rows($stmt) == 1){ $uname_err = "This username is already taken."; } else{ $uname = trim($_POST["uname"]); } } else{ echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } // Validate username if(empty(trim($_POST["fullname"]))){ $fullname_err = "Please enter a fullname."; } else{ // Prepare a select statement $sql = "SELECT id FROM users WHERE fullname = ?"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "s", $param_fullname); // Set parameters $param_fullname = trim($_POST["fullname"]); // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ /* store result */ mysqli_stmt_store_result($stmt); if(mysqli_stmt_num_rows($stmt) == 1){ $fullname_err = "This names is already taken."; } else{ $fullname = trim($_POST["fullname"]); } } else{ echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } // Validate password if(empty(trim($_POST["password"]))){ $password_err = "Please enter a password."; } elseif(strlen(trim($_POST["password"])) < 6){ $password_err = "Password must have atleast 6 characters."; } else{ $password = trim($_POST["password"]); } // Validate confirm password if(empty(trim($_POST["confirm_password"]))){ $confirm_password_err = "Please confirm password."; } else{ $confirm_password = trim($_POST["confirm_password"]); if(empty($password_err) && ($password != $confirm_password)){ $confirm_password_err = "Password did not match."; } } // Check input errors before inserting in database if(empty($fullname_err) && empty($uname_err) && empty($password_err) && empty($confirm_password_err)){ $fullname = mysqli_real_escape_string($link, $_REQUEST['fullname']); $uname = mysqli_real_escape_string($link, $_REQUEST['uname']); // Prepare an insert statement $sql = "INSERT INTO users (fullname, uname, password) VALUES (?, ?, ?)"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "sss", $param_fullname, $param_username, $param_password); // Set parameters $param_fullname = $fullname; $param_username = $uname; $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ // Redirect to login page header("location: users.php"); $_SESSION['status'] = "Record Successfuly Saved!"; } else{ echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } // Close connection // mysqli_close($link); } ?> I have put javascript to validate form before submitting and this only works on client side ; It won't fetch data from database to compare. <script> // Example starter JavaScript for disabling form submissions if there are invalid fields (function() { 'use strict'; window.addEventListener('load', function() { // Fetch all the forms we want to apply custom Bootstrap validation styles to var forms = document.getElementsByClassName('needs-validation'); // Loop over them and prevent submission var validation = Array.prototype.filter.call(forms, function(form) { form.addEventListener('submit', function(event) { if (form.checkValidity() === false) { event.preventDefault(); event.stopPropagation(); } form.classList.add('was-validated'); }, false); }); }, false); })(); </script>
  2. Hello Coding Masters, Thank you for reading my post. I need your help if if it's possible that Database table value will automatically update the value when time expires? Sample, If now time is is between ENTRYTime and CLOSE Time, table value will automatically update if time set expires? Enabled value is = 0 on my table Disabled value is = 0 on my table. But I have someone close to me suggested if its possible to set these automatically? Thank you so much for your feedback.
  3. Hello There, Anyone wants to help me how to achive this thing on PHP? I have zero knowledge on Pibot table for PHP Mysqli and minimal knowledge on programming. Here's the link for output And below is the Table Attendance: -- phpMyAdmin SQL Dump -- version 5.2.0 -- https://www.phpmyadmin.net/ -- -- Host: 127.0.0.1 -- Generation Time: Jun 01, 2022 at 10:29 AM -- Server version: 10.4.24-MariaDB -- PHP Version: 8.1.6 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `mcgibn` -- -- -------------------------------------------------------- -- -- Table structure for table `attendance` -- CREATE TABLE `attendance` ( `atid` int(11) NOT NULL, `memid` int(11) NOT NULL, `serid` int(11) NOT NULL, `calid` int(11) NOT NULL, `entrydate` timestamp NOT NULL DEFAULT current_timestamp(), `month` varchar(30) CHARACTER SET latin1 NOT NULL, `year` varchar(5) DEFAULT NULL, `createdat` timestamp NOT NULL DEFAULT current_timestamp(), `updatedat` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), `viewfrom` int(11) NOT NULL, `astatus` int(11) NOT NULL, `stype` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- -- Dumping data for table `attendance` -- INSERT INTO `attendance` (`atid`, `memid`, `serid`, `calid`, `entrydate`, `month`, `year`, `createdat`, `updatedat`, `viewfrom`, `astatus`, `stype`) VALUES (32, 37, 1, 1, '2022-05-31 12:55:28', 'May', '2022', '2022-05-31 12:55:28', '2022-05-31 12:55:28', 0, 1, 2), (33, 37, 2, 1, '2022-05-31 12:55:36', 'May', '2022', '2022-05-31 12:55:36', '2022-05-31 12:55:36', 0, 1, 1), (34, 37, 3, 1, '2022-05-31 12:55:43', 'May', '2022', '2022-05-31 12:55:43', '2022-06-01 03:28:55', 0, 1, 1), (35, 37, 1, 0, '2022-05-31 12:56:15', 'Jun', '2022', '2022-05-31 12:56:15', '2022-06-01 01:17:35', 0, 1, 2), (36, 37, 2, 1, '2022-05-31 12:56:25', 'Jun', '2022', '2022-05-31 12:56:25', '2022-06-01 01:17:35', 0, 1, 1), (37, 37, 3, 1, '2022-05-31 12:56:40', 'Jun', '2022', '2022-05-31 12:56:40', '2022-06-01 01:17:35', 0, 1, 1), (38, 37, 1, 1, '2022-05-31 12:57:24', 'May', '2023', '2022-05-31 12:57:24', '2022-05-31 12:57:24', 0, 1, 2), (39, 37, 2, 1, '2022-05-31 12:57:37', 'May', '2023', '2022-05-31 12:57:37', '2022-05-31 12:57:37', 0, 1, 1), (40, 37, 3, 1, '2022-05-31 12:57:46', 'May', '2023', '2022-05-31 12:57:46', '2022-05-31 12:57:46', 0, 1, 1), (41, 37, 1, 1, '2022-05-31 12:57:57', 'Jun', '2023', '2022-05-31 12:57:57', '2022-06-01 01:17:35', 0, 1, 2), (42, 37, 2, 1, '2022-05-31 12:58:08', 'Jun', '2023', '2022-05-31 12:58:08', '2022-06-01 01:17:35', 0, 1, 1), (43, 37, 3, 1, '2022-05-31 12:58:18', 'Jun', '2023', '2022-05-31 12:58:18', '2022-06-01 01:12:40', 0, 1, 1), (44, 49, 1, 1, '2022-05-31 12:58:32', 'May', '2022', '2022-05-31 12:58:32', '2022-05-31 12:58:32', 0, 1, 2), (45, 49, 2, 1, '2022-05-31 12:58:40', 'May', '2022', '2022-05-31 12:58:40', '2022-05-31 12:58:40', 0, 1, 1), (47, 49, 1, 1, '2022-05-31 12:59:01', 'Jun', '2022', '2022-05-31 12:59:01', '0000-00-00 00:00:00', 0, 1, 2), (48, 49, 2, 1, '2022-05-31 12:59:14', 'Jun', '2022', '2022-05-31 12:59:14', '2022-06-01 01:12:40', 0, 1, 1), (49, 49, 3, 1, '2022-05-31 12:59:31', 'Jun', '2022', '2022-05-31 12:59:31', '2022-06-01 01:12:40', 0, 1, 1), (50, 49, 1, 1, '2022-05-31 12:59:41', 'May', '2023', '2022-05-31 12:59:41', '2022-05-31 12:59:41', 0, 1, 2), (51, 49, 2, 1, '2022-05-31 12:59:49', 'May', '2023', '2022-05-31 12:59:49', '2022-05-31 12:59:49', 0, 1, 1), (52, 49, 3, 1, '2022-05-31 13:00:05', 'May', '2023', '2022-05-31 13:00:05', '2022-05-31 13:00:05', 0, 1, 1), (53, 49, 1, 1, '2022-05-31 13:00:21', 'Jun', '2023', '2022-05-31 13:00:21', '2022-06-01 01:12:40', 0, 1, 2), (54, 49, 2, 1, '2022-05-31 13:00:32', 'Jun', '2023', '2022-05-31 13:00:32', '2022-06-01 01:12:40', 0, 1, 1), (55, 49, 3, 1, '2022-05-31 13:00:43', 'Jun', '2023', '2022-05-31 13:00:43', '2022-06-01 01:12:40', 0, 1, 1), (56, 88, 1, 1, '2022-05-31 13:01:25', 'May', '2022', '2022-05-31 13:01:25', '2022-05-31 13:01:25', 0, 1, 2), (57, 88, 2, 1, '2022-05-31 13:01:30', 'May', '2022', '2022-05-31 13:01:30', '2022-05-31 13:01:30', 0, 1, 1), (58, 88, 3, 1, '2022-05-31 13:01:37', 'May', '2022', '2022-05-31 13:01:37', '2022-05-31 13:01:37', 0, 1, 1), (59, 88, 1, 1, '2022-05-31 13:01:45', 'Jun', '2022', '2022-05-31 13:01:45', '2022-06-01 01:27:00', 0, 1, 2), (60, 88, 2, 1, '2022-05-31 13:01:52', 'Jun', '2022', '2022-05-31 13:01:52', '2022-06-01 01:12:40', 0, 1, 1), (62, 88, 1, 1, '2022-05-31 13:02:37', 'Jun', '2023', '2022-05-31 13:02:37', '2022-06-01 01:27:07', 0, 1, 2), (63, 88, 2, 1, '2022-05-31 13:02:54', 'Jun', '2023', '2022-05-31 13:02:54', '2022-06-01 01:12:40', 0, 1, 1), (64, 88, 3, 1, '2022-05-31 13:03:04', 'Jun', '2023', '2022-05-31 13:03:04', '2022-06-01 01:27:10', 0, 1, 1), (65, 88, 1, 1, '2022-05-31 13:03:14', 'May', '2023', '2022-05-31 13:03:14', '2022-05-31 13:03:14', 0, 1, 2), (66, 88, 2, 1, '2022-05-31 13:03:22', 'May', '2023', '2022-05-31 13:03:22', '2022-05-31 13:03:22', 0, 1, 1), (67, 88, 3, 1, '2022-05-31 13:03:31', 'May', '2023', '2022-05-31 13:03:31', '2022-05-31 13:03:31', 0, 1, 1), (68, 89, 1, 1, '2022-05-31 13:04:21', 'May', '2022', '2022-05-31 13:04:21', '2022-05-31 13:04:21', 0, 1, 2), (69, 89, 2, 1, '2022-05-31 13:04:34', 'May', '2022', '2022-05-31 13:04:34', '2022-05-31 13:04:34', 0, 1, 1), (70, 89, 3, 1, '2022-05-31 13:04:40', 'May', '2022', '2022-05-31 13:04:40', '2022-05-31 13:04:40', 0, 1, 1), (71, 89, 1, 1, '2022-05-31 13:04:49', 'Jun', '2022', '2022-05-31 13:04:49', '2022-06-01 01:12:40', 0, 1, 2), (72, 89, 2, 1, '2022-05-31 13:04:56', 'Jun', '2022', '2022-05-31 13:04:56', '2022-06-01 01:12:40', 0, 1, 1), (73, 89, 3, 1, '2022-05-31 13:05:14', 'Jun', '2022', '2022-05-31 13:05:14', '2022-06-01 01:10:41', 0, 1, 1), (74, 89, 1, 1, '2022-05-31 13:05:24', 'May', '2023', '2022-05-31 13:05:24', '2022-05-31 13:05:24', 0, 1, 2), (75, 89, 2, 1, '2022-05-31 13:05:31', 'May', '2023', '2022-05-31 13:05:31', '2022-05-31 13:05:31', 0, 1, 1), (76, 89, 3, 1, '2022-05-31 13:05:41', 'May', '2023', '2022-05-31 13:05:41', '2022-05-31 13:05:41', 0, 1, 1), (77, 89, 1, 1, '2022-05-31 13:05:51', 'Jun', '2023', '2022-05-31 13:05:51', '2022-06-01 01:12:40', 0, 1, 2), (78, 89, 2, 1, '2022-05-31 13:05:59', 'Jun', '2023', '2022-05-31 13:05:59', '0000-00-00 00:00:00', 0, 1, 1), (79, 89, 3, 1, '2022-05-31 13:06:09', 'Jun', '2023', '2022-05-31 13:06:09', '2022-06-01 01:27:12', 0, 1, 1), (80, 84, 1, 1, '2022-05-31 13:07:19', 'May', '2022', '2022-05-31 13:07:19', '2022-06-01 03:40:25', 0, 1, 2), (81, 84, 2, 1, '2022-05-31 13:07:24', 'May', '2022', '2022-05-31 13:07:24', '2022-05-31 13:07:24', 0, 1, 1), (82, 84, 3, 1, '2022-05-31 13:07:31', 'May', '2022', '2022-05-31 13:07:31', '2022-06-01 03:42:52', 0, 1, 1), (83, 84, 1, 1, '2022-05-31 13:07:38', 'Jun', '2022', '2022-05-31 13:07:38', '2022-06-01 01:12:40', 0, 1, 2), (84, 84, 2, 1, '2022-05-31 13:07:45', 'Jun', '2022', '2022-05-31 13:07:45', '2022-06-01 01:27:14', 0, 1, 1), (85, 84, 3, 1, '2022-05-31 13:07:53', 'Jun', '2022', '2022-05-31 13:07:53', '2022-06-01 01:27:16', 0, 1, 1), (86, 84, 1, 1, '2022-05-31 13:08:12', 'May', '2023', '2022-05-31 13:08:12', '2022-05-31 13:08:12', 0, 1, 2), (87, 84, 2, 1, '2022-05-31 13:08:23', 'May', '2023', '2022-05-31 13:08:23', '2022-05-31 13:08:23', 0, 1, 1), (88, 84, 3, 1, '2022-05-31 13:08:30', 'May', '2023', '2022-05-31 13:08:30', '2022-05-31 13:08:30', 0, 1, 1), (89, 84, 1, 1, '2022-05-31 13:08:44', 'Jun', '2023', '2022-05-31 13:08:44', '2022-06-01 01:27:20', 0, 1, 2), (90, 84, 2, 1, '2022-05-31 13:08:58', 'Jun', '2023', '2022-05-31 13:08:58', '2022-06-01 01:27:22', 0, 1, 1), (91, 84, 3, 1, '2022-05-31 13:09:06', 'Jun', '2023', '2022-05-31 13:09:06', '2022-06-01 01:27:26', 0, 1, 1), (92, 121, 1, 1, '2022-05-31 13:09:59', 'May', '2022', '2022-05-31 13:09:59', '2022-05-31 13:09:59', 0, 1, 2), (93, 121, 2, 1, '2022-05-31 13:10:06', 'May', '2022', '2022-05-31 13:10:06', '2022-05-31 13:10:06', 0, 1, 1), (94, 121, 3, 1, '2022-05-31 13:10:13', 'May', '2022', '2022-05-31 13:10:13', '2022-05-31 13:10:13', 0, 1, 1), (95, 121, 1, 1, '2022-05-31 13:10:20', 'Jun', '2022', '2022-05-31 13:10:20', '2022-06-01 01:27:27', 0, 1, 2), (96, 121, 2, 1, '2022-05-31 13:10:29', 'Jun', '2022', '2022-05-31 13:10:29', '2022-06-01 01:27:29', 0, 1, 1), (97, 121, 3, 1, '2022-05-31 13:10:38', 'Jun', '2022', '2022-05-31 13:10:38', '2022-06-01 01:27:30', 0, 1, 1), (98, 121, 1, 1, '2022-05-31 13:10:50', 'May', '2023', '2022-05-31 13:10:50', '2022-05-31 13:10:50', 0, 1, 2), (99, 121, 2, 1, '2022-05-31 13:10:57', 'May', '2023', '2022-05-31 13:10:57', '2022-05-31 13:10:57', 0, 1, 1), (100, 121, 3, 1, '2022-05-31 13:11:11', 'May', '2023', '2022-05-31 13:11:11', '2022-05-31 13:11:11', 0, 1, 1), (101, 107, 1, 1, '2022-05-31 13:11:34', 'May', '2022', '2022-05-31 13:11:34', '2022-05-31 13:11:34', 0, 1, 2), (102, 107, 2, 1, '2022-05-31 13:11:39', 'May', '2022', '2022-05-31 13:11:39', '2022-05-31 13:11:39', 0, 1, 1), (103, 107, 3, 1, '2022-05-31 13:11:44', 'May', '2022', '2022-05-31 13:11:44', '2022-05-31 13:11:44', 0, 1, 1), (104, 107, 1, 1, '2022-05-31 13:11:51', 'Jun', '2022', '2022-05-31 13:11:51', '2022-06-01 01:10:41', 0, 1, 2), (105, 107, 2, 1, '2022-05-31 13:12:05', 'Jun', '2022', '2022-05-31 13:12:05', '2022-06-01 01:27:32', 0, 1, 1), (106, 107, 3, 1, '2022-05-31 13:12:14', 'Jun', '2022', '2022-05-31 13:12:14', '2022-06-01 07:57:46', 0, 1, 1), (107, 107, 1, 1, '2022-05-31 13:12:28', 'May', '2023', '2022-05-31 13:12:28', '2022-05-31 13:12:28', 0, 1, 2), (108, 107, 2, 1, '2022-05-31 13:12:37', 'May', '2023', '2022-05-31 13:12:37', '2022-05-31 13:12:37', 0, 1, 1), (109, 107, 3, 1, '2022-05-31 13:12:45', 'May', '2023', '2022-05-31 13:12:45', '2022-05-31 13:12:45', 0, 1, 1), (110, 107, 1, 1, '2022-05-31 13:12:56', 'Jun', '2023', '2022-05-31 13:12:56', '2022-06-01 01:27:36', 0, 1, 2), (111, 107, 2, 1, '2022-05-31 13:13:05', 'Jun', '2023', '2022-05-31 13:13:05', '2022-06-01 01:27:38', 0, 1, 1), (112, 107, 3, 1, '2022-05-31 13:17:28', 'Jun', '2023', '2022-05-31 13:17:28', '2022-06-01 01:27:40', 0, 1, 1), (113, 113, 1, 1, '2022-05-31 13:18:57', 'May', '2022', '2022-05-31 13:18:57', '2022-05-31 13:18:57', 0, 1, 1), (114, 113, 2, 1, '2022-05-31 13:19:04', 'May', '2022', '2022-05-31 13:19:04', '2022-05-31 13:19:04', 0, 1, 1), (115, 113, 3, 1, '2022-05-31 13:19:10', 'May', '2022', '2022-05-31 13:19:10', '2022-05-31 13:19:10', 0, 1, 1), (116, 113, 1, 1, '2022-05-31 13:19:18', 'Jun', '2022', '2022-05-31 13:19:18', '2022-06-01 01:10:41', 0, 1, 1), (117, 113, 2, 1, '2022-05-31 13:19:24', 'Jun', '2022', '2022-05-31 13:19:24', '2022-06-01 01:27:41', 0, 1, 1), (118, 113, 3, 1, '2022-05-31 13:19:31', 'Jun', '2022', '2022-05-31 13:19:31', '2022-06-01 07:57:43', 0, 1, 1), (119, 113, 1, 1, '2022-05-31 13:19:41', 'May', '2023', '2022-05-31 13:19:41', '2022-05-31 13:19:41', 0, 1, 1), (120, 113, 2, 1, '2022-05-31 13:19:48', 'May', '2023', '2022-05-31 13:19:48', '2022-05-31 13:19:48', 0, 1, 1), (121, 113, 3, 1, '2022-05-31 13:19:54', 'May', '2023', '2022-05-31 13:19:54', '2022-05-31 13:19:54', 0, 1, 1), (122, 113, 1, 1, '2022-05-31 13:20:04', 'Jun', '2023', '2022-05-31 13:20:04', '2022-06-01 01:27:45', 0, 1, 1), (123, 113, 2, 1, '2022-05-31 13:20:13', 'Jun', '2023', '2022-05-31 13:20:13', '2022-06-01 01:27:49', 0, 1, 1), (124, 113, 3, 1, '2022-05-31 13:20:22', 'Jun', '2023', '2022-05-31 13:20:22', '2022-06-01 01:27:53', 0, 1, 1), (125, 119, 1, 1, '2022-05-31 13:21:12', 'May', '2022', '2022-05-31 13:21:12', '2022-05-31 13:21:12', 0, 1, 1), (126, 119, 2, 1, '2022-05-31 13:21:18', 'May', '2022', '2022-05-31 13:21:18', '2022-05-31 13:21:18', 0, 1, 1), (127, 119, 3, 1, '2022-05-31 13:21:29', 'May', '2022', '2022-05-31 13:21:29', '2022-05-31 13:21:29', 0, 1, 1), (128, 119, 1, 1, '2022-05-31 13:21:45', 'Jun', '2022', '2022-05-31 13:21:45', '2022-06-01 01:27:54', 0, 1, 1), (129, 119, 2, 1, '2022-05-31 13:21:53', 'Jun', '2022', '2022-05-31 13:21:53', '2022-06-01 01:27:56', 0, 1, 1), (130, 119, 3, 1, '2022-05-31 13:22:16', 'Jun', '2022', '2022-05-31 13:22:16', '2022-06-01 01:28:00', 0, 1, 1), (131, 119, 1, 1, '2022-05-31 13:22:24', 'May', '2023', '2022-05-31 13:22:24', '2022-05-31 13:22:24', 0, 1, 1), (132, 119, 2, 1, '2022-05-31 13:22:30', 'May', '2023', '2022-05-31 13:22:30', '2022-05-31 13:22:30', 0, 1, 1), (133, 119, 3, 1, '2022-05-31 13:22:36', 'May', '2023', '2022-05-31 13:22:36', '2022-05-31 13:22:36', 0, 1, 1), (134, 119, 1, 1, '2022-05-31 13:22:45', 'Jun', '2023', '2022-05-31 13:22:45', '2022-06-01 01:28:03', 0, 1, 1), (135, 119, 2, 1, '2022-05-31 13:22:53', 'Jun', '2023', '2022-05-31 13:22:53', '2022-06-01 01:28:04', 0, 1, 1), (136, 119, 3, 1, '2022-05-31 13:23:10', 'Jun', '2023', '2022-05-31 13:23:10', '2022-06-01 01:28:08', 0, 1, 1), (137, 13, 1, 1, '2022-05-31 13:40:26', 'May', '2022', '2022-05-31 13:40:26', '2022-05-31 13:40:26', 0, 1, 1), (138, 13, 2, 1, '2022-05-31 13:40:31', 'May', '2022', '2022-05-31 13:40:31', '2022-05-31 13:40:31', 0, 1, 1), (139, 13, 3, 1, '2022-05-31 13:40:36', 'May', '2022', '2022-05-31 13:40:36', '2022-05-31 13:40:36', 0, 1, 1), (140, 13, 1, 1, '2022-05-31 13:40:42', 'Jun', '2022', '2022-05-31 13:40:42', '2022-06-01 01:28:10', 0, 1, 1), (141, 13, 2, 1, '2022-05-31 13:40:53', 'Jun', '2022', '2022-05-31 13:40:53', '2022-06-01 01:28:11', 0, 1, 1), (142, 13, 3, 1, '2022-05-31 13:41:11', 'Jun', '2022', '2022-05-31 13:41:11', '2022-06-01 03:41:46', 0, 1, 1); -- -- Indexes for dumped tables -- -- -- Indexes for table `attendance` -- ALTER TABLE `attendance` ADD PRIMARY KEY (`atid`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `attendance` -- ALTER TABLE `attendance` MODIFY `atid` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=143; COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; I followed this code below and it has different results and can't really do it myself, <?php if(isset($_POST['search'])) { $search = $_POST['search'] ?? ''; $year = $_POST['year'] ?? ''; $month = $_POST['month'] ?? ''; $sql = "SELECT DISTINCT entrydate FROM attendance ORDER BY entrydate "; $res = $link->query($sql); // mysqli query while ($row = $res->fetch_row()) { $dates[] = $row[0]; } /*********************************** * Table headings * ************************************/ $emptyRow = array_fill_keys($dates,''); // format dates foreach ($dates as $k=>$v) { $dates[$k] = date('d-M', strtotime($v)); } $heads = "<table class='table table-stripped table-bordered'>\n"; $heads .= "<tr><th>Name</th><th>" . join('</th><th>', $dates) . "</th></tr>\n"; /*********************************** * Main data * ************************************/ $sql = "SELECT entrydate, memid, astatus FROM attendance ORDER BY memid"; $res = $link->query($sql); $curname=''; $tdata = ''; while (list($d, $sn, $s) = $res->fetch_row()) { if ($curname != $sn) { if ($curname) { $tdata .= "<tr><td>$curname</td><td>" . join('</td><td>', $rowdata). "</td></tr>\n"; } $rowdata = $emptyRow; $curname = $sn; } $rowdata[$d] = $s; } $tdata .= "<tr><td>$curname</td><td>" . join('</td><td>', $rowdata). "</td></tr>\n"; $tdata .= "</table\n"; } ?> <?php echo $heads; echo $tdata; ?> Notes: memid = Member name serid = Services like (PM, PBB, WS) calid = 1st Week, 2nd Week and so-on. entrydate = TimeIn date. Hoping that there are someone who's able to help a newbie like me. Thank you and appreciate that.
  4. i want to embed Bann Script or user deactive or active <?php session_start(); $message=""; ?> <?php include "db.php"; $msg=''; if(isset($_POST['sb'])) { $time=time()-30; $ip_address=getIpAddr(); $name = mysqli_real_escape_string($a, $_POST['eml']); $pass = mysqli_real_escape_string($a, $_POST['pass']); $query=mysqli_query($a,"select count(*) as total_count from loginlogs where TryTime > $time and IpAddress='$ip_address'"); $check_login_row=mysqli_fetch_assoc($query); $total_count=$check_login_row['total_count']; //Checking if the attempt 3, or youcan set the no of attempt her. For now we taking only 3 fail attempted if($total_count==3){ $msg="To many failed login attempts. Please login after 30 sec"; }else{ //Getting Post Values $result=mysqli_query($a,"SELECT * FROM admin WHERE eml='$name' and pass= '$pass'"); $row = mysqli_fetch_assoc($result); $row=mysqli_num_rows($result); //ban user if($row==1) { $_SESSION['user_name'] =$name; header("location:wel.php?msg=Scuessfull eml"); mysqli_query($a,"delete from loginlogs where IpAddress='$ip_address'"); } else{ $total_count++; $rem_attm=4-$total_count; if($rem_attm==0){ $msg="To many failed login attempts. Please login after 40 sec"; }else{ $msg="<b>Please enter valid login details.<br/>$rem_attm attempts remaining <b>"; } $try_time=time(); mysqli_query($a,"insert into loginlogs(IpAddress,TryTime) values('$ip_address','$try_time')"); } }} if(isset($_SESSION['user_name']) ){ header("location:wel.php?msg=Scuessfull "); ?> <?php } ?> <form class="login-form" action="adminscure.php" method="post" > <div class="message"><?php if($message!="") { echo $message; } ?></div> <body id="LoginForm"> <div class="container"> <div class="main-div"> <div class="panel"> <h2>Admin Login</h2> <p>Please enter your email and passwords</p> </div> <form id="Login"> <div class="form-group"> <input type="name" name="eml" class="form-control" id="eml" placeholder="name"> </div> <div class="form-group"> <input type="password" name="pass" class="form-control" id="pass" placeholder="Password"> </div> <div> <input type="submit" name="sb" class="btn btn-primary"> <div id="result"><?php echo $msg?></div> </div> </form> <?php function getIpAddr(){ if (!empty($_SERVER['HTTP_CLIENT_IP'])){ $ipAddr=$_SERVER['HTTP_CLIENT_IP']; }elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $ipAddr=$_SERVER['HTTP_X_FORWARDED_FOR']; }else{ $ipAddr=$_SERVER['REMOTE_ADDR']; } return $ipAddr; }?>
  5. I am trying to help a friend with his football pool system. First an image and then the explanation: The numbers table holds random numbers, 10 under NFC and 10 under AFC. The numbers are generated after all 100 squares are filled in the squares table and are applied to the squares table as shown in the middle image. The Matrix table is for the 100 squares holding the square number, buyer name and the numbers matrix that I am trying to build. As you can see the NFC numbers are applied to all 100 squares repeating every 10 rows. The AFC numbers are the crux of the matter here. For every 10 rows the AFC number is the same and then advances to the next AFC number. I've never tried to explain anything like this before and I hope it makes sense. I'm trying to figure out how to construct the arrays(array) needed to insert these numbers into the matrix table for later processing to determine the winners.
  6. Hi all, I am trying to get data from MySQL to display in a html table in TCPDF but it is only displaying the ID. $accom = '<h3>Accommodation:</h3> <table cellpadding="1" cellspacing="1" border="1" style="text-align:center;"> <tr> <th><strong>Organisation</strong></th> <th><strong>Contact</strong></th> <th><strong>Phone</strong></th> </tr> <tbody> <tr>'. $id = $_GET['id']; $location = $row['location']; $sql = "SELECT * FROM tours WHERE id = $id"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { '<td>'.$location.'</td> <td>David</td> <td>0412345678</td> </tbody>'; } } '</tr> </table>'; Anyone got any ideas?
  7. Hi guys, I really hope this will make sense. I am creating a dynamic field on a button click for Pickup Location. That works fine and submitting the form to the database works fine. However, instead of one entry, each time I submit the form with multiple Pickup Locations, it creates multiple separate database entries. Here is the PHP for submitting: if(isset($_POST['new']) && $_POST['new']==1){ $pickups = ''; foreach($_POST['pickups'] as $cnt => $pickups) $pickups .= ',' .$pickups; $locations = count($_POST["pickups"]); if ($locations > 0) { for ($i=0; $i < $locations; $i++) { if (trim($_POST['pickups'] != '')) { $name = mysqli_real_escape_string($con, $_POST['name']); $price = mysqli_real_escape_string($con, $_POST['price']); //$origin = $_POST['origin']; $pickups = $_POST["pickups"][$i]; $destination = mysqli_real_escape_string($con, $_POST['destination']); $dep_date = mysqli_real_escape_string($con, $_POST['dep_date']); $ret_date = mysqli_real_escape_string($con, $_POST['ret_date']); $fleet_number = mysqli_real_escape_string($con, $_POST['fleet_number']); $driver = mysqli_real_escape_string($con, $_POST['driver']); $itinerary = mysqli_real_escape_string($con, $_POST['itinerary']); $submittedby = mysqli_real_escape_string($con, $_SESSION["username"]); $trn_date = mysqli_real_escape_string($con, date("Y-m-d H:i:s")); $query="insert into tours (`name`, `price`, `pickups`, `destination`, `dep_date`, `ret_date`, `fleet_number`, `driver`, `itinerary`, `submittedby`, `trn_date`)values ('$name', '$price', '$pickups', '$destination', '$dep_date', '$ret_date', '$fleet_number', '$driver', '$itinerary', '$submittedby', '$trn_date')"; mysqli_query($con,$query) or die(mysqli_error($con)); if(mysqli_affected_rows($con)== 1 ){ $message = '<i class="fa fa-check"></i> - Record Inserted Successfully'; } } } } } Here is the HTML form: <form role="form" method="post" name="add_tour" id="add_tour" action""> <input type="hidden" name="new" value="1" /> <div class="modal-body"> <div class="row form-group"> <div class="col-6"> <div class="form-group"><label for="name" class=" form-control-label">Name</label><input type="text" id="name" name="name" placeholder="Tour Name" class="form-control"> </div> </div> <div class="col-6"> <div class="form-group"><label for="price" class=" form-control-label">Price</label><input type="text" id="price" name="price" placeholder="0.00" class="form-control"> </div> </div> </div> <div class="row form-group"> <div class="col-6"> <div class="form-group origin" id="pickupsfield"><label for="pickups" class=" form-control-label">Pickup Location</label><input type="text" id="pickups" name="pickups[]" placeholder="Start Typing..." class="form-control"></div> <button type="button" class="btn btn-success add-field" id="add" name="add">Add New Location &nbsp; <span style="font-size:16px; font-weight:bold;">+ </span> </button> </div> <div class="col-6"> <div class="form-group"><label for="destination" class=" form-control-label">Destination</label><input type="text" id="destination" name="destination" placeholder="Start Typing..." class="form-control"></div> </div> </div> <div class="row form-group"> <div class="col-6"> <div class="form-group"><label for="dep_date" class=" form-control-label">Departure Date</label><input type="date" id="dep_date" name="dep_date" placeholder="" class="form-control"></div> </div> <div class="col-6"> <div class="form-group"><label for="ret_date" class=" form-control-label">Return Date</label><input type="date" id="ret_date" name="ret_date" placeholder="" class="form-control"></div> </div> </div> <div class="row form-group"> <div class="col-6"> <div class="form-group"><label for="fleet_number" class=" form-control-label">Fleet Number</label> <select class="form-control" id="fleet_number" name="fleet_number"> <option value="Select">== Select Fleet Number ==</option> <?php $sql = "SELECT fleet_number FROM fleet"; $result = $con->query($sql); while(list($fleet_number) = mysqli_fetch_row($result)){ $option = '<option value="'.$fleet_number.'">'.$fleet_number.'</option>'; echo ($option); } ?> </select> </div> </div> <div class="col-6"> <?php ?> <div class="form-group"><label for="driver" class=" form-control-label">Driver</label> <select class="form-control" id="driver" name="driver"> <option value="Select">== Select Driver ==</option> <?php $sql = "SELECT name FROM drivers"; $result = $con->query($sql); while(list($driver) = mysqli_fetch_row($result)){ $option = '<option value="'.$driver.'">'.$driver.'</option>'; echo ($option); } ?> </select> </div> </div> </div> <div class="form-group"><label for="itinerary" class=" form-control-label">Itinerary</label> <textarea class="form-control" id="itinerary" name="itinerary"></textarea> </div> <div class="modal-footer"> <button type="reset" class="btn btn-warning">Clear Form</button> <button type="submit" name="submit" id="submit" class="btn btn-primary">Confirm</button> </div> </form> And the Javascript for adding the new fields: <script> $(document).ready(function(){ var i = 1; $("#add").click(function(){ i++; $('#pickupsfield').append('<div id="row'+i+'"><input type="text" name="pickups[]" placeholder="Enter pickup" class="form-control"/></div><div><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></div>'); }); $(document).on('click', '.btn_remove', function(){ var button_id = $(this).attr("id"); $('#row'+button_id+'').remove(); }); $("#submit").on('click',function(){ var formdata = $("#add_tour").serialize(); $.ajax({ url :"", type :"POST", data :formdata, cache :false, success:function(result){ alert(result); $("#add_tour")[0].reset(); } }); }); }); </script> Anyone have any idea where I am going wrong? Before you say it, Yes, I know, Use Prepared statements 😷
  8. Hi all, Hope to find you all good. I have the following, which creates a php file. This works fine and without error. However, once created, the content of the page, which is got from the Database, is not showing. <?php include_once('includes/header.php'); if(isset($_POST['new']) && $_POST['new']==1){ if(isset($_POST['submit'])){ $trn_date = mysqli_real_escape_string($con, date("Y-m-d H:i:s")); $name = mysqli_real_escape_string($con, $_POST['name']); $description = mysqli_real_escape_string($con, $_POST['description']); $body = mysqli_real_escape_string($con, $_POST['body']); $submittedby = mysqli_real_escape_string($con, $_SESSION["username"]); $sql = "SELECT * FROM pages WHERE name='$name'"; $res = mysqli_query($con, $sql); if (mysqli_num_rows($res) > 0) { $message = '<i class="fa fa-times text-danger"> - A Page already exists with that name!</i>'; }else{ $ins_query="insert into pages (`trn_date`,`name`,`description`, `body`, `submittedby`)values ('$trn_date','$name','$description', '$body', '$submittedby')"; mysqli_query($con,$ins_query) or die(mysqli_error($con)); if(mysqli_affected_rows($con)== 1 ){ // Name of the template file. $template_file = 'template.php'; // Root folder if working in subdirectory. Name is up to you ut must match with server's folder. $base_path = '/protour/'; // Path to the directory where you store the "template.php" file. $template_path = 'includes/'; // Path to the directory where php will store the auto-generated couple's pages. $page_path = '../'; // Posted data. $row['name'] = str_replace(' ', '', $_POST['name']); $row['description'] = str_replace(' ', '', $_POST['description']); $row['body'] = $_POST['body']; // Data array (Should match with data above's order). $placeholders = array('{name}', '{description}', '{body}'); // Get the template.php as a string. $template = file_get_contents($template_path.$template_file); // Fills the template. $new_file = str_replace($placeholders, $row, $template); // Generates couple's URL and makes it frendly and lowercase. $page_url = str_replace(' ', '', strtolower($row['name'].'.php')); // Save file into page directory. $fp = fopen($page_path.$page_url, 'w'); fwrite($fp, $new_file); fclose($fp); // Set the variables to pass them to success page. $_SESSION['page_url'] = $page_url; // If working in root directory. $_SESSION['page_path'] = str_replace('.', '', $page_path); // If working in a sub directory. $_SESSION['page_path'] = substr_replace($base_path, '', -1).str_replace('.', '',$page_path); $message = '<i class="fa fa-check"></i> - Page Created Successfully'; } } } } ?> <!-- Header--> <div class="breadcrumbs"> <div class="col-sm-4"> <div class="page-header float-left"> <div class="page-title"> <h1>Pages</h1> </div> </div> </div> <div class="col-sm-8"> </div> </div> <div class="content mt-3"> <div class="animated fadeIn"> <div class="row"> <div class="col-lg-12"> <div class="card"> <div class="card-header"><strong>Add </strong><small>Page <?php if($message = isset($message) ? $message : ''){ printf($message); } ?></small></div> <div class="card-body card-block"> <form role="form" method="post" action""> <input type="hidden" name="new" value="1" /> <div class="modal-body"> <div class="form-group"><label for="name" class=" form-control-label">Page Name</label><input type="text" id="name" name="name" placeholder="name" class="form-control"> </div> <div class="form-group"><label for="description" class=" form-control-label">Description</label><input maxlength="100" type="text" id="description" name="description" placeholder="descriptioon" class="form-control"></div> <div class="form-group"><label for="body" class=" form-control-label">Body</label> <textarea class="form-control" id="body" name="body" placeholder="body"></textarea> </div> <div class="modal-footer"> <button type="submit" name="submit" id="submit" class="btn btn-primary">Confirm</button> </div> </form> </div> </div> </div><!-- .animated --> </div><!-- .content --> </div><!-- /#right-panel --> <!-- Right Panel --> <script src="assets/js/vendor/jquery-2.1.4.min.js"></script> <script src="assets/js/popper.min.js"></script> <script src="assets/js/plugins.js"></script> <script src="assets/js/main.js"></script> <script src="assets/js/bing.js"></script> <script src="assets/js/lib/data-table/datatables.min.js"></script> <script src="assets/js/lib/data-table/dataTables.bootstrap.min.js"></script> <script src="assets/js/lib/data-table/dataTables.buttons.min.js"></script> <script src="assets/js/lib/data-table/buttons.bootstrap.min.js"></script> <script src="assets/js/lib/data-table/jszip.min.js"></script> <script src="assets/js/lib/data-table/pdfmake.min.js"></script> <script src="assets/js/lib/data-table/vfs_fonts.js"></script> <script src="assets/js/lib/data-table/buttons.html5.min.js"></script> <script src="assets/js/lib/data-table/buttons.print.min.js"></script> <script src="assets/js/lib/data-table/buttons.colVis.min.js"></script> <script src="assets/js/lib/data-table/datatables-init.js"></script> <script src="https://cdn.tiny.cloud/1/sw6bkvhzd3ev4xl3u9yx3tzrux4nthssiwgsog74altv1o65/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script> <script> tinymce.init({ selector: 'textarea', plugins: 'advlist autolink lists link image charmap print preview hr anchor pagebreak', toolbar_mode: 'floating', }); </script> <script type="text/javascript"> $(document).ready(function() { $('#customer-table').DataTable(); } ); </script> </body> </html> My guess is the placeholder section is not working. // Posted data. $row['name'] = str_replace(' ', '', $_POST['name']); $row['description'] = str_replace(' ', '', $_POST['description']); $row['body'] = $_POST['body']; // Data array (Should match with data above's order). $placeholders = array('{name}', '{description}', '{body}'); Here is template.php <?php include_once('includes/header.php'); require_once('admin/includes/config.php'); if(isset($_POST['new']) && $_POST['new']==1){ $trn_date = mysqli_real_escape_string($con, date("Y-m-d H:i:s")); $name = mysqli_real_escape_string($con, $_POST['name']); $email = mysqli_real_escape_string($con, $_POST['email']); $pickup = mysqli_real_escape_string($con, $_POST['pickup']); $dropoff = mysqli_real_escape_string($con, $_POST['dropoff']); $dep_date = mysqli_real_escape_string($con, $_POST['dep_date']); $ret_date = mysqli_real_escape_string($con, $_POST['ret_date']); $dep_time = mysqli_real_escape_string($con, $_POST['dep_time']); $pax_numbers = mysqli_real_escape_string($con, $_POST['pax_numbers']); $ins_query="insert into quotes (`trn_date`,`name`,`email`, `pickup`, `dropoff`, `dep_date`, `ret_date`, `dep_time`, `pax_numbers`) values ('$trn_date','$name','$email', '$pickup', '$dropoff', '$dep_date', '$ret_date', '$dep_time', '$pax_numbers')"; mysqli_query($con,$ins_query) or die(mysqli_error($con)); if(mysqli_affected_rows($con)== 1 ){ $message = "Thank you. We will be in touch soon."; } } $sql = "SELECT * FROM slide"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { ?> <div class="hero-wrap" style='background-image: url("admin/uploads/<?php echo $row['image']; ?>")' data-stellar-background-ratio="0.5"> <div class="overlay"></div> <div class="container"> <div class="row no-gutters slider-text justify-content-start align-items-center"> <div class="col-lg-6 col-md-6 ftco-animate d-flex align-items-end"> <div class="text"> <p style="font-size: 18px;"><?php echo $row['slide_text']; ?></p> <a href="<?php echo $row['youtube']; ?>" class="icon-wrap popup-vimeo d-flex align-items-center mt-4"> <div class="icon d-flex align-items-center justify-content-center"> <span class="ion-ios-play"></span> </div> <div class="heading-title ml-5"> <span>Play Our Short Video</span> </div> </a> </div> </div> <div class="col-lg-2 col"></div> <div class="col-lg-4 col-md-6 mt-0 mt-md-5 d-flex"> <form method="post" action="" role="form" class="request-form ftco-animate"> <input type="hidden" name="new" value="1" /> <h2>Get A Quote</h2> <div class="d-flex"> <div class="form-group mr-2"> <label for="name" class="label">Name</label> <input class="form-control" type="text" id="name" name="name" placeholder="Your Name" /> </div> <div class="form-group ml-2"> <label for="email" class="label">Email</label> <input class="form-control" type="email" id="email" name="email" placeholder="Your Email" /> </div> </div> <div class="form-group"> <label for="searchBox" class="label">Pick-Up Location</label> <input class="form-control" type="text" id="searchBox" name="pickup" placeholder="Start Typing..." /> </div> <div class="form-group"> <label for="searchBoxAlt" class="label">Drop-Off Location</label> <input type="text" class="form-control" id="searchBoxAlt" name="dropoff" placeholder="Start Typing..." /> </div> <div class="d-flex"> <div class="form-group mr-2"> <label for="" class="label">Departure Date</label> <input type="text" class="form-control" id="book_pick_date" name="dep_date" placeholder="Date"> </div> <div class="form-group ml-2"> <label for="" class="label">Return Date</label> <input type="text" class="form-control" id="book_off_date" name="ret_date" placeholder="Date"> </div> </div> <div class="d-flex"> <div class="form-group mr-2"> <label for="" class="label">Pick-Up Time</label> <input type="text" class="form-control" id="time_pick" name="dep_time" placeholder="Time"> </div> <div class="form-group ml-2"> <label for"" class="label">Passenger Numbers</label> <input type="number" class="form-control" id="pax_numbers" name="pax_numbers" placeholder="Amount" /> </div> </div> <div class="form-group"> <button type="submit" class="btn btn-primary py-3 px-4">Request Quote</button> <p><?php if($message = isset($message) ? $message : ''){ printf($message); } ?></p> </div> </form> </div> </div> </div> </div> <?php } } ?> <script type="text/javascript" src="https://www.bing.com/api/maps/mapcontrol?key=AqIY0ivSCCdBIe3-EKGuox9cwBFw2wWRWIErZi1iy57EfD67PoiSra9wl_wu48de&callback=bingMapsReady" async defer></script> <?php if(isset($_GET['id'])){ $id = mysqli_real_escape_string($con, $_GET['id'] ?? DEFAULT_ID); $sql = "SELECT * FROM pages WHERE id = $id"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_array()) { ?> <!-- HOW IT WORKS --> <section class="ftco-section ftco-no-pt ftco-no-pb"> <div class="container"> <div class="row no-gutters"> <div class="col-md-12 wrap-about py-md-5 ftco-animate"> <div class="heading-section mb-5 pl-md-5"> <span class="subheading"><?php echo $row['description']; ?> </span> <h2 class="heading"><?php echo $row['name']; ?></h2> <?php echo $row['body']; ?> </div> </div> </div> </div> </section> <?php } } } ?> <!-- FOOTER --> <?php include_once('includes/footer.php'); ?> Please note that this is just a project and will not be going live. It's for learning purposes and I am aware there are some vulnerabilities within parts of the code. Any assistance with the above issues though would really be appreciated. Thanks and have a ripper evening.
  9. Hi, this query runs fine when I run it from PHPMyAdmin: UPDATE `tran_term_taxonomy` SET `description` = (SELECT keyword from `good_keywords` ORDER BY RAND() LIMIT 1,1) WHERE `tran_term_taxonomy`.`taxonomy` = 'post_tag' AND `tran_term_taxonomy`.`description` = "" LIMIT 1 However, when I run the same query in a PHP file on my server, the page doesn't load at all. The message I get is: www.somesite.com is currently unable to handle this request. HTTP ERROR 500. This is my PHP code: <?php include("/database/connection/path/db_connect.php"); $result4 = mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE `tran_term_taxonomy` SET `description` = (SELECT keyword from `good_keywords` ORDER BY RAND() LIMIT 1,1) WHERE `tran_term_taxonomy`.`taxonomy` = 'post_tag' AND `tran_term_taxonomy`.`description` = "" LIMIT 1"); echo $result4; ?> So how do I make this query work please? Thanks for your guidance.
  10. Hi there I am a new at this website, thanks for helping me... I have this code: <?php $select_active_shopes="SELECT tbl_shopkeepers_info.*, tbl_active_shopkeepers.* FROM tbl_shopkeepers_info INNER JOIN tbl_active_shopkeepers ON(tbl_active_shopkeepers.shopkeeper_id=tbl_shopkeepers_info.shopkeeper_id) ORDER BY tbl_active_shopkeepers.active_shopkeeper_id DESC"; $rs_active_shopes=mysqli_query($link,$select_active_shopes) or die(mysqli_error($link)); ?> <div class="container-fluid text-center my-3"> <h2 class="font-weight-light"></h2> <div class="row mx-auto my-auto"> <div id="recipeCarousel" class="carousel slide w-100" data-ride="carousel"> <div class="carousel-inner w-100" role="listbox"> <?php $i = 1; $next_item = true; while($row_active_shopes=mysqli_fetch_array($rs_active_shopes)) { $shop_img=$row_active_shopes['shop_img']; if ($i == 1) { echo '<div class="carousel-item active">'; } elseif ($next_item == true) { echo ' <div class="carousel-item">'; } ?> <div class="col-md-2"> <div class="card-body"> <div class="circular--portrait"> <img class="img-fluid" src="<?php echo "images/".$row_active_shopes['shop_img'];?>"> </div> <p class="card-text" id="font"><?php echo $row_active_shopes['location_name'];?></p> </div> </div> <?php $next_item = false; if ($i % 4 == 0) { echo '</div>'; $next_item = true; } $i++; } ?> </div> </div> <a class="carousel-control-prev w-auto" href="#recipeCarousel" role="button" data-slide="prev"> <span class="carousel-control-prev-icon bg-dark border border-dark rounded-circle" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next w-auto" href="#recipeCarousel" role="button" data-slide="next"> <span class="carousel-control-next-icon bg-dark border border-dark rounded-circle" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </div> with js below code: $('#recipeCarousel').carousel({ interval: 10000 }) $('.carousel .item').each(function(){ var next = $(this).next(); if (!next.length) { next = $(this).siblings(':first'); } next.children(':first-child').clone().appendTo($(this)); if (next.next().length>0) { next.next().children(':first-child').clone().appendTo($(this)); } else { $(this).siblings(':first').children(':first-child').clone().appendTo($(this)); } }); this code is working for displaying data my problem when I clicked the next and previous to the next slide not working. Output codes: How I can fix please help me
  11. Im trying to write some code for a raffle, when someone buys one ticket it works well but if someone buys ten tickets. i would like it to put each one on a new row, the last column is the ticket number which is got by another table called count and i want the new count in the last column of each row. In the actual script there is more than two columns but this is an example just to try to let you know what im trying to do. As you can see i want the ticket number to increment by one every time someone buys tickets. (the ticket number is in a simple table with just id and ticket number) EXAMPLE someone buys 2 tickes name | ticket number John | 1 john | 2 then someone buys three tickets jane | 3 jane | 4 jane | 5 This is what i have. (WORKING EXAMPLE of the code tha doesnt work.) as you can see the ticker number stays the same and not increment by one. <?php $num //is a number between 1 and 10 $tr //is the current count got from database (this needs to count up by one every entry) include 'includes/connect.php'; $num = "3"; // number of tickets someone buys. $count = "5"; // count of tickets already sold (so this is start count for this transaction). $id = "1"; // this is the line the counter is on to keep count updated for the amount of tickets sold. $name = 'john'; //example name for($i=0;$i< $num;$i++){ $count="$count+1"; // increments count by 1 $sql123 = "UPDATE count SET count=$count WHERE id='$id'"; //should update database to new count $sql = "INSERT INTO test (name, number) VALUES ('$name', '$count')"; if($result = mysqli_query($con, $sql)){ echo "<br>tickets bought and entered into database,<br>Thank you<br>"; } else { echo "Error: " . $sql . "<br>" . $con->error; } } ?> Not sure what im doing wrong? Thank you in advance Nook6
  12. Hi All, I am adding a button that will delete many things in the system which all have the same $job_id There is going to be 10 or so tables that need to delete * where $job_id = ? Is there a better way to do this rather than just iterating my code 10 times. I was looking at just joining but isnt one benefit of prepared statements that they can be used again and again to increase speed.
  13. HI All Not sure how best to describe what i am trying to do so here goes. People use my system to order food from a menu - this is not for a restaurant where you order one starter main and desert, they will be ordering 00's of meals. The table layout is as follows: ssm_menu menu_id | menu_name | menu_price ssm_menu_connection menu_id | menu_item_id | surrogate_id ssm_menu_items menu_item_id | menu_item_name | menu_item_category ssm_menu_order job_id | menu_id | menu_item_id | menu_item_qty Menu items can appear on more than one menu. If a user orders 100 of menu_item_id 1, 2 & 3 these appear on menu_id 1& 2 Menu_id 1 only contains item_id 1, 2, 3 Menu_id 2 contains menu_item 1,2,3,4,5,6,7,8,910 when querying the database, i would like the menu_id to comeback as 1 as all of the items appear on this menu and out of all available menu items the higher percentage have been picked from this menu than menu_id 2. So on menu_id 1 = 100% of the available menu_item_id have been given a menu_item_qty but on menu_id 2, only 30% of the available menu_item_id have been selected. the sql that i have started with is the following: select menu_name from ssm_menu a inner join ssm_menu_connection b on a.menu_id = b.menu_id inner join ssm_menu_items c on b.menu_item_id = c.menu_item_id inner join ssm_menu_order d on c.menu_item_id = d.menu_item_id where job_id = 27 The result of this is: Menu One, Menu One, Menu One, Menu Two, Menu Two, Menu Two I hope this is enough information to shed some light on what i am trying to achieve and appreciate any feedback in advance. Kind Regards Adam
  14. I have 3 staff members that need to pick vacation in a certain order. Each have X weeks vacation and can pick off a calendar their choice 1-3 weeks per round. I'm trying to loop through the DB to find who is next to pick with weeks left ~~~~~~First round of picking~~~~~~ STAFF 1 - PICK ORDER 1 - 3 weeks available STAFF 2 - PICK ORDER 2 - 5 weeks available STAFF 3 - PICK ORDER 3 - 3 weeks available Staff 1 takes 2 Weeks Staff 2 takes 1 Weeks Staff 3 takes 3 Weeks ~~~~~~Second round of picking~~~~~~ STAFF 1 - PICK ORDER 1 - 1 weeks available STAFF 2 - PICK ORDER 2 - 4 weeks available STAFF 3 - PICK ORDER 3 - No weeks left Staff 1 takes 1 Weeks Staff 2 takes 3 Weeks Staff 3 Skipped ~~~~~~Third round of picking~~~~~~ STAFF 1 - PICK ORDER 1 - No weeks left STAFF 2 - PICK ORDER 2 - 1 weeks available STAFF 3 - PICK ORDER 3 - No weeks left Staff 1 Skipped Staff 2 takes 1 Weeks Staff 3 Skipped ~~~~~~~~~~~~ All staff 0 weeks left end --calendar.php-- $year=2020; $sql = "SELECT * FROM vac_admin WHERE pick_year='$year'; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { $row_admin = mysqli_fetch_assoc($result); } $current_pick_staff = $row_admin['current_pick_staff']; $sql = "SELECT * FROM vac_pick_order WHERE pick_year='$year' && pick_order = '$current_pick_staff'"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); if($row['vac_c_counter'] < 0){ $emp_num = $row['emp_num']; }ELSE{ ?????????????????? goto next staff with weeks > 0 ?????Somthing like if ($current_pick_staff == 3){ $current_pick_staff = 1; }ELSE{ $current_pick_staff++; } ?????????????????? } ~<FORM>~~~~~~~~~~~~~~~~~~~~~ Staff with $emp_num can now pick ~~~~~~ $_POST -> $date = XXXX-XX-XX; $num_weeks = X; $emp_num; ~</FORM>~~~~~~~~~~~~~~~~~~~~~ --process.php-- $year = 2020; $date = $_POST['date']; $num_weeks = $_POST['num_weeks']; $emp_num = $_POST['emp_num']; $sql = "INSERT INTO vac_picks (pick_year,emp_num,date) VALUES ($year,$emp_num,$date)"; $sql = "UPDATE vac_pick_order SET vac_c_counter=vac_c_counter - $num_weeks WHERE emp_num='$emp_num'; $sql = "UPDATE vac_admin SET pick_order=pick_order +1 WHERE pick_year='$year' ; Then back to calendar.php until all weeks gone.
  15. Hello everyone, I am trying to submit a comment in a comment box and send it to the DB but is not happening. The connection is good as I am logging in and all but no data is sent to the DB when I post the comment. It doesn't show in my comment section either. Form <!--comment section--> <?php if(isset($_SESSION['id'])) { echo "<form method='POST' action='" . setComments($conn) . "'> <input type='hidden' name='uidUsers' value='".$_SESSION['id']."'> <input type='hidden' name='posted' value='" . date('Y-m-d H:i:s') . "'> Comments: <textarea rows = '5' cols = '15' name='body'></textarea><br><br> <button name='commentSubmit' type='submit'>Comment</button> </form>"; }else { echo "Log in to comment!"; } getComments($conn); Function to set and get comments function setComments($conn) { if (isset($_POST['commentSubmit'])){ $user_id = $_POST['uidUsers']; $body = $_POST['body']; $posted = $_POST['posted']; $sql = "INSERT INTO comments (uidUsers, posted, body) VALUES ('$user_id', '$posted', '$body')"; $result = mysqli_query($conn, $sql); } } function getComments($conn) { $sql = "SELECT * FROM comments"; $result = mysqli_query($conn, $sql); while ($row = $result->fetch_assoc()){ $id = $row['uidUsers']; $sql2 ="SELECT * FROM users WHERE uidUsers='$id'"; $result2 = mysqli_query($conn, $sql2); if($row2 = $result2->fetch_assoc()){ echo "<div class='comment-box'><p>"; echo $row2['uidUsers'] . "<br>"; echo $row['posted'] . "<br>"; echo nl2br($row['body']); echo "</p></div>"; } } }
  16. If anyone could help, I'm not getting an error message and I've tried changing the code around a few times and outputting errors. The database does not update and i'm getting no error message output on submit, I assume i'm missing something? <?php session_start(); include_once 'dbconnect.php'; if (!isset($_SESSION['userSession'])) { header("Location: index.php"); } $query = $DBcon->query("SELECT * FROM tbl_users WHERE user_id=".$_SESSION['userSession']); $userRow=$query->fetch_array(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Welcome - <?php echo $userRow['email']; ?></title> <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"> <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen"> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <?php include_once 'header.php'; ?> <html> <head></head> <body> <h1>Send Message:</h1> <form action='message.php' method='POST'> <table> <tbody> <tr> <td>To: </td><td><input type='text' name='to' /></td> </tr> <tr> <td>From: </td><td><input type='text' name='from' /></td> </tr> <tr> <td>Message: </td><td><input type='text' name='message' /></td> </tr> <tr> <td></td><td><input type='submit' value='Create Task' name='sendMessage' /></td> </tr> </tbody> </table> </form> </body> </html> <?php if (isSet($_POST['sendMessage'])) { if (isSet($_POST['to']) && $_POST['to'] != '' && isSet($_POST['from']) && $_POST['from'] != '' && isSet($_POST['message']) && $_POST['message'] != '') { $to = $_POST['to']; $from = $userRow['email']; $message = $_POST['message']; $q = "INSERT INTO tbl_messages(id,message,to,from) VALUES('', '$message', '$to', '$from')"; if ($DBcon->query($q)) { $msg = "<div class='alert alert-success'> <span class='glyphicon glyphicon-info-sign'></span> Message Sent ! </div>"; }else { $msg = "<div class='alert alert-danger'> <span class='glyphicon glyphicon-info-sign'></span> Message not Sent! ! </div>"; } } } $DBcon->close();?> <?php php include_once 'footer.php'; ?> </html>
  17. Hi all Trying to build a multi level nav for bootstrap from a database below is the code I am using <?php $table = 'tbl_pages_'.$lang; $sql = "SELECT * FROM $table where parent_id = 0 and visible = 1 order by `order` asc"; //echo $sql; $result = mysqli_query($dbConn,$sql) or die(mysqli_error($dbConn)); if(mysqli_num_rows($result)>0){ ?> <nav class="navbar navbar-default navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav navbar-right"> <?php while($row = mysqli_fetch_assoc($result)){ if($row['page'] == 'riders'){ $pageId = $row['page_id']; //get rider information $table = 'tbl_riders_'.$lang; $sql2 = "SELECT * FROM $table where active = 1 order by `sort` asc"; $result2 = mysqli_query($dbConn,$sql2) or die(mysqli_error($dbConn)); if(mysqli_num_rows($result2) >0){ if($page == $row['page']){ echo '<li class="active dropdown">'; } else{ echo '<li class="dropdown">'; } echo '<a href="'.$shopConfig['url'].$row['link'].'" class="dropdown-toggle " data-hover="dropdown" data-toggle="dropdown">'.$row['menu_display']; echo '<b class="caret"></b></a>'; echo '<ul class="dropdown-menu">'; while($row2 = mysqli_fetch_assoc($result2)){ echo '<li><a href="'.$shopConfig['url'].$row['link'].'/'.$row2['id'].'/'.$row2['identifier'].'">'.$row2['rider_name'].'</a></li>'; } $table = 'tbl_pages_'.$lang; $sql3 = "SELECT * FROM $table where parent_id = $pageId and visible = 1 order by `order` asc"; //echo $sql3; $result3 = mysqli_query($dbConn,$sql3) or die(mysqli_error($dbConn)); if(mysqli_num_rows($result3)>0){ while($row3 = mysqli_fetch_assoc($result3)){ echo '<li><a href="'.$shopConfig['url'].$row3['link'].'">'.$row3['menu_display'].'</a></li>'; } } echo '</ul>'; echo '</li>'; } echo ''; } if(($row['page'] != 'shop') && ($row['page'] !='riders')){ $pageId = $row['page_id']; $pagetable = 'tbl_pages_'.$lang; $dropdown = ''; $subSQL = "SELECT * FROM $pagetable where parent_id = $pageId and visible =1 order by `order` asc"; //echo $subSQL; $subresult = mysqli_query($dbConn,$subSQL) or die(mysqli_error($dbConn)); $subRows = mysqli_num_rows($subresult); if($page == $row['page']){ if($subRows >0){ $dropdown = ' dropdown'; } echo '<li class="active'.$dropdown.'">'; } else{ if($subRows >0){ $dropdown = ' class="dropdown"'; } echo '<li'.$dropdown.'>'; } if($subRows > 0){ echo '<a href="'.$shopConfig['url'].$row['link'].'" class="dropdown-toggle " data-hover="dropdown" data-toggle="dropdown">'.$row['menu_display'].' <b class="caret"></b></a>'; echo '<ul class="dropdown-menu">'; while($row3 = mysqli_fetch_assoc($result3)){ echo '<li><a href="'.$shopConfig['url'].$row3['link'].'">'.$row3['menu_display'].'</a></li>'; } echo '</ul>'; } else{ echo '<a href="'.$shopConfig['url'].$row['link'].'">'.$row['menu_display'].'</a>'; } } } echo '</li>'; } else{ if($row['page'] =='shop' && $shopConfig['shop'] == 1 && $shopConfig['shop_status']=='2'){ if($page == 'shop'){ echo '<li class="active">'; } else{ echo '<li>'; } echo '<a href="'.$shopConfig['url'].$row['link'].'">'.$row['menu_display'].'</a></li>'; } ?> </ul> </div><!--/.nav-collapse --> </div> </nav> <?php } ?> this is the HTML it is rendering [code] <nav class="navbar navbar-default navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav navbar-right"> <li><a href="http://www.plymouthdevils.co/">Home</a><li><a href="http://www.plymouthdevils.co/sponsors">Sponsors</a><li class="active"><a href="http://www.plymouthdevils.co/news">News</a><li><a href="http://www.plymouthdevils.co/photos">Photos</a><li class="dropdown"><a href="http://www.plymouthdevils.co/riders" class="dropdown-toggle " data-hover="dropdown" data-toggle="dropdown">Riders<b class="caret"></b></a><ul class="dropdown-menu"><li><a href="http://www.plymouthdevils.co/riders/1/lee-smart">Lee Smart</a></li><li><a href="http://www.plymouthdevils.co/riders/2/henry-atkins">Henry Atkins</a></li><li><a href="http://www.plymouthdevils.co/riders/3/callum-walker">Callum Walker</a></li><li><a href="http://www.plymouthdevils.co/riders/4/richard-andrews">Richard Andrews</a></li><li><a href="http://www.plymouthdevils.co/riders/5/saul-bulley">Saul Bulley</a></li><li><a href="http://www.plymouthdevils.co/riders/6/steve-boxall">Steve Boxall</a></li></ul></li><li><a href="http://www.plymouthdevils.co/fixtures">Fixtures</a><li><a href="http://www.plymouthdevils.co/season-tickets">Season Tickets</a></li> </div> </div> [/code] I't's probably something obvious I've missed, but can't spot it.
  18. Hi, I've question regards to the topic title above for, "how to get/post myorder page code to payment page??" which didn't retrieve any data from myorder page or do I need a database for myorder page?. As myorder page uses GET function to collect information from product page that using mysqli SELECT function to get data from the database. Also "how to get/post the Total from the myorder page to payment page??". Below are the following code: - myorder.php page <?php session_start(); include 'db2.php'; if ( !empty($_SESSION["firstname"])) { } else { $_SESSION["firstname"]=null; } ?> <?php session_start(); if(isset($_POST["add_to_cart"])) { if(isset($_SESSION["shopping_cart"])) { $item_array_id = array_column($_SESSION["shopping_cart"], "item_id"); if(!in_array($_GET["id"], $item_array_id)) { $count = count($_SESSION["shopping_cart"]); $item_array = array( 'item_id' => $_GET["id"], 'item_name' => $_POST["hidden_vname"], 'item_price' => $_POST["hidden_vprice"], 'item_quantity' => $_POST["quantity"] ); $_SESSION["shopping_cart"][$count] = $item_array; } else { echo '<script>alert("Item Already Added")</script>'; echo '<script>window.location="myorder.php"</script>'; } } else { $item_array = array( 'item_id' => $_GET["id"], 'item_name' => $_POST["hidden_vname"], 'item_price' => $_POST["hidden_vprice"], 'item_quantity' => $_POST["quantity"] ); $_SESSION["shopping_cart"][0] = $item_array; } } if(isset($_GET["action"])) { if($_GET["action"] == "delete") { foreach($_SESSION["shopping_cart"] as $keys => $values) { if($values["item_id"] == $_GET["id"]) { unset($_SESSION["shopping_cart"][$keys]); echo '<script>alert("Item Removed")</script>'; echo '<script>window.location="myorder.php"</script>'; } } } } ?> <div class="panel"> <div class="panel-heading clearfix"> <h4 class="panel-title pull-left" style="padding-top: 7.5px;">Your Order Summary</h4> </div><!-- end panel-heading --> <div class="table-responsive"> <?php if (null==$_SESSION["firstname"]) { echo "You got to <a href='signin.php'>Sign In </a>to see Your Order summary"; exit(); } else { $sql = "Select * from register where firstname = "."'".$_SESSION["firstname"]."'"; $result = mysqli_query($con, $sql); $userinfo = mysqli_fetch_assoc($result); echo '<h5>'; echo $userinfo["firstname"]." ".$userinfo["lastname"]; echo '<br>'; echo $userinfo["address"]; echo '<br>'; echo $userinfo["country"]." ".$userinfo["zipcode"]; echo '</h5>'; } ?> <br /> <table class="table table-bordered"> <tr> <th width="40%">Item Name</th> <th width="10%">Quantity</th> <th width="20%">Price</th> <th width="15%">Total</th> <th width="5%">Action</th> </tr> <?php if(!empty($_SESSION["shopping_cart"])) { $total = 0; foreach($_SESSION["shopping_cart"] as $keys => $values) { ?> <tr> <td><?php echo $values["item_name"]; ?></td> <td><?php echo $values["item_quantity"]; ?></td> <td>$ <?php echo $values["item_price"]; ?></td> <td>$ <?php echo number_format($values["item_quantity"] * $values["item_price"], 2); ?></td> <td><a href="myorder.php?action=delete&id=<?php echo $values["item_id"]; ?>"><span class="text-danger">Remove</span></a></td> </tr> <?php $total = $total + ($values["item_quantity"] * $values["item_price"]); } ?> <tr> <td colspan="3" align="right">Total</td> <td align="right">$ <?php echo number_format($total, 2); ?></td> <td></td> </tr> <?php } ?> </table> </div> <form method="post"> <a href="index.php" class="btn btn-default">Continue Browsing</a> <a href="checkout.php" class="btn btn-default">Check Out</a></form> </div> - payment.php page <?php session_start(); if ( !empty($_SESSION["firstname"])) { } else { $_SESSION["firstname"]=null; } ?> <?php if (null==$_SESSION["firstname"]) { echo "You got to <a href='signin.php'>Sign In </a>to see Your Checkout summary"; exit(); } else { } ?> <?php // define variables and set to empty values $firstnameErr = $lastnameErr = $addressErr = $countryErr = $zipcodeErr = $emailErr = $creditcardnoErr = $expireMMErr = $expireYYErr = $creditcardexpiryErr = ""; $firstname = $lastname = $address = $country = $zipcode = $email = $creditcardno = $expireMM = $expireYY = $creditcardexpiry= ""; $haserror = false; global $con; if (null==$_SESSION["firstname"]) { echo "Sign in <a href='signin.php'>Sign in</a> first before making payment"; exit(); } else { } if ($_SERVER["REQUEST_METHOD"] == "Post") { if (empty($_POST["firstname"])) { $firstnameErr = "Firstname is required"; } else { $firstname = test_input($_POST["firstname"]); } if (empty($_POST["lastname"])) { $lastnameErr = "Lastname is required"; } else { $lastname = test_input($_POST["lastname"]); } if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); } if (empty($_POST["address"])) { $addressErr = "Address is required"; } else { $address = test_input($_POST["address"]); } if (empty($_POST["country"])) { $countryErr = "Country is required"; } else { $country = test_input($_POST["country"]); } if (empty($_POST["zipcode"])) { $zipcodeErr = "Zipcode is required"; } else { $zipcode = test_input($_POST["zipcode"]); } if (empty($_POST["creditcardno"])) { $creditcardnoErr = "Credit Card number is required"; $haserror = true; } else { $creditcardno = test_input($_POST["creditcardno"],$con); // Check if Creditcard only contains numbers if (!preg_match("/^[0-9]{15,16}$/",$creditcardno)) { $creditcardnoErr = "Only numbers allowed and minimum 15 digits"; $haserror = true; } } if (empty($_POST["expireMM"])) { $expireMMErr = "Expiry Month is required"; $haserror = true; } else { $expireMM = test_input($_POST["expireMM"],$con); } if (empty($_POST["expireYY"])) { $expireYYErr = "Expiry Year is required"; $haserror = true; } else { $expireYY = test_input($_POST["expireYY"],$con); } $creditcardexpiry = $expireMM.$expireYY; // Post to Database if no error if (!$haserror) { $sql = "INSERT INTO usercheckout (firstname, lastname, address, country, zipcode, email, creditcardno,creditcardexpiry,amount) VALUES (". "'".$firstname."'" . ", " . "'".$lastname."'" . ", " . "'".$address."'" . ", " . "'".$country."'" . ", " . "'".$zipcode."'" . ", " . "'".$email."'" . ", " . "'".$creditcardno."'" . ", " . "'".$creditcardexpiry."'" . ",". $_SESSION['total'].")"; if(mysqli_query($con, $sql)){ $sql0="SELECT MAX(paymentID) as paymentIDVal FROM usercheckout"; $result0 = mysqli_query($connection, $sql0); $pay = mysqli_fetch_assoc($result0); if (mysqli_query($connection, $sql0)){ $_SESSION['payid'] = $pay['paymentIDVal']; } $sql1 = "Select a.*, b.vname FROM shopping_cart a INNER JOIN video_products b ON a.vid=b.vid where checkout = 0"; $result1 = mysqli_query($con, $sql1); // Send out email for confirmed orders $subject = "Cherry Online Orders Confirmation"; $body = "<h2>Receipt Number: " . $_SESSION['payid'] . "</h2><br><br>"; $body .= "<table border='1'>"; $body .="<tr>"; $body .="<th>Product</th>"; $body .="<th>Unit Price</th>"; $body .="<th>Quantity</th>"; $body .="<th>Subtotal</th>"; $body .="</tr>"; while($row = mysqli_fetch_assoc($result1)){ $body .="<tr>"; $body .="<td>" . $row['vname'] . "</td>"; $body .="<td>" . $row['scprice'] . "</td>"; $body .="<td>" . $row['scquantity'] . "</td>"; $body .="<td>" . $row['scprice']*$row['scquantity'] . "</td>"; $body .="</tr>"; } $body .="</table>"; $headers = "From: StayONFLIX < stayonflix1234@gmail.com > \r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=utf-8\r\n"; mail($email,$subject,$body,$headers); // Set Checkout flag to 1 to signify item checked out $sql2 = "UPDATE shopping_cart SET Checkout = '1', paymentid =".$_SESSION['payid']." WHERE checkout = 0"; if(mysqli_query($con, $sql2)){ mysqli_close($con); header("Location: index.php"); } } // exit(); } } function test_input($data,$connection) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); $data = mysqli_real_escape_string($connection, $data); return $data; } ?> <div class="row"> <div class="col-md-6 col-sm-6 col-xs-6"> <div class="panel panel-default"> <div class="panel-heading">Payment Address</div> <div class="panel-body"> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> First Name: <input type="text" name="firstname" value="<?php echo $firstname;?>"> <span class="error">* <?php echo $firstnameErr;?></span> <br><br> Last Name: <input type="text" name="lastname" value="<?php echo $lastname;?>"> <span class="error">* <?php echo $lastnameErr;?></span> <br><br> E-mail: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr;?></span> <br><br> Address: <input type="text" name="address" value="<?php echo $address;?>"> <span class="error">* <?php echo $addressErr;?></span> <br><br> Country: <input type="text" name="country" value="<?php echo $country;?>"> <span class="error">* <?php echo $countryErr;?></span> <br><br> Zipcode: <input type="text" name="zipcode" value="<?php echo $zipcode;?>"> <span class="error">* <?php echo $zipcodeErr;?></span> <br><br> Credit Card Number: <input type="text" name="creditcardno" value="<?php echo $creditcardno;?>" size="16" maxlength="16"> <span class="error">* <?php echo $creditcardnoErr;?></span> <br><br> Credit Card Expiry: <select name='expireMM'> <option value=''>Month</option> <option value='01'>January</option> <option value='02'>February</option> <option value='03'>March</option> <option value='04'>April</option> <option value='05'>May</option> <option value='06'>June</option> <option value='07'>July</option> <option value='08'>August</option> <option value='09'>September</option> <option value='10'>October</option> <option value='11'>November</option> <option value='12'>December</option> </select> <?php echo "<select name='expireYY'>"; echo "<option value=''>Year</option>"; for($i=0;$i<=10;$i++){ $expireYY=date('Y',strtotime("last day of +$i year")); echo "<option name='$expireYY'>$expireYY</option>"; } echo "</select>"; ?> <span class="error">* <?php echo $expireMMErr;?>&nbsp<?php echo $expireYYErr;?></span> <br><br> Amount: $<?php echo $_SESSION['total'];?> <br><br> <input type="submit" name="submit" value="Submit"> </form> </div> </div> </div> <div class="col-md-6 col-sm-6 col-xs-6"> <div class="panel panel-success"> <div class="panel-heading"> Review Order</div> <div class="panel-body"> <div class="row"> <div class="col-md-4 col-sm-4"> <span style="font-size:14px;"></span> </div> <div class="col-md-4 col-sm-4"> <span style="font-size:14px;">Item Name</span><br> <span style="color:rgba(99, 95, 95, 0.86);">Quantity: 1</span> </div> <div class="col-md-3 col-sm-3"> <span class="pull-right" style="font-weight:bold;font-size:20px;">$15.00</span> </div> </div> <hr> <div class="row"> <div class="col-md-6 col-sm-6"> <span style="font-weight:bold;font-size:20px;">Total Price</span> </div> <div class="col-md-5 col-sm-5"> <span class="pull-right" style="font-weight:bold;font-size:20px;">$15.00</span> </div> </div> </div> </div> </div> </div> Thanks for helping Appreciate alot, if someone could help.
  19. I created a recipe site that displays various dishes, and I'm tickled pink that I got it to work (first time doing this!) But I'd like to have pages that displays dishes by its category. The column that houses this is called "category" which has 7 total: Appetizers & Beverages, Soups & Salads, Side Items, Main Dishes, Baked Goods, Desserts, and Cookies & Candy. I have this page connected to a "connection.php" page, but here's the code in question: <!-- Page Title--> <div class="row"> <div class="col-lg-12"> <h1 class="page-header">Appetizers & Beverages</h1> </div> </div> <!-- /Page Title --> <!-- Displayed Data--> <?php $sql = "SELECT id, category, bilde, title FROM oppskrift_table ORDER BY title "; $result = mysqli_query($con, $sql); if(mysqli_num_rows($result) > 0 ){ while($row = mysqli_fetch_assoc($result)){ ?> <div align="center" class="col-md-3"> <a href="#"> <img class="img-responsive img-cat" src="bilder/rBilder/<?=$row['bilde']?>" width="250" alt=""> </a> <h4 style="max-width:250px;"> <a href="#" class="dishes"> <?=$row['title']?> </a> </h4> </div> <?php } } ?> <!-- END Displayed Data--> </div> How can I tweak this so that only the category Appetizers & Beverages shows up on the page?
  20. can someone assistance me with converting this code over to mysqli. I know that mysqli requires 2 parameters instead of one... i tried $user = mysqli_real_escape_string($g_link, $en['user']); but no connection was passed. $user = mysql_real_escape_string($en['user']); $pass = mysql_real_escape_string($en['pass']); $sql = "SELECT m_id, m_user, m_pass, m_email, m_del FROM $membtable WHERE m_user='".$user."' AND m_pass='".$pass."' AND m_del!=1"; $result = mysql_query($sql); $line = mysql_fetch_assoc($result); Db Connection $g_link = false; function GetDbConn() { global $g_link; if( $g_link ) return $g_link; $g_link = mysqli_connect($db_server, $db_user, $db_pass) or die("Error " . mysqli_error($g_link)); mysqli_select_db($g_link, 'cialdb') or die('Could not select database.'); return $g_link; }
  21. Hello I'm trying to check if 2 values exist in the database using php, Google didn't help... I need something like this : if($stmt = mysqli_prepare($db_connect,'QUERY TO CHECK IF USERNAME AND EMAIL EXIST')){ mysqli_stmt_bind_param($stmt, "ss", $user,$email); mysqli_stmt_execute($stmt); /* if username exist echo username exist if email exist echo email exist */ } else{/*error*/} thanks !
  22. Im having trouble on my php script. it is working on my computer but when I put it in x10hosting it fails and gives an error 500. I tried tracing the problem and I found out that it happens if I call get_result. Here is the part code: $username = strtolower(filter_input(INPUT_POST, 'username')); $password = filter_input(INPUT_POST, "password"); $remember = filter_input(INPUT_POST, "remember"); $result = array(); include 'Connection.php'; $query = "SELECT Number, Username, Password, Alias, Level FROM user WHERE Username = ?;"; $stmt = $conn->prepare($query); if(!$stmt->prepare($query)) { die( "Failed to prepare statement."); } $stmt->bind_param("s", $username); $stmt->execute(); echo $stmt->error; //error hapens here $selectResult = $stmt->get_result();
  23. Hi, I am making a CMS and I can't get the search page to work right. The CMS is for a new local DJI store and I can't get anything to show up when I search for those who have paid for insurance on their drones. And when I enter a first or last name that multiple people have in common, like Mike or Smith, the info doesn't display correctly, The first customer is displayed correctly, but no one else is. searchcodefirst.php searchcodeinsurance.php searchcodelast.php
  24. I am trying to add a query to my script that updates a value in my database by subtracting "1". When I run the query, I get "Fatal error: Call to a member function free() on boolean in ../path/to/my/script" $sql = "UPDATE table_5 SET chairs = chairs - 1 WHERE chairs > 0 AND chair_model = 'model_33'"; Any idea what I'm doing wrong? Table 5: Chairs | Model Number | 22 | model_33 44 | model_44
  25. Hi all. I don't know why this is happening. I have a scrip that backs up database. It works fine on database1 but when i use it on database2, it throws an error? Fatal error: Call to a member function fetch_row() on a non-object in $tableshema = $shema->fetch_row() ; both databases are on same domain. ps: even with another backup script still throws an error in database2 thanks ##################### //CONFIGURATIONS ##################### // Define the name of the backup directory define('BACKUP_DIR', 'cashBackup' ) ; // Define Database Credentials define('HOST', 'localhost' ) ; define('USER', 'username' ) ; define('PASSWORD', 'password' ) ; define('DB_NAME', 'database2' ) ; /* Define the filename for the Archive If you plan to upload the file to Amazon's S3 service , use only lower-case letters . Watever follows the "&" character should be kept as is , it designates a timestamp , which will be used by the script . */ $archiveName = 'mysqlbackup--' . date('d-m-Y') . '@'.date('h.i.s').'&'.microtime(true) . '.sql' ; // Set execution time limit if(function_exists('max_execution_time')) { if( ini_get('max_execution_time') > 0 ) set_time_limit(0) ; } //END OF CONFIGURATIONS /* Create backupDir (if it's not yet created ) , with proper permissions . Create a ".htaccess" file to restrict web-access */ if (!file_exists(BACKUP_DIR)) mkdir(BACKUP_DIR , 0700) ; if (!is_writable(BACKUP_DIR)) chmod(BACKUP_DIR , 0700) ; // Create an ".htaccess" file , it will restrict direct access to the backup-directory . $content = 'deny from all' ; $file = new SplFileObject(BACKUP_DIR . '/.htaccess', "w") ; $written = $file->fwrite($content) ; // Verify that ".htaccess" is written , if not , die the script if($written <13) die("Could not create a \".htaccess\" file , Backup task canceled") ; // Check timestamp of the latest Archive . If older than 24Hour , Create a new Archive $lastArchive = getNameOfLastArchieve(BACKUP_DIR) ; $timestampOfLatestArchive = substr(ltrim((stristr($lastArchive , '&')) , '&') , 0 , - ; if (allowCreateNewArchive($timestampOfLatestArchive)) { // Create a new Archive createNewArchive($archiveName) ; } else { echo '<p>'.'Sorry the latest Backup is not older than 24Hours , try a few hours later' .'</p>' ; } ########################### // DEFINING THE FOUR FUNCTIONS // 1) createNewArchive : Creates an archive of a Mysql database // 2) getFileSizeUnit : gets an integer value and returns a proper Unit (Bytes , KB , MB) // 3) getNameOfLastArchieve : Scans the "BackupDir" and returns the name of last created Archive // 4) allowCreateNewArchive : Compares two timestamps (Yesterday , lastArchive) . Returns "TRUE" , If the latest Archive is onlder than 24Hours . ########################### // Function createNewArchive function createNewArchive($archiveName){ $mysqli = new mysqli(HOST , USER , PASSWORD , DB_NAME) ; if (mysqli_connect_errno()) { printf("Connect failed: %s", mysqli_connect_error()); exit(); } // Introduction information $return = "--\n"; $return .= "-- A Mysql Backup System \n"; $return .= "--\n"; $return .= '-- Export created: ' . date("Y/m/d") . ' on ' . date("h:i") . "\n\n\n"; $return .= "--\n"; $return .= "-- Database : " . DB_NAME . "\n"; $return .= "--\n"; $return .= "-- --------------------------------------------------\n"; $return .= "-- ---------------------------------------------------\n"; $return .= 'SET AUTOCOMMIT = 0 ;' ."\n" ; $return .= 'SET FOREIGN_KEY_CHECKS=0 ;' ."\n" ; $tables = array() ; // Exploring what tables this database has $result = $mysqli->query('SHOW TABLES' ) ; // Cycle through "$result" and put content into an array while ($row = $result->fetch_row()) { $tables[] = $row[0] ; } // Cycle through each table foreach($tables as $table) { // Get content of each table $result = $mysqli->query('SELECT * FROM '. $table) ; // Get number of fields (columns) of each table $num_fields = $mysqli->field_count ; // Add table information $return .= "--\n" ; $return .= '-- Tabel structure for table `' . $table . '`' . "\n" ; $return .= "--\n" ; $return.= 'DROP TABLE IF EXISTS `'.$table.'`;' . "\n" ; // Get the table-shema $shema = $mysqli->query('SHOW CREATE TABLE '.$table) ; // Extract table shema $tableshema = $shema->fetch_row() ; // Append table-shema into code $return.= $tableshema[1].";" . "\n\n" ; // Cycle through each table-row while($rowdata = $result->fetch_row()) { // Prepare code that will insert data into table $return .= 'INSERT INTO `'.$table .'` VALUES ( ' ; // Extract data of each row for($i=0; $i<$num_fields; $i++) { $return .= '"'.$rowdata[$i] . "\"," ; } // Let's remove the last comma $return = substr("$return", 0, -1) ; $return .= ");" ."\n" ; } $return .= "\n\n" ; } // Close the connection $mysqli->close() ; $return .= 'SET FOREIGN_KEY_CHECKS = 1 ; ' . "\n" ; $return .= 'COMMIT ; ' . "\n" ; $return .= 'SET AUTOCOMMIT = 1 ; ' . "\n" ; //$file = file_put_contents($archiveName , $return) ; $zip = new ZipArchive() ; $resOpen = $zip->open(BACKUP_DIR . '/' .$archiveName.".zip" , ZIPARCHIVE::CREATE) ; if( $resOpen ){ $zip->addFromString( $archiveName , "$return" ) ; } $zip->close() ; $fileSize = getFileSizeUnit(filesize(BACKUP_DIR . "/". $archiveName . '.zip')) ; $message = <<<msg <h4>BACKUP completed ,</h4> <p> The backup file has the name of : <strong> $archiveName </strong> and it's file-size is : $fileSize. </p> <p> This zip archive can't be accessed via a web browser , as it's stored into a protected directory.<br> It's highly recomended to transfer this backup to another filesystem , use your favorite FTP client to download the file . </p> msg; echo $message ; } // End of function creatNewArchive // Function to append proper Unit after a file-size . function getFileSizeUnit($file_size){ switch (true) { case ($file_size/1024 < 1) : return intval($file_size ) ." Bytes" ; break; case ($file_size/1024 >= 1 && $file_size/(1024*1024) < 1) : return round(($file_size/1024) , 2) ." KB" ; break; default: return round($file_size/(1024*1024) , 2) ." MB" ; } } // End of Function getFileSizeUnit // Funciton getNameOfLastArchieve function getNameOfLastArchieve($backupDir) { $allArchieves = array() ; $iterator = new DirectoryIterator($backupDir) ; foreach ($iterator as $fileInfo) { if (!$fileInfo->isDir() && $fileInfo->getExtension() === 'zip') { $allArchieves[] = $fileInfo->getFilename() ; } } return end($allArchieves) ; } // End of Function getNameOfLastArchieve // Function allowCreateNewArchive function allowCreateNewArchive($timestampOfLatestArchive , $timestamp = 24) { $yesterday = time() - $timestamp*3600 ; return ($yesterday >= $timestampOfLatestArchive) ? true : false ; } // End of Function allowCreateNewArchive
×
×
  • 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.