广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 3622 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   
chris710908 手机 会员卡
个人文章 个人相簿 个人日记 个人地图
知名人士
级别: 知名人士 该用户目前不上站
推文 x15 鲜花 x128
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
推文 x0
[PHP][讨论] php插入新纪录问题?(已解决~多谢aa站长^^)
请问各位大大~小弟用dreamweaver做了问卷系统,
目前资料库有29个栏位~~如下
--------------------------------------------------------
会员代号   题项1   题项二....... 总分   会员类别
chris       2       3           52       ??
--------------------------------------------------------
目前的功能已经做到填完问卷递交后
可以记录论坛会员代号,问卷题项分数以及问卷加总分数~
请问如果想要再加入一段程式码~判断总分如果大于50分的话
在会员类别这个栏位插入"建设者";总分大于40分的话在
会员类别这个栏位插入"热衷者"。最终目的就是要能在填完问卷后
能同时记录论坛会员代号,问卷题项分数,问卷加总分数以及会员类别到资料库中
请大大帮帮忙~谢谢


我用dreaweaver插入纪录的功能~语法产生如下~~
复制程式
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO questionaire (username, item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14, item15, item16, item17, item18, item19, item20, item21, item22, item23, item24, item25, item26, item27, sum, class_name) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['N1'], "text"),
                       GetSQLValueString($_POST['N2'], "text"),
                       GetSQLValueString($_POST['N3'], "text"),
                       GetSQLValueString($_POST['N4'], "text"),
                       GetSQLValueString($_POST['N5'], "text"),
                       GetSQLValueString($_POST['N6'], "text"),
                       GetSQLValueString($_POST['N7'], "text"),
                       GetSQLValueString($_POST['N8'], "text"),
                       GetSQLValueString($_POST['N9'], "text"),
                       GetSQLValueString($_POST['N10'], "text"),
                       GetSQLValueString($_POST['N11'], "text"),
                       GetSQLValueString($_POST['N12'], "text"),
                       GetSQLValueString($_POST['N13'], "text"),
                       GetSQLValueString($_POST['N14'], "text"),
                       GetSQLValueString($_POST['N15'], "text"),
                       GetSQLValueString($_POST['N16'], "text"),
                       GetSQLValueString($_POST['N17'], "text"),
                       GetSQLValueString($_POST['N18'], "text"),
                       GetSQLValueString($_POST['N19'], "text"),
                       GetSQLValueString($_POST['N20'], "text"),
                       GetSQLValueString($_POST['N21'], "text"),
                       GetSQLValueString($_POST['N22'], "text"),
                       GetSQLValueString($_POST['N23'], "text"),
                       GetSQLValueString($_POST['N24'], "text"),
                       GetSQLValueString($_POST['N25'], "text"),
                       GetSQLValueString($_POST['N26'], "text"),
                       GetSQLValueString($_POST['N27'], "text"),
                                           GetSQLValueString($_POST['N21']+$_POST['N2']+$_POST['N3']+$_POST['N4']+$_POST['N5']+$_POST['N6']+$_POST['N7']+$_POST['N8']+$_POST['N9']+$_POST['N10']+$_POST['N11']+$_POST['N12']+$_POST['N13']+$_POST['N14']+$_POST['N15']+$_POST['N16']+$_POST['N17']+$_POST['N18']+$_POST['N19']+$_POST['N20']+$_POST['N21']+$_POST['N22']+$_POST['N23']+$_POST['N24']+$_POST['N25']+$_POST['N26']+$_POST['N27'], "text")
                                        
                                  );


  mysql_select_db($database_Q1, $Q1);
  $Result1 = mysql_query($insertSQL, $Q1) or die(mysql_error());

  $insertGoTo = "end.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}


[ 此文章被chris710908在2006-01-18 11:16重新编辑 ]



