|
各位大大,小弟在做一个registration from,然后制作好后去测试时,就出现问题“Query failed”。
各位大大可以帮助小弟吗?以下的代码是registration-exec.php
- <?php
- //Start session
- session_start();
-
- //Include database connection details
- require_once('config.php');
-
- //Array to store validation errors
- $errmsg_arr = array();
-
- //Validation error flag
- $errflag = false;
-
- //Connect to mysql server
- $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
- if(!$link) {
- die('Failed to connect to server: ' . mysql_error());
- }
-
- //Select database
- $db = mysql_select_db(DB_DATABASE);
- if(!$db) {
- die("Unable to select database");
- }
-
- //Function to sanitize values received from the form. Prevents SQL injection
- function clean($str) {
- $str = @trim($str);
- if(get_magic_quotes_gpc()) {
- $str = stripslashes($str);
- }
- return mysql_real_escape_string($str);
- }
-
- //Sanitize the POST values
- $mobile_number = clean($_POST['mobile_number']);
- $name = clean($_POST['name']);
- $ic = clean($_POST['ic']);
- $address = clean($_POST['address']);
- $telephone = clean($_POST['telephone']);
- $mobile = clean($_POST['mobile']);
- $email = clean($_POST['email']);
- $occupation = clean($_POST['occupation']);
- $industry = clean($_POST['industry']);
- $mother_name = clean($_POST['mother_name']);
- $reference_name = clean($_POST['reference_name']);
- $reference_phone = clean($_POST['reference_phone']);
- $relationship = clean($_POST['relationship']);
- $sim = clean($_POST['sim']);
- $redtone_mobile = clean($_POST['redtone_mobile']);
- $bank = clean($_POST['bank']);
- $bank_ac = clean($_POST['bank_ac']);
- $bank_name = clean($_POST['bank_name']);
- $upline_name = clean($_POST['upline_name']);
- $upline_mobile = clean($_POST['upline_mobile']);
- $file = clean($_POST['file']);
-
-
- //Input Validations
- if($mobile_number == '') {
- $errmsg_arr[] = 'Mobile Number missing';
- $errflag = true;
- }
- if($name == '') {
- $errmsg_arr[] = 'Name missing';
- $errflag = true;
- }
- if($ic == '') {
- $errmsg_arr[] = 'New NRIC missing';
- $errflag = true;
- }
- if($address == '') {
- $errmsg_arr[] = 'Address missing';
- $errflag = true;
- }
- if($mother_name == '') {
- $errmsg_arr[] = 'Mother Maiden Name missing';
- $errflag = true;
- }
- if($sim == '') {
- $errmsg_arr[] = 'Sim Serial Number missing';
- $errflag = true;
- }
- if($redtone_mobile == '') {
- $errmsg_arr[] = 'REDtone Mobile no missing';
- $errflag = true;
- }
- if($bank == '') {
- $errmsg_arr[] = 'Name Of Bank missing';
- $errflag = true;
- }
- if($bank_ac == '') {
- $errmsg_arr[] = 'Bank A/C No missing';
- $errflag = true;
- }
- if($bank_name == '') {
- $errmsg_arr[] = 'Bank A/C Name missing';
- $errflag = true;
- }
- if($file == '') {
- $errmsg_arr[] = 'File is missing';
- $errflag = true;
- }
-
-
- //Check for duplicate Mobile Number
- if($mobile_number != '') {
- $qry = "SELECT * FROM register WHERE mobile_number='$mobile_number'";
- $result = mysql_query($qry);
- if($result) {
- if(mysql_num_rows($result) > 0) {
- $errmsg_arr[] = 'Mobile Number already in use';
- $errflag = true;
- }
- @mysql_free_result($result);
- }
- else {
- die("Query failed");
- }
- }
-
- //If there are input validations, redirect back to the registration form
- if($errflag) {
- $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
- session_write_close();
- header("location: registration.php");
- exit();
- }
- //Create INSERT query
- $qry = "INSERT INTO members(mobile_number, name, ic, address, telephone, mobile, email, occupation, industry, mother_name, reference_name, reference_phone, relationship, sim, redtone_mobile, bank, bank_ac, bank_name, upline_name, upline_mobile, file) VALUES('$mobile_number','$name','$ic','$address','$telephone','$mobile','$email','$occupation','$industry','$mother_name','$reference_name','$reference_phone','$relationship','$sim','$redtone_mobile','$bank','$bank_ac','$bank_name','$upline_name','$upline_mobile','$file')";
- $result = @mysql_query($qry);
-
- //Check whether the query was successful or not
- if($result) {
- header("location: registration-success.php");
- exit();
- }else {
- die("Query failed");
- }
- ?>
复制代码
[ 本帖最后由 Samuelngu 于 3-12-2009 10:42 AM 编辑 ] |
|