【php开源代码栏目提醒】:以下是网学会员为您推荐的php开源代码-voteAddItem.php,希望本篇文章对您学习有所帮助。
<?php require_once('Connections/connVoteSystem.php'); ?>
<?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 .= "?" . $_SERVER['QUERY_STRING'];
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO voteitem (vote_id, vote_item) VALUES (%s, %s)",
GetSQLValueString($_POST['vote_id'], "int"),
GetSQLValueString($_POST['vote_item'], "text"));
mysql_select_db($database_connVoteSystem, $connVoteSystem);
$Result1 = mysql_query($insertSQL, $connVoteSystem) or die(mysql_error());
$insertGoTo = "voteAddItem.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE voteitem SET vote_item=%s WHERE voteitem_id=%s",
GetSQLValueString($_POST['vote_item'], "text"),
GetSQLValueString($_POST['voteitem_id'], "int"));
mysql_select_db($database_connVoteSystem, $connVoteSystem);
$Result1 = mysql_query($updateSQL, $connVoteSystem) or die(my
sql_error());
$updateGoTo = "voteAddItem.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_RecVoteItem = "1";
if (isset($_GET['vote_id'])) {
$colname_RecVoteItem = (get_magic_quotes_gpc()) ? $_GET['vote_id'] : addslashes($_GET['vote_id']);
}
mysql_select_db($database_connVoteSystem, $connVoteSystem);
$query_RecVoteItem = sprintf("SELECT * FROM voteitem WHERE vote_id = %s", $colname_RecVoteItem);
$RecVoteItem = mysql_query($query_RecVoteItem, $connVoteSystem) or die(mysql_error());
$row_RecVoteItem = mysql_fetch_assoc($RecVoteItem);
$totalRows_RecVoteItem = mysql_num_rows($RecVoteItem);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>投票
系统</title>
<script language="JavaScript" type="text/
JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0)