廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 3609 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為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.104494 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言