-
Posts
24,615 -
Joined
-
Last visited
-
Days Won
835
Everything posted by Barand
-
Also, if continuing to use mysqli, place this line before connecting to the db server mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
-
You are missing the step to prepare the query before binding the parameters. I would strongly advise you use PDO rather than mysqli - much simpler.
-
Step 1 - read the error message Step 2 - look at the parameters in your code Step 3 - consult the reference manual to see what they should be Step 4 - adjust code accordingly
-
Just for the record... mysql> select * from datetest; +------------+------+ | unix | date | +------------+------+ | 1576972800 | NULL | | 1579651200 | NULL | | 1582329600 | NULL | +------------+------+ mysql> UPDATE datetest SET date = from_unixtime(unix); mysql> select * from datetest; +------------+------------+ | unix | date | +------------+------------+ | 1576972800 | 2019-12-22 | | 1579651200 | 2020-01-22 | | 1582329600 | 2020-02-22 | +------------+------------+
-
https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_from-unixtime
-
try $product_queried = '09shjk1'; $xml=simplexml_load_string($xmlstr) or die("Error: Cannot make object"); $items = $xml->xpath("//PRODUCT[@ITEM='$product_queried']"); if ($items) echo $items[0]['ITEM'] . ' - ' . $items[0]->STOCK . '<br>'; else echo "Not found";
-
Include is not function. ( )s are not required.
-
then <?php echo $result2['user_convoy']; ?> and <td><?php echo $result2['name']; ?></td> <td><?php echo $result2['date']; ?></td> Where are those values (user_convoy, name and date) supposed to come from?
-
Do you have an input form yet where the user can specify their requirements and dimensions/quantities?
-
You can submit the form when the checkbox is clicked <input type="checkbox" name="display" value="1" onclick="this.form.submit()"> <!-- give it a value --> The thing to remember about about checkboxes (and radiobuttons) is that only checked values are submitted so your processing has to check if they were posted or not. Either $display = isset($_POST['display']) ? $_POST['display'] : 0; or (v7.0+) $display = $_POST['display'] ?? 0;
-
That's the equivalent of removing the bulb when a warning light comes on. It doesn't fix anything.
-
Looks like the query is failing. Try putting $Search in single quotes, or, better, use a prepared query.
-
That is one of the worse pieces of advice I have seen in these forums for a long time. @Endrick, ignore what @jodunno said in the above quote and specify the columns your query needs - don't use "SELECT * ". One day it will come back to bite you. Consider this scenario... Joe has written a script which creates a register of all student names, and uses "SELECT * FROM student" (with the excuse that he needs all the columns anyway) and iterates through the results. He then takes a holiday and, while he is away, things change. A colleague of his adds a new "dissertation" column and an image BLOB column to the student table. This contains the text of each student's 10,000 word final dissertation and a photo of the student. His register program still works but a query that took milliseconds now takes an age to run. The register doesn't need the dissertation or image data but, nevertheless, is dragging them down from the database for every student.
-
If they were empty, var_dump would show string(0) "" try echo bin2hex($exif1['GPS']['GPSAltitureRef']);
-
Where you have a function that desn't return a value (referred to in some languages as a void function and in other languages as a procedure) then, I agree, a return on the last line is pointless as it exits the function anyway. For functions that return a value, a return is necessary, and usually on the last line, although not necessarily. Another debugging tip... When outputting to the screen normally, use "echo" When outputting variables for debug puposes only, use "print". This makes it easy to search and remove stuff that shouldn't be in the production version.
-
I wouldn't split the clients into vendor and client tables - just have a client table. In one transaction, A might be the seller but in another transaction A might be the buyer (as in the examples in your initial post). Just record the buyer and seller ids in each sale transaction. Don't store derived data, such as total paid, balance outstanding etc. You get those by querying the transactions and payments.
-
Your items table may be a headache. Vendor B sells bikes and the item attributes are Now what if vendor D sells fridge/freezers whose attributes are width, height, depth, colour, fridge capacity, freezer capacity, ice dispenser(Y/N) and vendor E is selling concert tickets?
-
That query is looking at March to May only, so that needs changing. Also it looks for those who paid; you now want those who didin't pay. In addition, you are looking for any occurence, not when there are 3.
-
If it helps, note that that a <button> element can have a value attribute independent of its label <?php $option = $_GET['option'] ?? ''; if ($option) echo "You chose $option<hr>"; ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Sample</title> </head> <body> <form> Select an option <button name="option" value="1">Choose me</button> <button name="option" value="2">Choose me</button> <button name="option" value="3">No, Choose me</button> <button name="option" value="4">No, Choose me</button> <button name="option" value="5">No, Choose me</button> </form> </body> </html>
-
when $ret > 0 you get sent to dashboard. It will not get as far the 3rd condition. Once on elseif condition is satisfied it stops processing them. BTW, you should always have an exit instruction after a header("location ...");
-
With mysqli, when you use prepare() you get a statement object. The fetch_all() method you are using is a mysqli result object method (You get a result object when you use mysqli query() ). mysqli was built by two teams of developers who never spoke to one another, and so you get one set of methods for statements and a completely different set for results. Use PDO and this mess goes away.
-
try $temp = []; foreach ($cars as $car) { $qty = intval($car); $key = trim(strstr($car, ','), ','); if (!isset($temp[$key])) $temp[$key] = 0; $temp[$key] += $qty; } foreach ($temp as $k => $t) { $newcars[] = "$t,$k"; }
-
Given that your form would look something like this your cars array would be an array of string values and not an array of arrays as you posted., IE $cars = [ 0 => "1,'BMW',15,13", 1 => "8,'BMW',15,13", 2 => "3,'Saab',5,2", 3 => "3,930,2,8", 4 => "6,370,7,1" ]; unless you are doing further processing to creat the posted array
-
Going back a step, how are you creating that original array?
-
Finishing a school assignment about a shopping cart
Barand replied to Niksou's topic in PHP Coding Help
All you should be sending to the cart is product id and quantity. Never allow the user the specify their own price, otherwise you'll end up selling everything for 0.01. On the cart page, query the database to get price and description.