Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. A prepared query is the best way to accomplish that. MYSQLI $inputname = "O'Brien"; $res = $mysqli->prepare("SELECT whatever from table1 where lastname = ? "; $res->bind->param("s", $inputname); $res->execute(); PDO $inputname = "O'Brien";; $res = $pdo->prepare("SELECT whatever from table1 where lastname = ? "; $res->execute( [$inputname] );
  2. If you intend calculating a total of the voucher codes or using them in some other arithmetic operation then keep it as a number (BIGINT) but if it's just a code, then it's a string.
  3. Looks like you are trying to store a 19 digit number in an INT field with a maximum value of 2147483647. Your voucher code is actually a string that consists of numeric characters (like a phone number) so store it as one, say VARCHAR(20);
  4. This example ensures every student has a unique matriculation number CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `firstName` varchar(50) NOT NULL, `lastName` varchar(50) NOT NULL, `matricNo` varchar(50) NOT NULL, `DOB` date NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `idx_student_matricNo` (`matricNo`) ) ;
  5. Describe "not working". That on its own tells us nothing.
  6. There's an example here, courtesy of @Psycho
  7. Don't check if a user exisits by first running a query. Instead, you should put a UNIQUE constraint on the columns and trap duplicate key errors when they occur on inserting a record. Why a mix of mysqli and PDO. Just stick with PDO. Don't create a new connection for each query as you do in you signup_push function - that will really slow you down. Create the connection once and pass it in the function arguments. INSERT, UPDATE and DELETE queries do not create result sets. You are inserting then using fetchAll() to count non-existant results. PDO::row_count() will tell you how many were affected by the query.
  8. Why duplicate all the code when the only thing that needs to change is the name of the database in the query?
  9. Use array keys instead of array_search $results = array_keys(array_column($data, 'oname'), 'Border.aao');
  10. Example of form and writing its form data to two tables in different databases <?php $con = <your db connection code> ; if ($_SERVER['REQUEST_METHOD']=='POST') { $stmt1 = $con->prepare("INSERT INTO database1.mytable(col1, col2, col3) VALUES (?,?,?)"); // insert into table i database1 $stmt2 = $con->prepare("INSERT INTO database2.mytable(col1, col2, col3) VALUES (?,?,?)"); // insert into table i database2 $stmt1->execute([ $_POST['val1'],$_POST['val2'],$_POST['val3'] ]); $stmt2->execute([ $_POST['val1'],$_POST['val2'],$_POST['val3'] ]); } ?> <form method='post'> Value 1 <input name='val1'> Value 2 <input name='val2'> Value 3 <input name='val3'> <input type='submit>' </form>
  11. OK. But, again, why do you need two pages? Are both databases on the same server? (Even if they aren't it just means you need two connections)
  12. Why submit to 2 pages?
  13. My query didn't involve any external variables as the date+7 is calculated in the query. I therefore used query() instead of prepare() - there is no execute() required with query(). Incidentally, your code just compares against now, now 7 days from now,
  14. Try $stmt = $pdo->query("SELECT * FROM care_plan_review WHERE reminder_date > CURDATE() + INTERVAL 7 DAY");
  15. Don't use a number. Each character in a number can be 1 of 10 choices. If you use a string of mixed uppercase, lowercase, numbers and puctuation each character can be 1 of 90 (approx) characters.
  16. The first reply in this thread does it without array iterator - read it beyond the first sentence and look at the output.
  17. https://www.php.net/print_f You don't need to select the same column twice. The %s in the print_f format argument are placeholders for the string variables ($row['type_chocolate']) mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $mysqli = mysqli_connect("localhost", "root", "P-11fl32fg14", "cocoa"); $query = "SELECT type_chocolate FROM type_chocolate"; $result = mysqli_query($mysqli, $query); while ($row = mysqli_fetch_assoc($result)) { printf("<a href='cacau_type_chocolate.php?type_chocolate=%s'>%s</a>", $row['type_chocolate'], $row['type_chocolate']); }
  18. It does exactly the same thing. Apart from making the PHP processor work a little harder, what does it achieve?
  19. Do you mean something like this countdown.php.txt
  20. @Zane I am pretty sure that these days #go-to-here at the end of the URL will send the user to the element on the page with id='go-to-here'
  21. We'll probably never know. I did ask for his table structures but that got ignored. Good luck.
  22. As @ginerjm stated, the AND is wrong - it should be a comma. Also the use of "... FROM users, messages" will result in a cartesian join. If you have a 100 users and each have 1 message, the query will return 10,000 rows (each user joined to each message). You need to specify the join criteria. What are the structures of your 2 tables? ie the output from these two queries.... DESCRIBE users; DESCRIBE messages;
  23. Store dates and times in your DB as date, time or datetime types format yyyy-mm-dd-hh-ii-ss (that's what they are there for). You can then use the dozens of inbuilt datetime functions, sort and compare them. There is, however, a str_to_date() function in mysql to convert a string to a datetime type. Yo can use the date_format() function to convert a datetime field to your required output format (eg d/m/Y). Example My original table select * from deftest; +---------------------------------+ | test | +---------------------------------+ | Mon, 21 Nov 2022 10:05:13 +0200 | +---------------------------------+ Using the functions... select test as original , str_to_date(test, '%a, %d %b %Y %H:%i:%s') as asDatetime , date_format(str_to_date(test, '%a, %d %b %Y %H:%i:%s'), '%d/%m/%Y') as output from deftest; +---------------------------------+---------------------+------------+ | original | asDatetime | output | +---------------------------------+---------------------+------------+ | Mon, 21 Nov 2022 10:05:13 +0200 | 2022-11-21 10:05:13 | 21/11/2022 | +---------------------------------+---------------------+------------+
  24. The error message would have told which line the error was on. Perhaps you could tell us?
×
×
  • 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.