【发布时间】:2013-11-26 23:40:50
【问题描述】:
我不会声称确切地知道我在做什么,因为我不知道,这可能很明显。我试图将表单和更新数据库的功能保留在同一个文件中。我做错了什么?
以下是重要的部分:
HTML:
<form id="billing" action="?updatebilling" method="post">
PHP:
<!-- Function to update billing -->
<?php
function updatebilling() {
// Connecting to the MySQL server
$host="localhost";
$user_name="root";
$pwd="bluebox";
$database_name="rewired";
$db=mysql_connect($host, $user_name, $pwd) or die(mysql_error());
if (mysql_error() > "") print mysql_error() . "<br>";
mysql_select_db($database_name, $db);
if (mysql_error() > "") print mysql_error() . "<br>";
// Static info - account number
$account_id=users::getAttr('Account', 'account_id');
// Storing form values into PHP variables
$zip = mysql_real_escape_string($_POST['billingzip']);
$name = mysql_real_escape_string($_POST['name']);
// Inserting variables into database
$sql = "INSERT INTO `web_signup`
SET `account_id` = '{$account_id}',
`zip` = '{$billingzip}',
`cardholder_name` = '{$name}',
`updated_at` = NOW()";
$result = mysql_query($sql) or die(mysql_error().$sql);
mysql_close($db);
} ?>
【问题讨论】:
-
你遇到了什么错误?
-
应该将您的数据库连接保持在单独的安全页面上。此外,您不能将其用作表单操作。应该是
<form id='billing' action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>。如果您是游戏新手,请使用new mysqli()和面向对象的 PHP。它会节省大量的击键! -
那么你是如何调用函数的呢?您遇到了哪些具体问题?
-
这个函数如何访问静态的东西?