我正在使用jQuery表單來收集用戶數據,並且我試圖將表單值插入表ptb_registrations
。將表單數據插入MySQL?
我收到錯誤「錯誤更新數據庫」
有人能告訴我在哪裏,我錯了,請,這應該是相當簡單的。
HTML:
<form action="process_registration.php" method="post" id="reg_form">
<!-- #first_step -->
<div id="first_step">
<h1>SIGN UP FOR A FREE <span>ACTION-TIME.COM</span> ACCOUNT</h1>
<div class="form">
<input type="text" name="username" id="username" value="username" />
<label for="username">At least 4 characters. Uppercase letters, lowercase letters and numbers only.</label>
<input type="password" name="password" id="password" value="password" />
<label for="password">At least 4 characters. Use a mix of upper and lowercase for a strong password.</label>
<input type="password" name="cpassword" id="cpassword" value="password" />
<label for="cpassword">If your passwords aren’t equal, you won’t be able to continue with signup.</label>
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="submit" type="submit" name="submit_first" id="submit_first" value="" />
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<!-- #second_step -->
<div id="second_step">
<h1>SIGN UP FOR A FREE <span>WEBEXP18</span> ACCOUNT</h1>
<div class="form">
<input type="text" name="firstname" id="firstname" value="first name" />
<label for="firstname">Your First Name. </label>
<input type="text" name="lastname" id="lastname" value="last name" />
<label for="lastname">Your Last Name. </label>
<input type="text" name="email" id="email" value="email address" />
<label for="email">Your email address. We send important administration notices to this address. </label>
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="submit" type="submit" name="submit_second" id="submit_second" value="" />
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<!-- #third_step -->
<div id="third_step">
<h1>SIGN UP FOR A FREE <span>WEBEXP18</span> ACCOUNT</h1>
<div class="form">
<select id="age" name="age">
<option> 0 - 17</option>
<option>18 - 25</option>
<option>26 - 40</option>
<option>40+</option>
</select>
<label for="age">Your age range. </label> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<select id="gender" name="gender">
<option>Male</option>
<option>Female</option>
</select>
<label for="gender">Your Gender. </label> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<select id="country" name="country">
<option>United States</option>
<option>United Kingdom</option>
<option>Canada</option>
<option>Serbia</option>
<option>Italy</option>
</select>
<label for="country">Your country. </label> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="submit" type="submit" name="submit_third" id="submit_third" value="" />
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<!-- #fourth_step -->
<div id="fourth_step">
<h1>SIGN UP FOR A FREE <span>WEBEXP18</span> ACCOUNT</h1>
<div class="form">
<h2>Summary</h2>
<table>
<tr><td>Username</td><td></td></tr>
<tr><td>Password</td><td></td></tr>
<tr><td>Email</td><td></td></tr>
<tr><td>Name</td><td></td></tr>
<tr><td>Age</td><td></td></tr>
<tr><td>Gender</td><td></td></tr>
<tr><td>Country</td><td></td></tr>
</table>
</div> <!-- clearfix --><div class="clear"></div><!-- /clearfix -->
<input class="send submit" type="submit" name="submit_fourth" id="submit_fourth" value="" />
</div>
</form>
PHP/MySQL的:
<?php ob_start();
include '../includes/_config/connection.php';
$query="INSERT INTO ptb_registrations (ID,
username,
password,
firstname,
lastname,
email,
age,
gender,
country
)
VALUES('NULL',
'".$username."',
'".$password."',
'".$firstname."',
'".$lastname."',
'".$email."',
'".$age."',
'".$gender."',
'".$country."'
)";
mysql_query($query) or die ('Error updating database');
?>
<?php include ('includes/send_email/reg_email.php'); ?>
<? ob_flush(); ?>
http://php.net/manual/en/function.mysql-error.php會讓你在正確的軌道上。 – Sturm 2013-03-05 17:33:57
爲什麼不檢查錯誤信息? with或者die(mysql_error()); – Chris 2013-03-05 17:34:37
更改'mysql_query($ query)或死('錯誤更新數據庫');'到'mysql_query($ query)或死(mysql_error());'和發佈結果。 – 2013-03-05 17:35:03