Skip to content
Advertisement

Print out user’s data from MySQL in profile user [closed]

Am trying to print out users’s inputted data to profile site, but there is something wrong I cannot figure out why this error

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in /home2-1/n/noorja/public_html/WSK12021/OTIUM-backup/OTIUM02-sandbox/profile.php:49 Stack trace: #0 /home2-1/n/noorja/public_html/WSK12021/OTIUM-backup/OTIUM02-sandbox/profile.php(49): PDOStatement->execute(Array) #1 {main} thrown in /home2-1/n/noorja/public_html/WSK12021/OTIUM-backup/OTIUM02-sandbox/profile.php on line 49

What should I do….

The code to print the table in prfile.php:

<h2>Report</h2>
<?php
//kirjautuneen käyttäjän userID?
    $data1['email'] = $_SESSION['semail'];
    
    //var_dump($data1);
    $sql1 = "SELECT id FROM otium where email =  :email";
    $kysely1=$DBH->prepare($sql1);
    $kysely1->execute($data1);
    $tulos1=$kysely1->fetch();
    $currentUserID=$tulos1[0];

    // Print out calnder data, what currentUser has inputted
$data3['title'] = $currentUserID;
$sql3 = "SELECT 'title', 'start' FROM tbl_events WHERE userID = :userID  DESC LIMIT 30";
$kysely3=$DBH->prepare($sql3);
$kysely3->execute($data3);              

    echo("<table>
        <tr>
            <th>Diary input</th>
      <th>Input date</th>
        </tr>");
    
        while   ($row=$kysely3->fetch()){   
                echo("<tr><td>".$row["title"]."</td>
                <td>".$row["start"]."</td>
                </tr>");
        }
    
  echo("</table>");
  
?>

This way I add events in my calendar.php

<?php session_start(); ?>
<?php

    require_once "db.php";

    $title = isset($_POST['title']) ? $_POST['title'] : "";
    $start = isset($_POST['start']) ? $_POST['start'] : "";
    $end = isset($_POST['end']) ? $_POST['end'] : "";


//kirjautuneen käyttäjän userID?
$data2['email'] = $_SESSION['semail'];
//var_dump($data1);
$sql1 = "SELECT id FROM otium where email =  :email";
$kysely1 = $DBH->prepare($sql1);
$kysely1->execute($data2);
$tulos1 = $kysely1->fetch();

$data1['userID']=$tulos1[0];

    try { 
    //Tiedot kantaan

        $data1['title'] = $_POST['title'];
        $data1['start'] = $_POST['start'];
        $data1['end'] = $_POST['end'];

        $STH = $DBH->prepare("INSERT INTO tbl_events (title, start, end, userID) VALUES (:title, :start, :end, :userID);");
        $STH->execute($data1);


    file_put_contents('log/DBErrors.txt', "Merkintä on:"  . $title . "  " . $start . "  " . $end . "  " .' id '.$data1['userID'].' email '.$_SESSION['semail']);
    if (! $result) {
        $result = mysqli_error($DBH);
    }

    } catch(PDOException $e) {
        echo "Yhteysvirhe: " . $e->getMessage(); 
        file_put_contents('log/DBErrors.txt', 'Connection: '.$e->getMessage()."n", FILE_APPEND);
    }

?>

Advertisement

Answer

The problem was that in the old code I used title

// Print out calnder data, what currentUser has inputted
$data3['title'] = $currentUserID;
$sql3 = "SELECT title, start FROM tbl_events WHERE userID = :userID";
$kysely3=$DBH->prepare($sql3);
$kysely3->execute($data3);  

Updated version has userID:

// Print out calnder data, what currentUser has inputted
$data3['userID'] = $currentUserID;
$sql3 = "SELECT title, start FROM tbl_events WHERE userID = :userID";
$kysely3=$DBH->prepare($sql3);
$kysely3->execute($data3);  
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement