前提・実現したいこと
php、データベースについて質問します。昨日にphpの表示部分に入力した値がデータベースに登録できるというシステムを作り、昨日は実行できました、しかし、今日こちらの事情によりxamppを消し、再インストールをして、データをすべて移し終えました、そしてphpとデーターベースが使用可能となり、追加しようとして昨日作っておいたプログラムを作動させたところ追加されなかったです。
データベースにsampleと言うプログラムをあらかじめ作成してそこに昨日作っておたphpプログラムで追加するというものです。
該当のソースコード
昨日作っておいたコードです。
php
1index.php(処理部分) 2<?php 3$local='localhost'; 4$user_name='root'; 5$pass=''; 6$db_name='ph23_sample'; 7$sql=''; 8 9 if(isset($_GET['botton'])){ 10 $name=$_GET['name']; 11 $age=$_GET['age']; 12 13 $link=mysqli_connect($local,$user_name,$pass,$db_name); 14 mysqli_set_charset($link,'utf8'); 15 //これがベース!! 16 $sql=mysqli_query($link,"INSERT INTO sample(name,age)VALUES('".$name."',".$age.")"); 17 mysqli_close($link); 18 require_once 'index2.php'; 19 20 exit; 21 }else{ 22 require_once 'index1.php'; 23 24 exit; 25 } 26 ?> 27//$sqlの中にはtrueが入っています。
php
1index1(最初に画面が出る入力部分) 2<!DOCTYPE html> 3<html lang="en"> 4<head> 5 <meta charset="UTF-8"> 6 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 <title>Document</title> 9</head> 10<body> 11<form action="index.php" nethod="get"> 12 氏名<input type="text" name="name"><br> 13 年齢<input type="text" name="age"><br> 14 15 <input type="submit" name='botton' value='登録'> 16</form> 17 18</body> 19</html>
php
1index2.php(index1.phpのボタンが押された際に飛ぶ表示部分) 2<!DOCTYPE html> 3<html lang="en"> 4<head> 5 <meta charset="UTF-8"> 6 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 <title>Document</title> 9</head> 10<body> 11 <p>登録完了</p> 12</body> 13</html>
試したこと
昨日の時点でできてたことが急にできなくなったからなぜだか理由がわかりません。何を試したらいいかわかりません。教えてほしいです。
昨日できていたことはすべて試しました。
回答2件
あなたの回答
tips
プレビュー