献花 x0 回到顶端 [楼 主] From:台湾台湾索尼 | Posted:2006-01-17 12:13 |
aa 手机 会员卡 葫芦墩家族
个人文章 个人相簿 个人日记 个人地图 个人商品
特殊贡献奖 社区建设奖
头衔:            
站长
级别: 站长 该用户目前不上站
推文 x1964 鲜花 x5260
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

你试试看这样
复制程式
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $sum=$_POST['N21']+$_POST['N2']+$_POST['N3']+$_POST['N4']+$_POST['N5']+$_POST['N6']+$_POST['N7']+$_POST['N8']+$_POST['N9']+$_POST['N10']+$_POST['N11']+$_POST['N12']+$_POST['N13']+$_POST['N14']+$_POST['N15']+$_POST['N16']+$_POST['N17']+$_POST['N18']+$_POST['N19']+$_POST['N20']+$_POST['N21']+$_POST['N22']+$_POST['N23']+$_POST['N24']+$_POST['N25']+$_POST['N26']+$_POST['N27'];
  if($sum>50) $class_name='建设者'
  elseif($sum>40) $class_name='热衷者'
  $insertSQL = sprintf("INSERT INTO questionaire (username, item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14, item15, item16, item17, item18, item19, item20, item21, item22, item23, item24, item25, item26, item27, sum, class_name) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['N1'], "text"),
                       GetSQLValueString($_POST['N2'], "text"),
                       GetSQLValueString($_POST['N3'], "text"),
                       GetSQLValueString($_POST['N4'], "text"),
                       GetSQLValueString($_POST['N5'], "text"),
                       GetSQLValueString($_POST['N6'], "text"),
                       GetSQLValueString($_POST['N7'], "text"),
                       GetSQLValueString($_POST['N8'], "text"),
                       GetSQLValueString($_POST['N9'], "text"),
                       GetSQLValueString($_POST['N10'], "text"),
                       GetSQLValueString($_POST['N11'], "text"),
                       GetSQLValueString($_POST['N12'], "text"),
                       GetSQLValueString($_POST['N13'], "text"),
                       GetSQLValueString($_POST['N14'], "text"),
                       GetSQLValueString($_POST['N15'], "text"),
                       GetSQLValueString($_POST['N16'], "text"),
                       GetSQLValueString($_POST['N17'], "text"),
                       GetSQLValueString($_POST['N18'], "text"),
                       GetSQLValueString($_POST['N19'], "text"),
                       GetSQLValueString($_POST['N20'], "text"),
                       GetSQLValueString($_POST['N21'], "text"),
                       GetSQLValueString($_POST['N22'], "text"),
                       GetSQLValueString($_POST['N23'], "text"),
                       GetSQLValueString($_POST['N24'], "text"),
                       GetSQLValueString($_POST['N25'], "text"),
                       GetSQLValueString($_POST['N26'], "text"),
                       GetSQLValueString($_POST['N27'], "text"),
                                           GetSQLValueString($_POST['N21']+$_POST['N2']+$_POST['N3']+$_POST['N4']+$_POST['N5']+$_POST['N6']+$_POST['N7']+$_POST['N8']+$_POST['N9']+$_POST['N10']+$_POST['N11']+$_POST['N12']+$_POST['N13']+$_POST['N14']+$_POST['N15']+$_POST['N16']+$_POST['N17']+$_POST['N18']+$_POST['N19']+$_POST['N20']+$_POST['N21']+$_POST['N22']+$_POST['N23']+$_POST['N24']+$_POST['N25']+$_POST['N26']+$_POST['N27'], "text"),
                                           '$class_name'
                                        
                                  );


  mysql_select_db($database_Q1, $Q1);
  $Result1 = mysql_query($insertSQL, $Q1) or die(mysql_error());

  $insertGoTo = "end.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}


献花 x0 回到顶端 [1 楼] From:台湾台湾固网 | Posted:2006-01-18 08:25 |
chris710908 手机 会员卡
个人文章 个人相簿 个人日记 个人地图
知名人士
级别: 知名人士 该用户目前不上站
推文 x15 鲜花 x128
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片

