0

The query is not being carried out, would you be so kind as to guide me on my error?

<?php

require "conection.php";

$mi_busqueda = $_POST['mi_busqueda'];

$insert_query = $con->prepare("INSERT INTO hist_less_cred (id_student)
SELECT id_student
FROM students
WHERE student_qr = ?");
$insert_query->bind_param("is", $mi_busqueda);
$insert_query->execute();

header ('Location: qr_lector.php');
exit();

?> 

the insert inside the other table does not carry it out

  • 1
    `SELECT id_student, ?` - What's with the `?` you've placed there? `$insert_query->bind_param("is", $mi_busqueda);` - You define the type for two different values, but only pass in one. Not sure why you need the `SELECT` in that `INSERT` when you already have the `id_student` from the first select. When you say "did not work", you _always_ need to explain what that mean. You should also include what debugging you've done. Getting errors? Checked the webservers error log? – M. Eriksson Sep 19 '22 at 06:17
  • One obvious error is you have 2 placeholders in the query, 2 type definitions, but only one variable in the bind_param. There could be other errors as well. You need to configure mysqli error reporting that'll help you to debug all problems – Your Common Sense Sep 19 '22 at 06:43
  • Also, the logic behind the initial question is incomprehensible. Given you tried the 3rd query alone "and it did not work either", why mention the first two at all? – Your Common Sense Sep 19 '22 at 06:46
  • make the change you mentioned to me, place that ? moreover, now I have some doubts regarding what you tell me, how can I use the value already brought from the last query, from the select and how can I check the webservers error log, sorry but I'm new to this, believe me I'm a senior or at least a junior would not be asking this –  Sep 19 '22 at 06:47
  • You can fetch it, [the usual way](https://stackoverflow.com/a/14625134/285587). Also, to mention someone, start their name with @, like `@YourCommonSense` – Your Common Sense Sep 19 '22 at 07:12

0 Answers0