macromedia.dreamweaver
[Top] [All Lists]

multiple choise and update mysql

Subject: multiple choise and update mysql
From: "Marco"
Date: Thu, 31 Dec 2009 16:02:29 +0100
Newsgroups: macromedia.dreamweaver


I am using dreamweaver CS4, php and mysql

I want to be able to select multiple items in a listbox and insert multiple 
records in the database just in one click.  For example if i have three 
absent people i want to be able to select that three people from the listbox 
, click the submit button and then all of the selected people would be added 
as absent all at once (hope you understand what i'm getting at)

At the moment i can have my listbox and  i can select more people all at 
once but only the first has added on database.

What can I do?

Here is my code

[PHP]<?php require_once('Connections/server.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", 
$theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : 
$theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? 
mysql_real_escape_string($theValue) : mysql_escape_string($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 partecipanti (evento, username, 
presente) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['evento'], "text"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['presente'], "int"));

  mysql_select_db($database_server, $server);
  $Result1 = mysql_query($insertSQL, $server) or die(mysql_error());

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

mysql_select_db($database_server, $server);

$colname_senzarisposta = "-1";
if (isset($_GET['id'])) {
  $colname_senzarisposta = $_GET['id'];
}
mysql_select_db($database_server, $server);
$query_senzarisposta = sprintf("SELECT username, hash, fname, lname FROM 
calendar_users WHERE hash NOT IN (SELECT username FROM partecipanti WHERE 
evento = %s)", GetSQLValueString($colname_senzarisposta, "text"));
$senzarisposta = mysql_query($query_senzarisposta, $server) or 
die(mysql_error());
$row_senzarisposta = mysql_fetch_assoc($senzarisposta);
$totalRows_senzarisposta = mysql_num_rows($senzarisposta);

$colname_elencosenzarisposta = "-1";
if (isset($_GET['id'])) {
  $colname_elencosenzarisposta = $_GET['id'];
}
mysql_select_db($database_server, $server);
$query_elencosenzarisposta = sprintf("SELECT username, hash, fname, lname 
FROM calendar_users WHERE hash NOT IN (SELECT username FROM partecipanti 
WHERE evento = %s)", GetSQLValueString($colname_elencosenzarisposta, 
"int"));
$elencosenzarisposta = mysql_query($query_elencosenzarisposta, $server) or 
die(mysql_error());
$row_elencosenzarisposta = mysql_fetch_assoc($elencosenzarisposta);
$totalRows_elencosenzarisposta = mysql_num_rows($elencosenzarisposta);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento senza titolo</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" 
id="form1">


<table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">name</td>
      <td><select name="username" size="12">
        <option value="value">choose people</option>
        <?php
do {
?>
        <option value="<?php echo $row_elencosenzarisposta['hash']?>"><?php 
echo $row_elencosenzarisposta['fname']?></option>
        <?php
} while ($row_elencosenzarisposta = 
mysql_fetch_assoc($elencosenzarisposta));
  $rows = mysql_num_rows($elencosenzarisposta);
  if($rows > 0) {
      mysql_data_seek($elencosenzarisposta, 0);
      $row_elencosenzarisposta = mysql_fetch_assoc($elencosenzarisposta);
  }
?>
      </select></td>
    </tr>
    <tr> </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td valign="baseline"><table>
        <tr>
          <td><input type="radio" name="presente" value="1" />
            not absent</td>
        </tr>
        <tr>
          <td><input type="radio" name="presente" value="0" />
            absent</td>
        </tr>
      </table></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="update" /></td>
    </tr>
  </table>
    <input type="hidden" name="evento" value="<?php echo $_GET['id']; ?>" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>[/PHP] 



<Prev in Thread] Current Thread [Next in Thread>
  • multiple choise and update mysql, Marco <=