表情 谢谢站长相助~刚刚看了站长的原始码~才知道自己的逻辑错误了@@
刚刚测试了一下~~有些小问题~显示这class_name栏位未知~~然后修改成
GetSQLValueString($class_name,"text") 就可以了~~
感谢站长相助~~ 表情          



复制程式
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $sum=$_POST['N21']+$_POST['N2']+$_POST['N3']+$_POST['N4']+$_POST['N5']+$_POST['N6']+$_POST['N7']+$_POST['N8']+$_POST['N9']+$_POST['N10']+$_POST['N11']+$_POST['N12']+$_POST['N13']+$_POST['N14']+$_POST['N15']+$_POST['N16']+$_POST['N17']+$_POST['N18']+$_POST['N19']+$_POST['N20']+$_POST['N21']+$_POST['N22']+$_POST['N23']+$_POST['N24']+$_POST['N25']+$_POST['N26']+$_POST['N27'];
  if($sum>=116) {$class_name='热衷者'}
  elseif($sum>=105) {$class_name='意见领袖者'
  ;}elseif($sum>=102) {$class_name='建设者'}
  elseif($sum>=89) {$class_name='潜伏者'}else{$class_name='抒发情感者'}
  $insertSQL = sprintf("INSERT INTO questionaire (username, item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14, item15, item16, item17, item18, item19, item20, item21, item22, item23, item24, item25, item26, item27, sum, class_name) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['N1'], "text"),
                       GetSQLValueString($_POST['N2'], "text"),
                       GetSQLValueString($_POST['N3'], "text"),
                       GetSQLValueString($_POST['N4'], "text"),
                       GetSQLValueString($_POST['N5'], "text"),
                       GetSQLValueString($_POST['N6'], "text"),
                       GetSQLValueString($_POST['N7'], "text"),
                       GetSQLValueString($_POST['N8'], "text"),
                       GetSQLValueString($_POST['N9'], "text"),
                       GetSQLValueString($_POST['N10'], "text"),
                       GetSQLValueString($_POST['N11'], "text"),
                       GetSQLValueString($_POST['N12'], "text"),
                       GetSQLValueString($_POST['N13'], "text"),
                       GetSQLValueString($_POST['N14'], "text"),
                       GetSQLValueString($_POST['N15'], "text"),
                       GetSQLValueString($_POST['N16'], "text"),
                       GetSQLValueString($_POST['N17'], "text"),
                       GetSQLValueString($_POST['N18'], "text"),
                       GetSQLValueString($_POST['N19'], "text"),
                       GetSQLValueString($_POST['N20'], "text"),
                       GetSQLValueString($_POST['N21'], "text"),
                       GetSQLValueString($_POST['N22'], "text"),
                       GetSQLValueString($_POST['N23'], "text"),
                       GetSQLValueString($_POST['N24'], "text"),
                       GetSQLValueString($_POST['N25'], "text"),
                       GetSQLValueString($_POST['N26'], "text"),
                       GetSQLValueString($_POST['N27'], "text"),
                       GetSQLValueString($_POST['N21']+$_POST['N2']+$_POST['N3']+$_POST['N4']+$_POST['N5']+$_POST['N6']+$_POST['N7']+$_POST['N8']+$_POST['N9']+$_POST['N10']+$_POST['N11']+$_POST['N12']+$_POST['N13']+$_POST['N14']+$_POST['N15']+$_POST['N16']+$_POST['N17']+$_POST['N18']+$_POST['N19']+$_POST['N20']+$_POST['N21']+$_POST['N22']+$_POST['N23']+$_POST['N24']+$_POST['N25']+$_POST['N26']+$_POST['N27'], "text"),GetSQLValueString($class_name,"text")
                                      );


  mysql_select_db($database_Q1, $Q1);
  $Result1 = mysql_query($insertSQL, $Q1) or die(mysql_error());

  $insertGoTo = "end.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}



献花 x0 回到顶端 [2 楼] From:台湾台湾索尼 | Posted:2006-01-18 11:14 |

首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.060965 second(s),query:16 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言