skip to Main Content

I am currently working on a project that is to display data that come from a MySQL database

I realized a script in PHP which is composed of 3 buttons, which is characterized by a value of the database.

I call the table enc_type which has as number 012

0 = Sale taken away

1 = Sale in delivery

2 = Sale on site

My goal would be to display the data via a button when I click desuss

But when I execute my code, I have this error that appears:

Fatal error: Uncaught TypeError: Unsupported operand types: string +
string in C:xampphtdocsECRANecran.php:75 Stack trace: #0
C:xampphtdocsECRANecran.php(57): functionSQL1() #1 {main} thrown in
C:xampphtdocsECRANecran.php on line 75

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="css/ecran.css">
    <title>ECRAN-VAE</title>
</head>
<body>
        <center>
            <div id="heure">
                <script>
                    function startTime() {
                    var today = new Date();
                    var h = today.getHours();
                    var m = today.getMinutes();
                    m = checkTime(m);
                    document.getElementById('heure').innerHTML =
                    ""+h + ":" + m;
                    var t = setTimeout(startTime, 500);
                    }
                    function checkTime(i) {
                    if (i < 10) {i = "0" + i};  
                    return i;
                    }
                    startTime();
                </script>
            </div>
    </center>

    <?php
 // Connexion à la base de données via ODBC
 $dsn = "";
 $user = "";
 $password = "";
 $conn = odbc_connect($dsn, $user, $password);
 // Vérifier si la connexion a réussi
 if (!$conn) {
     die("Erreur de connexion à la base de données: " . odbc_errormsg());
 }
 // Fonction pour exécuter une requête SQL
 function executerRequete($conn, $sql)
 {
     $result = odbc_exec($conn, $sql);
     // Vérifier si la requête a réussi
     if (!$result) {
         die("Erreur d'exécution de la requête: " . odbc_errormsg());
     }
     return $result;
 }
 // Vérifier si un bouton a été cliqué
 if (isset($_POST["bouton"])) {
     $enc_type = $_POST["bouton"];
     // Exécuter la fonction SQL correspondante en fonction de la valeur de enc_type
     switch ($enc_type) {
         case "0":
             fonctionSQL1();
             break;
         case "1":
             fonctionSQL2();
             break;
         case "2":
             fonctionSQL3();
             break;
         default:
             echo "Bouton invalide.";
     }
 }
 // Fonction SQL 1
 function fonctionSQL1()
 {
     global $conn;
     $sql =
         "SELECT * FROM FROM Client RIGHT JOIN encaissement ON Client.cli_id = encaissement.enc_client WHERE enc_etat<>4 AND enc_date= convert(date,getdate()) AND ((DATEDIFF(n,enc_heure_fab_fin, getDate()) < 3 AND enc_prepared <> 0) OR enc_prepared = 0) AND enc_emporte <> 1 " +
         " ORDER BY encaissement.enc_heure_fab_deb ASC";
     $resultat = executerRequete($conn, $sql);
 }
 // Fonction SQL 2
 function fonctionSQL2()
 {
     global $conn;
     $sql =
         "SELECT * FROM FROM Client RIGHT JOIN encaissement ON Client.cli_id = encaissement.enc_client WHERE enc_etat<>4 AND enc_date= convert(date,getdate()) AND ((DATEDIFF(n,enc_heure_fab_fin, getDate()) < 3 AND enc_prepared <> 0) OR enc_prepared = 0) AND enc_emporte <> 1 " +
         " ORDER BY encaissement.enc_heure_fab_deb ASC";
     $resultat = executerRequete($conn, $sql);
     // Faites quelque chose avec le résultat de la requête
     // ...
 }
 // Fonction SQL 3
 function fonctionSQL3()
 {
     global $conn;
     $sql =
         "SELECT * FROM FROM Client RIGHT JOIN encaissement ON Client.cli_id = encaissement.enc_client WHERE enc_etat<>4 AND enc_date= convert(date,getdate()) AND ((DATEDIFF(n,enc_heure_fab_fin, getDate()) < 3 AND enc_prepared <> 0) OR enc_prepared = 0) AND enc_emporte <> 1 " +
         " ORDER BY encaissement.enc_heure_fab_deb ASC";
     $resultat = executerRequete($conn, $sql);
     // Faites quelque chose avec le résultat de la requête
     // ...
 }
 // Fermer la connexion à la base de données
 odbc_close($conn);
 ?>

<!DOCTYPE html>
<html>
<head>
    <title>Exemple de boutons et fonctions SQL via ODBC</title>
</head>
<body>
    <div class="BOUTON">
        <form method="post" action="">
            <button type="submit" name="bouton" value="0">VENTE EMPORTER</button>
            <button type="submit" name="bouton" value="1">VENTE EN LIVRAISON</button>
            <button type="submit" name="bouton" value="2">VENTE SUR PLACE</button>
        </form>
    </div>
</body>
</html>

2

Answers


  1. You cannot concatenate strings with "+" -operator in PHP. You should use "." instead.

    So, for example

    "SELECT * FROM FROM Client RIGHT JOIN encaissement ON Client.cli_id = encaissement.enc_client WHERE enc_etat<>4 AND enc_date= convert(date,getdate()) AND ((DATEDIFF(n,enc_heure_fab_fin, getDate()) < 3 AND enc_prepared <> 0) OR enc_prepared = 0) AND enc_emporte <> 1 " +
             " ORDER BY encaissement.enc_heure_fab_deb ASC";
    

    should be

    "SELECT * FROM FROM Client RIGHT JOIN encaissement ON Client.cli_id = encaissement.enc_client WHERE enc_etat<>4 AND enc_date= convert(date,getdate()) AND ((DATEDIFF(n,enc_heure_fab_fin, getDate()) < 3 AND enc_prepared <> 0) OR enc_prepared = 0) AND enc_emporte <> 1 " .
                 " ORDER BY encaissement.enc_heure_fab_deb ASC";
    
    Login or Signup to reply.
  2. Wrong syntax about concatenation operator.

    Check the official documentation:
    https://www.php.net/manual/en/language.operators.string.php

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search