【发布时间】:2014-01-17 20:05:43
【问题描述】:
由于某种原因,我似乎无法获取插入 php 和 mysql 的数据。
我有一个带有连接字符串的init.php,一个order.php 文件,最后一个band_list.php。
我在将数据导入数据库时遇到了一些问题。
数据库有3个表:
order it has id, order_id and band_id columns
users it has id, name and password columns
bands it has Band_id, name and stock columns
band_list.php 向用户显示了乐队演出的详细信息。
<?php
require 'core/init.php';
$Band_id = $_GET['id'];
$result = mysql_query("SELECT * FROM bands WHERE Band_id = $Band_id");
echo "<table border = '1'>
<tr>
<th>Band Name</th>
<th>Venue</th>
<th>Category</th>
<th>Stock</th>
<th>Add</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr><form name=\"myform\" action=\" order.php\" method=\"post\">";
echo "<td> <input name=\"band\" type=\"hidden\" value=\"". $Band_id."\" ></td>";
echo "<td>" .$row['Name']. "</td>";
echo "<td>" .$row['Venue']. "</td>";
echo "<td>" .$row['Category']. "</td>";
echo "<td>" .$row['Stock']. "</td>";
echo "<td><button>Buy Ticket</button></td>";
echo "<td><input type=\" submit\" value=\"Buy Ticket\"></td>";
echo "</tr> </form>";
}
echo "</table>";
?>
order.php 具有用于将数据发送到数据库的查询
<?php
require 'core/init.php';
session_start();
$Band_id = $_REQUEST['Band_id'];
$user_id = $_SESSION['user_id'];
$sql = "INSERT INTO orders (band_id,user_id) VALUES($Band_id,$user_id)";
mysql_query ($sql, $linkme)
or die ("could not add to database");
?>
并且连接字符串在一个初始化文件中。
所以这个想法是,当用户点击购买票时,它会获取当前的Band_id 和 user_id 并将它们插入数据库 table orders 到列 band_id 和 user_id 中。
这不是快乐我只是得到我的或死("could not add to database");字符串出现。
我的做法有问题吗?
【问题讨论】: