打印出 MySQL 用户个人资料中的用户数据
Print out user's data from MySQL in profile user
我正在尝试将用户输入的数据打印到配置文件站点,但出了点问题我无法弄清楚为什么会出现此错误
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
我该怎么办....
在prfile.php中打印table的代码:
<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>");
?>
这样我就可以在 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);
}
?>
问题是在旧代码中我使用了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);
更新版本有 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);
我正在尝试将用户输入的数据打印到配置文件站点,但出了点问题我无法弄清楚为什么会出现此错误
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
我该怎么办....
在prfile.php中打印table的代码:
<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>");
?>
这样我就可以在 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);
}
?>
问题是在旧代码中我使用了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);
更新版本有 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);