我不會聲稱完全知道我在做什麼,因爲我不這樣做,那可能很明顯。我試圖保持窗體和函數更新數據庫在同一個文件中。我究竟做錯了什麼?HTML表單和PHP函數將表單數據保存到同一文件/頁面中的mysql
這裏是重要的位:
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);
} ?>
您收到了哪些錯誤? –
應該保持您的數據庫連接在一個單獨的安全頁面上。此外,您不能將其用作表單操作。應該是'
那麼你怎麼實際調用這個函數呢?你有什麼具體問題? –