PHPとMySQLを連結させてログイン画面とメインページを作成したのですが、データベースに入力したデータを入力すると
Parse error: syntax error, unexpected identifier "name", expecting "]"in C:\xampp\htdocs\課題7\r\main.php on line 11
というエラーがでます。
原因の箇所を修正しても同じエラーが出るのでどこが原因なのでしょうか?
login.php
php
1```<!DOCTYPE html> 2<html> 3<head> 4<meta charset="UTF-8"> 5<title>ログイン</title> 6<link rel="stylesheet" href="../style.css"> 7<link rel="stylesheet" href="style.css"> 8</head> 9<body> 10 11<form action="main.php" method="post" autocomplete="off"> 12年<input type="number" name="year" ><br> 13組<input type="number" name="class"><br> 14出席番号<input type="number" name="number_id" ><br> 15名前<input type="text" name="name"><br> 16パスワード<input type="password" name="password" ><br> 17 18 19<input type="submit" value="ログイン"> 20</form> 21</body> 22</html> 23 24 25 26main.php 27 28<!DOCTYPE html> 29<html> 30<head> 31<meta charset="UTF-8"> 32<title>メイン画面</title> 33<link rel="stylesheet" href="../style.css"> 34<link rel="stylesheet" href="style.css"> 35</head> 36<body> 37 38<?php session_start();?> 39<?php require '../header.php';?> 40<?php 41unset($_SESSION['user_table']); 42$pdo=new PDO('mysql:host=localhost;dbname=english word;charset=utf8', 43'staff','password'); 44$sql=$pdo->prepare('select * from user_table where year=? and class=? and 45number_id=? and name=? and password=?'); 46 47$sql->execute([$_REQUEST['year'],$_REQUEST['class'],$_REQUEST['number_id], 48$_REQUEST['name'],$_REQUEST['password']]); 49 50foreach ($sql as $row) { 51 $_SESSION['user_table']=[ 52 'year'=>$row['year'], 'class'=>$row['class'], 53 'number_id'=>$row['number_id'], 'name'=>$row['name'], 54 'password'=>$row['password']]; 55} 56 57 58 59if(isset($_SESSION['user_table'])){ 60 if($_REQUEST['year']==0){ 61echo "先生"; 62}else{ 63echo"生徒"; 64} 65}else{ 66echo "エラー"; 67} 68?> 69</body> 70</html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。