佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1343|回复: 2

请求各位大大的帮助

[复制链接]
发表于 3-12-2009 10:41 AM | 显示全部楼层 |阅读模式
各位大大,小弟在做一个registration from,然后制作好后去测试时,就出现问题“Query failed”。
各位大大可以帮助小弟吗?以下的代码是registration-exec.php

  1. <?php
  2.         //Start session
  3.         session_start();
  4.         
  5.         //Include database connection details
  6.         require_once('config.php');
  7.         
  8.         //Array to store validation errors
  9.         $errmsg_arr = array();
  10.         
  11.         //Validation error flag
  12.         $errflag = false;
  13.         
  14.         //Connect to mysql server
  15.         $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  16.         if(!$link) {
  17.                 die('Failed to connect to server: ' . mysql_error());
  18.         }
  19.         
  20.         //Select database
  21.         $db = mysql_select_db(DB_DATABASE);
  22.         if(!$db) {
  23.                 die("Unable to select database");
  24.         }
  25.         
  26.         //Function to sanitize values received from the form. Prevents SQL injection
  27.         function clean($str) {
  28.                 $str = @trim($str);
  29.                 if(get_magic_quotes_gpc()) {
  30.                         $str = stripslashes($str);
  31.                 }
  32.                 return mysql_real_escape_string($str);
  33.         }
  34.         
  35.         //Sanitize the POST values
  36.         $mobile_number = clean($_POST['mobile_number']);
  37.         $name = clean($_POST['name']);
  38.         $ic = clean($_POST['ic']);
  39.         $address = clean($_POST['address']);
  40.         $telephone = clean($_POST['telephone']);
  41.         $mobile = clean($_POST['mobile']);
  42.         $email = clean($_POST['email']);
  43.         $occupation = clean($_POST['occupation']);
  44.         $industry = clean($_POST['industry']);
  45.         $mother_name = clean($_POST['mother_name']);
  46.         $reference_name = clean($_POST['reference_name']);
  47.         $reference_phone = clean($_POST['reference_phone']);
  48.         $relationship = clean($_POST['relationship']);
  49.         $sim = clean($_POST['sim']);
  50.         $redtone_mobile = clean($_POST['redtone_mobile']);
  51.         $bank = clean($_POST['bank']);
  52.         $bank_ac = clean($_POST['bank_ac']);
  53.         $bank_name = clean($_POST['bank_name']);
  54.         $upline_name = clean($_POST['upline_name']);
  55.         $upline_mobile = clean($_POST['upline_mobile']);
  56.         $file = clean($_POST['file']);
  57.         
  58.         
  59.         //Input Validations
  60.         if($mobile_number == '') {
  61.                 $errmsg_arr[] = 'Mobile Number missing';
  62.                 $errflag = true;
  63.         }
  64.         if($name == '') {
  65.                 $errmsg_arr[] = 'Name missing';
  66.                 $errflag = true;
  67.         }
  68.         if($ic == '') {
  69.                 $errmsg_arr[] = 'New NRIC missing';
  70.                 $errflag = true;
  71.         }
  72.         if($address == '') {
  73.                 $errmsg_arr[] = 'Address missing';
  74.                 $errflag = true;
  75.         }
  76.         if($mother_name == '') {
  77.                 $errmsg_arr[] = 'Mother Maiden Name missing';
  78.                 $errflag = true;
  79.         }
  80.         if($sim == '') {
  81.                 $errmsg_arr[] = 'Sim Serial Number missing';
  82.                 $errflag = true;
  83.         }
  84.         if($redtone_mobile == '') {
  85.                 $errmsg_arr[] = 'REDtone Mobile no missing';
  86.                 $errflag = true;
  87.         }
  88.         if($bank == '') {
  89.                 $errmsg_arr[] = 'Name Of Bank missing';
  90.                 $errflag = true;
  91.         }
  92.         if($bank_ac == '') {
  93.                 $errmsg_arr[] = 'Bank A/C No missing';
  94.                 $errflag = true;
  95.         }
  96.         if($bank_name == '') {
  97.                 $errmsg_arr[] = 'Bank A/C Name missing';
  98.                 $errflag = true;
  99.         }
  100.         if($file == '') {
  101.                 $errmsg_arr[] = 'File is missing';
  102.                 $errflag = true;
  103.         }

  104.         
  105.         
  106.         //Check for duplicate Mobile Number
  107.         if($mobile_number != '') {
  108.                 $qry = "SELECT * FROM register WHERE mobile_number='$mobile_number'";
  109.                 $result = mysql_query($qry);
  110.                 if($result) {
  111.                         if(mysql_num_rows($result) > 0) {
  112.                                 $errmsg_arr[] = 'Mobile Number already in use';
  113.                                 $errflag = true;
  114.                         }
  115.                         @mysql_free_result($result);
  116.                 }
  117.                 else {
  118.                         die("Query failed");
  119.                 }
  120.         }
  121.         
  122.         //If there are input validations, redirect back to the registration form
  123.         if($errflag) {
  124.                 $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  125.                 session_write_close();
  126.                 header("location: registration.php");
  127.                 exit();
  128.         }

  129.         //Create INSERT query
  130.         $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')";
  131.         $result = @mysql_query($qry);
  132.         
  133.         //Check whether the query was successful or not
  134.         if($result) {
  135.                 header("location: registration-success.php");
  136.                 exit();
  137.         }else {
  138.                 die("Query failed");
  139.         }
  140. ?>
复制代码

[ 本帖最后由 Samuelngu 于 3-12-2009 10:42 AM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 4-12-2009 02:47 AM | 显示全部楼层

回复 1# Samuelngu 的帖子

看看你的table structure...
回复

使用道具 举报

发表于 4-12-2009 07:37 PM | 显示全部楼层
echo 你的query出来去mysql run一run, 看有没有问题...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 25-4-2024 09:30 AM , Processed in 0.070485 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表