duanbi3385 2014-01-17 14:29 采纳率: 100%
浏览 45
已采纳

php使用insert语句添加到数据库

I have a simple insert statement that should use $GLOBALS that has my connection string in. Problem is that it does not insert the data. Have I done this correctly?

Insert.php

<?php
require 'core/init.php';

$Name = $_REQUEST["Name"];
$Venue = $_REQUEST["Venue"];
$Category = $_REQUEST["Category"];

$query = "INSERT INTO bands (Name, Venue, Category)
          VALUES ('$Name', '$Venue', '$Category')";
mysql_query ($query,$GLOBALS)
    or die ("could not add to database");

echo("You have added: <br />");
$result = mysql_query("SELECT * FROM bands ORDER  BY  Band_id DESC LIMIT 1");

while($row = mysql_fetch_array($result))
{
    echo $row['Name']. "" . $row['Venue']. "" . $row['Category'];
    echo "<br />";
}
?>
  • 写回答

2条回答 默认 最新

  • douhuang9886 2014-01-17 14:32
    关注

    You don't put whole $GLOBALS variable in your mysql_query() call. You put the specific variable with the connection string only:

    mysql_query($query, $GLOBALS['connection']) // Assuming you called the connection var "connection"
        or die ("could not add to database");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据