-
Posts
24,604 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
I'd suggest something like this if($_SERVER['REQUEST_METHOD']=='POST') { $post = array_map('trim', $_POST); unset($post['submit']); // not wanted on journey $post['id'] = trim($_SESSION['id']); $post['submittedby'] = trim($_SESSION["username"]); if ($_FILES['image']['error'] = UPLOAD_ERR_OK) { // image file directory $target = "images/".basename($_FILES['image']['name']); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; $post['image'] = $target; }else{ $msg = "Failed to upload image"; $post['image'] = null; } } else { $post['image'] = null; } try { $sql = "UPDATE users SET name = :name, email = :email, phone = :phone, address = :address, license_number = :license_number, position = :position, role = :role, submittedby = :submittedby, image = :image WHERE id = :id "; $stmt= $db->prepare($sql); $stmt->execute($post); $message = ' <i class="fa fa-check text-success"> Record Updated!</i>'; } catch (PDOException $e) { $message = ' <i class="fa fa-check text-danger"> Something went wrong please contact the server admin.</i>'; } }
-
You aren't providing the values for the placeholders when you execute the query. Turn on the error reporting. Also you aren't specifying which row to update, so you will apply the same update to them all.
-
sending email with info from mysql database inserted
Barand replied to Gunnyk's topic in PHP Coding Help
What have you tried so far? -
Randomizing posts in word press - by a random seed + a day variable
Barand replied to maberg's topic in PHP Coding Help
You could just forget about the session value and SELECT ... ORDER BY RAND(dayofyear(CURDATE())) -
Display MQTT data on php page without refreshing the page.
Barand replied to michelle1404's topic in Javascript Help
Good luck with that. The MQTT is javascript, which runs in the client browser. PHP runs on the server. -
Display MQTT data on php page without refreshing the page.
Barand replied to michelle1404's topic in Javascript Help
I have moved it for you. -
Display MQTT data on php page without refreshing the page.
Barand replied to michelle1404's topic in Javascript Help
Does this help? -
I get it now. (I'll take the order example as I happened to have a convenient pair of test tables) TABLE: oc_order +----------+-----------+----------+------------+-----------------+ | order_id | firstname | lastname | date_added | order_status_id | +----------+-----------+----------+------------+-----------------+ | 1 | Hugh | Jass | 2020-05-01 | 1 | | 2 | Laura | Norder | 2020-05-03 | 1 | | 3 | Tom | DiCanari | 2020-05-05 | 1 | | 4 | Peter | Dowt | 2020-05-07 | 1 | +----------+-----------+----------+------------+-----------------+ 4 rows in set (0.00 sec) TABLE: oc_order_product +------------------+----------+-------------+----------+ | order_product_id | order_id | name | quantity | +------------------+----------+-------------+----------+ | 1 | 1 | Gizmo | 2 | | 2 | 1 | Widget | 5 | | 3 | 1 | Wotsit | 1 | | 4 | 2 | Thingy | 2 | | 5 | 2 | Widget | 1 | | 6 | 2 | Thingumajig | 1 | | 7 | 3 | Gizmo | 20 | | 8 | 3 | Widget | 15 | | 9 | 4 | Gizmo | 25 | | 10 | 4 | Thingy | 5 | | 11 | 4 | Wotsit | 10 | +------------------+----------+-------------+----------+ PROBLEM: to produce a paginated result with 2 orders per page SOLUTION: Use a paginated subquery for the orders instead of the order table itself PAGE 1 SELECT o.order_id , customer , p.name , p.quantity FROM ( SELECT order_id , concat(firstname, ' ', lastname) as customer FROM oc_order ORDER BY order_id LIMIT 0, 2 -- <- paginate here ) o JOIN oc_order_product p USING (order_id) +----------+--------------+-------------+----------+ | order_id | customer | name | quantity | +----------+--------------+-------------+----------+ | 1 | Hugh Jass | Gizmo | 2 | | 1 | Hugh Jass | Widget | 5 | | 1 | Hugh Jass | Wotsit | 1 | | 2 | Laura Norder | Thingy | 2 | | 2 | Laura Norder | Widget | 1 | | 2 | Laura Norder | Thingumajig | 1 | +----------+--------------+-------------+----------+ PAGE 2 SELECT o.order_id , customer , p.name , p.quantity FROM ( SELECT order_id , concat(firstname, ' ', lastname) as customer FROM oc_order ORDER BY order_id LIMIT 2, 2 ) o JOIN oc_order_product p USING (order_id) +----------+--------------+--------+----------+ | order_id | customer | name | quantity | +----------+--------------+--------+----------+ | 3 | Tom DiCanari | Gizmo | 20 | | 3 | Tom DiCanari | Widget | 15 | | 4 | Peter Dowt | Gizmo | 25 | | 4 | Peter Dowt | Thingy | 5 | | 4 | Peter Dowt | Wotsit | 10 | +----------+--------------+--------+----------+
-
Are you sure this is a database table and not a spreadsheet? Can you show a sample of the data to ilustrate the problem? It's difficult to imagine why this might be the case.
-
If you want a wavy line, just generate a sine wave.
-
The first one looks to me like it was created with ✶ or similar
-
You gotta be joking. There's only one true Editor - PHPEd 😁 - and so it begins.
-
An earlier post of yours shows you apparently disapprove of people posting solutions, so why should we?
-
While you're in a receptive mood I have another couple of recommendations for you. Use prepared statements so you aren't putting data values directly into the queries. Switch to PDO from mysqli. It's far more streamlined and makes (1) above much easier.
-
BTW, the time_start, time_end, break_time columns in your stafftime table should be type TIME, not VARCHAR.
-
How you do it depends on how you are entering the data. The are basically two approaches... Create the timesheet record first then, each day add that days stafftime record Have a form where you enter the timesheet header data and all days' times at once for a user. If you use the first, have a dropdown so the user can select the timesheet record id and write that id with the day's times into stafftime. Doing it the second way, on posting the form you would first write the timesheet record (id would be an autoincrement column) then call lastInserId() to get the id of that new record. You then insert the time records with that last inserted id as the sheet_id.
-
Received and loaded. Thanks. For each timesheet record you should have up to 7 (1 for each day of the week) records in stafftime. These stafftime records for the week should have a sheet_id value which matches the timesheet id of the parent timesheet record. You stafftime.sheet_id values match none of the timesheet ids.
-
Not what I asked for. There is no way that enables me to run your query on your data. I wanted something similar to what I posted in your previous topic...
-
Do you want to post a dump of your data so I can run your query at my end?
-
Did you read the bit in the JOIN tutorial about LEFT JOIN to a table (user in your case) and then referencing a column from that table in the WHERE clause?
-
Follow the link in my sig. There's a section in the tutorials dedicated to JOINS
-
Put this line immediately before your line that creates your mysqli connection mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); That will force mysqli to report any erors it encounters.
-
As @gizmola said, the first problem is missing style= second) You are using obsolete html markup 3) you have specified a couple of classes but not put them inside the class="w3-container" 4) Again inline style without the style= 5) You have broken up the style attributes with a couple of rogue quotes
-
If you know the cat_id, can't you then determine the category? All you should need to pass is the cat_id, which should be the value in your options.
-
Why? What's the difference between your category and cat_title?