-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
You are grouping by jobId so you will get one row for each job. The max(quoteId) should be OK (as that is a aggregation) and also jobName and clientId from the job record, but the remaining values (like version and currency) could be arbitrarily selected from from any quote record associated with jobId.
-
I know the <select> dropdown looks fine and the options display correctly but view the page source code. The problem comes when the form is submitted and the value is wrong.
-
Beware when enclosing a string attribute value with single quotes. If $myrow['cats'] = "O'Reilly books; echo "<option value='{$myrow['cat']}'>{$myrow['cat']}</option>"; then the generated HTML will be And the submitted GET value... Instead, echo "<option value=\"{$myrow['cat']}\">{$myrow['cat']}</option>"; ->
-
How do you list two columns but not show duplicates from first column?
Barand replied to Plugnz13's topic in MySQL Help
Only out the maincat when it changes to a new value. set prevcat = maincat foreach record start new row if maincat != prevcat output maincat set prevcat = maincat else output blank endif output subcat end row end foreach -
Have you considered a common format such as ".csv" file EG First_Name,Last_Name,Sex,Fruits Scott,Chegg,male,"orange, berry" Laura,Norder,female,"apple, orange" code if($_SERVER['REQUEST_METHOD']=='POST'){ if (!file_exists('file.txt')) { file_put_contents('file.txt', "First_Name,Last_Name,Sex, Fruits\n"); // write header line } $file=fopen("file.txt", "a"); $record = [$_POST['firstName'], $_POST['lastName'], $_POST['sex'], join(',', $_POST['fruit'])]; fputcsv($file, $record); }
-
$_POST['fruit'] is an array, so line 9 would need to be $fruit = "Fav Fruits:" . join(', ', $_POST['fruit']); then fwrite($file, $fruit); I don't know what you subsequently intend to do with the text file but the format you use makes it both difficult to read and to process. An improvent would be some form of delimiter character between fields and newlines at end of each record. eg First Name:Laura|Last Name:Norder|Sex:female|Fav fruit:Apple, Orange First Name:Scott|Last Name:Chegg|Sex:male|Fav fruit:Apple, Berry [EDIT] Ignore the above comment re format. I just noticed you are (subtly) outputting newlines - I was looking for more explicit "\n";
-
A better way to handle multiple checkboxes like those is Fav Fruit<input type="checkbox" name="fruit[]" value="apple">Apple <input type="checkbox" name="fruit[]" value="orange">Orange <input type="checkbox" name="fruit[]" value="berry">Berry<br> so the checked ones are posted as an array $_POST = Array ( [firstName] => Scott [lastName] => Chegg [sex] => male [fruit] => Array ( [0] => apple [1] => berry ) ) When writing to the file fwrite($file, join(', ', $_POST['fruit']);
-
Define it as id int not null auto_increment primary key Remove "id" and its value from the insert query - let mysql handle it.
-
What is your primary key and how is it defined?
-
If it isn't reporting errors it may be logging them. Check the error log.
-
Does this help? <!DOCTYPE html> <html lang='en'> <head> <title>sample</title> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> var prices = { "Item A":12500, "Item B":9500, "Item C":99, "Item D":9900 } function listPrices() { $.each( prices, function(k, v) { price = v/100 let item = $("<li>", { "html": k + " : £" + price.toFixed(2)}) $("#price-list").append(item) }) } </script> <style type='text/css'> body { background-color: #fbf7e9; } </style> </head> <body> <button onclick='listPrices()'>Prices</button> <ul id='price-list'> </ul> </body> </html>
-
How to treat an XML code in html page correctly?
Barand replied to eaglehopes's topic in PHP Coding Help
Perhaps echo '<pre>' . htmlentities(' <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> ..... </url> <url> ..... </url> <url> ..... </url> <url> ..... </url> </urlset> ') . '</pre>'; -
the above comment still applies
-
Nothing is posted to login.php so the php block at the top is totally redundant. It look as though that code should be at the top of formulaire.php.
-
The normal convention is that only registered users can log in. You appear to be adding a "Catch 22" dimension to your application in that you have to log in in order to register.
-
$insertuserquery = "INSERT INTO users (username, hash, salt, fname, lname, email) VALUES ('$username', '$hash', '$salt', '$fname', '$lname', '$email')"; You still need to get the synatax correct in your name and email check queries. I f you can't see what's wrong, try echo $namecheckquery;
-
@Adamhumbug Your code appeared to be trying to calculate all totals in a loop (eg on button click) <button onclick='calculate()'>Calculate all totals</button> script function calculate() { $.each($(".completeLine"), function(k, v) { var qty = $(v).find('.itemQty option:selected').val(); var price = $(v).find('.itemSelected option:selected').data('priceuk'); $(v).find('.line-total').val(qty*price); }) }
-
Copy client information from one database to another
Barand replied to wongle's topic in PHP Coding Help
Assuming DB1 and DB2 live on the same server... $pdo->exec("INSERT INTO DB2.client SELECT * from DB1.client WHERE client_id = 223"); -
String literal values need to be quoted. You should be using a prepared statement, not putting those values directly into the query. You dont execute the query - you just define a string.
-
Use substr() echo substr($property['tagline'], 0, $x) . '...'; Why all the <?php ?> tags?
-
Not really. The $username is a string literal an would need to be inside quotes within a query. The query is probably failing with an "unknow column" error. The PDO options (what options!) don't implement exception reporting.
-
value="<?php while($item = $stmt->fetch()) { echo $item['agency_user']; } ?>" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NO! NO! NO! You don't use a while loop when there is only a single row returned. The while loop fetches rows until there are none left, at which point item contains "false" (ie empty). You are using the prepared query incorrectly. The point of preparing queries is to avoid putting variables into the query. <?php if ($SERVER['REQUEST_METHOD'] == 'POST') { //database cn $db = new PDO("mysql:host=localhost;dbname=centrify","root",""); $stmt = $db->prepare("SELECT * FROM agencies_data WHERE agency_user = ? "); $stmt->execute([ $_POST['user'] ]); $item = $stmt->fetch(); if ($item) { ?> <input class="form-control" type="text" name="oid" value="<?= $item['agency_user']?>"> <php } } ?>