オンラインショップのログイン画面を作っています。
ユーザーがログインした後に、商品カテゴリをセレクトボックスから選べるようにしたいと思っています。
このセレクトボックスの中身はproduct_categoryテーブルから持ってくるようになっているのですが、データが入ってきません。
//product DB//の箇所のコードなのですが、何が間違っているのでしょうか?
php
1<?php 2session_start(); 3ini_set("include_path","./includes"); 4include("dbinfo.inc"); 5if(!isset($_SESSION['username'])) { 6 header("Location: login.php"); 7} 8 9 $logtime = date("H:i:s"); 10 11// ユーザーIDからユーザー名を取り出す 12$mysqli = new mysqli($host, $user, $passwd, $dbname); 13$sql = "SELECT * FROM login WHERE username='".$_SESSION['username']."'"; 14 15$result = $mysqli->query($sql); 16if (!$result) { 17 print('Cant execute query.' . $mysqli->error); 18 $mysqli->close(); 19 exit(); 20} 21 22// GET user info 23while ($row = $result->fetch_assoc()) { 24 $username = $row['username']; 25 $email = $row['email']; 26 $gen = $row['gen']; 27 } 28$sql = "UPDATE login SET logtime = NOW() WHERE username = '" . $_SESSION['username'] . "'"; 29 30$result = $mysqli->query($sql); 31if (!$result) { 32 print('Cant execute query.' . $mysqli->error); 33 $mysqli->close(); 34 exit(); 35} 36// Cut data base 37//$result->close(); 38 39//product DB// 40$sql = "SELECT * FROM product_category WHERE category='".$_SESSION['category']."'"; 41$result = $mysqli->query($sql); 42 43foreach((array)$category as $value) 44{ 45 $category_i = $value; 46 echo $_POST['category']; 47} 48if (!$result) { 49 print('Cant execute query.' . $mysqli->error); 50 $mysqli->close(); 51 exit(); 52} 53 54 55 /* 56 function get_the_category( $id = false ) { 57 $categories = get_the_terms( $id, 'category' ); 58 if ( ! $categories || is_wp_error( $categories ) ) 59 $categories = array(); 60 61 $categories = array_values( $categories ); 62 63 foreach ( array_keys( $categories ) as $key ) { 64 _make_cat_compat( $categories[$key] ); 65 } 66 }*/ 67 68 69?> 70 71<!DOCTYPE HTML> 72<html> 73<head> 74<title>Exercise6</title> 75<link rel="stylesheet" href="custom.css"> 76<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"> 77</head> 78<body> 79 <div class="col-xs-6 col-xs-offset-3"> 80 <h1>Online shop</h1><p>Username:<?php echo $username; ?></p> 81 82<select name="category"> 83 <option value="NULL">Choose One</option> 84 <?php echo "<option value='" .$category_i."' ". ($category_i == $value?'selected':'') .">".$value."</option>"; ?> 85</select> 86 87<br><br> 88 <button type="submit" class="btn btn-default" name="submit"><a href="login.php">Submit</a></button> 89 <button type="button" class="btn btn-default" name="logout"><a href="login.php">Logout</a></button> 90 91 92 </div> 93</body> 94</html>
テーブル名: product_discription
catalog_id INT(5) AUTO_INCREMENT. Primary key.Unique.
name VARCHAR(50)
description VARCHAR(500)
price DECIMAL(7,2)
category_id VARCHAR(10)
テーブル名: product_category
category_id INT(10) AUTO_INCREMENT. Primary key.Unique.
category VARCHAR(100) (category name)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/25 06:40
2017/05/25 07:00
2017/05/25 07:14 編集
2017/05/25 07:17
2017/05/25 07:29
2017/05/31 03:34 編集
2017/05/31 03:38