好吧所以我只是盯着使用pdo但我慢慢得到它的悬念我想知道如何制作一个下拉菜单或列表痘填充数据到页面上的字段我已经启动代码通过查找pdo指南等但我很难找到解决方案.也对不整洁的代码感到抱歉,但我又是整个编程场景的新手
谢谢你的建议到目前为止我的代码:这是连接字符串:
<?php
session_start();
if(!isset($_SESSION["user_id"])){
header("location:../Pages/login.html");
}
//databse connection Sting
$connection = new PDO("sqlsrv:server=servername;Database=databasename", "username", "password");
//insertion function
$smt = $connection->prepare('select exam_id From exam');
?>
Run Code Online (Sandbox Code Playgroud)
这也包括我的会话cookie,但是效果很好,这是我到目前为止的下拉框的人口.
<select name="lst_exam" id="lst_exam">
<?php
$smt->execute();
while ($row = $smt->fetch()){
echo "<option>" . $row["exam_id"] . "</option>";
}
$connection = null;
if(isset($_POST["lst_exam"]));
?>
</select>
Run Code Online (Sandbox Code Playgroud)
我试图填充的文本框是txt_exam_id,txt_location,txt_date_taken,txt_exam_taken,txt_grade_recieved
你好,由于某种原因,我的SQL服务器脚本给我一个语法错误,虽然代码工作之前,我不知道为什么我是新来的sql并已在网上看了但没有发现任何会修复它.由于某种原因,user_id是粉红色的,grade_recieved给了我一个错误.
create table exam(
exam_id varchar (10) not null,
user_id varchar (10) not null,
location varchar (30) not null,
date_taken varchar (8) not null,
exam_taken varchar (20) not null
grade_recieved varchar (4) not null,
primary key (exam_id),
FOREIGN KEY (user_id) REFERENCES account (user_id)
);
Run Code Online (Sandbox Code Playgroud)