variabili di sessione con ciclo while

ertrottola

Utente Attivo
10 Ago 2011
81
0
0
Salve a tutti, sono nuovo sia sul forum, che fresco di programmazione di php:mavieni:
se non disturbo vorrei capire il perchè e risolvere questo problema.

questo è il codice della prima pagina, che contiene un ciclo while e un form con delle check dove recupero i dati nel mio database.
e qui mi da una notice che la variabile $row_Rs_portate['id'] non è definita,

PHP:
  <form action="preventivo.php" method="post">  <?php do { ?>
        <h4>Aperitivi </h4>
        <div id="aperitivi">
       
          <<input name="myCheck[<?php  echo $row_Rs_portate['id']; ?>]" type="checkbox" <?php echo (isset($_SESSION['myCheck'][$row_Rs_portate['id']])) ? "checked=\"checked\" ":""; ?> value="<?php echo $row_Rs_portate['aperitivi']; ?>" /> 
          <?php echo $row_Rs_portate['aperitivi'];
		  $row_Rs_portate['id']
		   ?>
     
      </div>
      <?php } while ($row_Rs_portate = mysql_fetch_assoc($Rs_portate)); ?>

Questa è la pagina dove recupero i valori delle checkbox, ma mi da un errore che le variabili non sono definite, e quindi non mi tira fuori i dati
Dove sto sbagliando?
grazie per l'aiuto

PHP:
<?php
$_SESSION['myCheck'] = $_POST['myCheck'];
foreach ($myCheck as $key => $value) { 
    echo "$value<br />"; 
} 
?>
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
così ad occhio e croce mi sembra logico che ti dia indefinita in quanto prima la usi (penso che ti dia indefinita a questa riga)
....? "checked=\"checked\" ":""; ?> value="<?php echo $row_Rs_portate['aperitivi']; ?>" />
e po la definisci alcune righe dopo
<?php } while ($row_Rs_portate = mysql_fetch_assoc($Rs_portate)); ?>
ma non vedendo tutto il codice può darsi che mi sbagli
 

ertrottola

Utente Attivo
10 Ago 2011
81
0
0
dunque sono arrivato fin qui:

PHP:
div id="aperitivi">       
         <input <?php if (!(strcmp($row_Rs_portate['aperitivi'],"yes"))) {echo "checked=\"checked\"";} ?>  name="myCheck[<?php $_SESSION['myCheck']= $row_Rs_portate['aperitivi']; ?>]" type="checkbox"  value="<?php echo $row_Rs_portate['aperitivi']; ?>" /> 
         <?php echo $row_Rs_portate['aperitivi']; ?>
     
      </div>

cosi non mi dà più la notice

seconda pagina

PHP:
<div id="news">
   <?php
session_start();
$_SESSION['myCheck']=$_POST['myCheck'] ;
foreach ($_SESSION['myCheck'] as $key => $value) { 
    echo "$value<br />"; 
} 
?>  
   <a href="portate.php"> modifica dati </a></div>

qui mostra i dati che voglio,
ma quando non seleziono nulla mi da:


Notice: Undefined index: myCheck in C:\Programmi\EasyPHP-5.3.6.0\www\pastauovo\preventivo.php on line 98

Warning: Invalid argument supplied for foreach() in C:\Programmi\EasyPHP-5.3.6.0\www\pastauovo\preventivo.php on line 99

e non mi tiene le sessioni in memoria:hammer:
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
credo che il problema sia qui
se non selezioni $_POST['myCheck'] (che nel caso di selezione diventa un array) rimane vuoto per cui in pratica non crei la sessione e questa non diventa array.
per cui la notice e il warning
prova a mettere una verifica sul post

PHP:
<?php
session_start();
if($_POST['myCheck']!= NULL){//oppure prova con $_POST['myCheck']!= "" oppure !is_array($_POST['myCheck'])
	$_SESSION['myCheck']=$_POST['myCheck'] ;
	foreach ($_SESSION['myCheck'] as $key => $value) { 
    	echo "$value<br />"; 
	}
	echo "<a href=\"portate.php\"> modifica dati </a>";
}else{
	echo "<a href=\"portate.php\"> devi fare almeno una scelta </a>";
}
?>
 

ertrottola

Utente Attivo
10 Ago 2011
81
0
0
Salve Borgo Italia grazie per il tuo interesse.
errori nella seconda pagina mi dà solo una notice e non mi tiene in memoria ancora le sessioni, sto provando di tutto anche le tue opzioni ma nulla, se non ti è molto disturbo ti invio il codice così se puoi dargli un occhiata forse con la tua esperienza potrai trovare l'errore che mi sta facendo letterarmente impazzire.

questa è la pagina dei prodotti:

PHP:
<?php require_once('../Connections/pastauovo.php'); ?>
<?php 
session_start();

require_once('../Connections/pastauovo.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;
}
}

mysql_select_db($database_pastauovo, $pastauovo);
$query_Rs_aperitivi = "SELECT aperitivi FROM preventivi";
$Rs_aperitivi = mysql_query($query_Rs_aperitivi, $pastauovo) or die(mysql_error());
$row_Rs_aperitivi = mysql_fetch_assoc($Rs_aperitivi);
$totalRows_Rs_aperitivi = mysql_num_rows($Rs_aperitivi);

mysql_select_db($database_pastauovo, $pastauovo);
$query_Rs_antipasti_carne = "SELECT antipasti_carne FROM preventivi";
$Rs_antipasti_carne = mysql_query($query_Rs_antipasti_carne, $pastauovo) or die(mysql_error());
$row_Rs_antipasti_carne = mysql_fetch_assoc($Rs_antipasti_carne);
$totalRows_Rs_antipasti_carne = mysql_num_rows($Rs_antipasti_carne);

mysql_select_db($database_pastauovo, $pastauovo);
$query_Rs_antipasti_pesce = "SELECT antipasti_pesce FROM preventivi";
$Rs_antipasti_pesce = mysql_query($query_Rs_antipasti_pesce, $pastauovo) or die(mysql_error());
$row_Rs_antipasti_pesce = mysql_fetch_assoc($Rs_antipasti_pesce);
$totalRows_Rs_antipasti_pesce = mysql_num_rows($Rs_antipasti_pesce);

mysql_select_db($database_pastauovo, $pastauovo);
$query_Rs_primi_carne = "SELECT primi_carne FROM preventivi";
$Rs_primi_carne = mysql_query($query_Rs_primi_carne, $pastauovo) or die(mysql_error());
$row_Rs_primi_carne = mysql_fetch_assoc($Rs_primi_carne);
$totalRows_Rs_primi_carne = mysql_num_rows($Rs_primi_carne);

mysql_select_db($database_pastauovo, $pastauovo);
$query_Rs_primi_pesce = "SELECT primi_pesce FROM preventivi";
$Rs_primi_pesce = mysql_query($query_Rs_primi_pesce, $pastauovo) or die(mysql_error());
$row_Rs_primi_pesce = mysql_fetch_assoc($Rs_primi_pesce);
$totalRows_Rs_primi_pesce = mysql_num_rows($Rs_primi_pesce);

mysql_select_db($database_pastauovo, $pastauovo);
$query_Rs_secondi_carne = "SELECT secondi_carne FROM preventivi";
$Rs_secondi_carne = mysql_query($query_Rs_secondi_carne, $pastauovo) or die(mysql_error());
$row_Rs_secondi_carne = mysql_fetch_assoc($Rs_secondi_carne);
$totalRows_Rs_secondi_carne = mysql_num_rows($Rs_secondi_carne);
?>
<!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">
<!-- InstanceBegin template="/Templates/7evennighte.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Documento senza titolo</title>
<!-- InstanceEndEditable -->
<link href="../blogger/css/master_7evennighte.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script src="../blogger/SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="../blogger/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
	background-color: #F3F3F3;
}
a:link {
	color: #333;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #333;
}
a:hover {
	text-decoration: underline;
	color: #999;
}
a:active {
	text-decoration: none;
	color: #333;
}
</style>
</head>

<body>
<div class="container">
  <div id="header"></div>
  <div id="menu">
    <ul id="MenuBar1" class="MenuBarHorizontal">
      <li><a href="../blogger/index.php">HOME</a> </li>
      <li><a href="../blogger/computers.php">COMPUTERS</a></li>
      <li><a href="../blogger/internet.php">INTERNET</a> </li>
      <li><a href="../blogger/develomper.php">DEVELOMPER</a></li>
      <li><a href="../blogger/grafica.php">GRAFICA</a></li>
      <li><a href="../blogger/contatti.php">CONTATTI</a></li>
    </ul>
  </div>
  <div id="content"><!-- InstanceBeginEditable name="content" -->
    <form action="preventivo.php" method="post">
      <h4>Aperitivi </h4>
      <?php do { ?>
        <div id="aperitivi">
          <?php echo $row_Rs_aperitivi['aperitivi']; ?>
          <input <?php if (!(strcmp($row_Rs_aperitivi['aperitivi'],"yes"))) {echo "checked=\"checked\"";} ?> name="myCheck[<?php $_SESSION['myCheck']=$row_Rs_aperitivi['aperitivi']; ?>]" type="checkbox" value="<?php echo $row_Rs_aperitivi['aperitivi']; ?>" />
        </div>
        <?php } while ($row_Rs_aperitivi = mysql_fetch_assoc($Rs_aperitivi)); ?>
<h4>Antipasti di Carne </h4>
        <?php do { ?>
          <div id="antipasti_carne">
          <?php echo $row_Rs_antipasti_carne['antipasti_carne']; ?>
            <input <?php if (!(strcmp($row_Rs_antipasti_carne['antipasti_carne'],"yes"))) {echo "checked=\"checked\"";} ?> name="myCheck[<?php $_SESSION['myCheck']= $row_Rs_antipasti_carne['antipasti_carne']; ?>]" type="checkbox" value="<?php echo $row_Rs_antipasti_carne['antipasti_carne']; ?>" />
          </div>
          <?php } while ($row_Rs_antipasti_carne = mysql_fetch_assoc($Rs_antipasti_carne)); ?>
<h4>Antipasti di Pesce </h4>
        <?php do { ?>
          <div id="antipasti_pesce"> <?php echo $row_Rs_antipasti_pesce['antipasti_pesce']; ?>
            <input <?php if (!(strcmp($row_Rs_antipasti_pesce['antipasti_pesce'],"yes"))) {echo "checked=\"checked\"";} ?> name="myCheck[<?php $_SESSION['myCheck']=$row_Rs_antipasti_pesce['antipasti_pesce']; ?>]" type="checkbox" value="<?php echo $row_Rs_antipasti_pesce['antipasti_pesce']; ?>" />
          </div>
          <?php } while ($row_Rs_antipasti_pesce = mysql_fetch_assoc($Rs_antipasti_pesce)); ?>
<h4>Primi di Carne </h4>
        <div id="primi_carne">
          <input name="myCheck[]" type="checkbox" />
        </div>
<h4>Primi di Pesce </h4>
        <div id="primi_pesce">
          <input name="myCheck[]" type="checkbox" />
        </div>
<h4>Secondi di Carne </h4>
        <div id="secondi_carne">
          <input name="myCheck[]" type="checkbox" />
        </div>
<h4>Secondi di Pesce </h4>
        <div id="secondi_pesce">
          <input name="myCheck[]" type="checkbox" />
        </div>
<h4>Contorni </h4>
        <div id="contorni">
          <input name="myCheck[]" type="checkbox" />
        </div>
<h4>Dolci </h4>
        <div id="dolci">
          <input name="myCheck[]" type="checkbox" />
        </div>
<h4>Frutta</h4>
      <div id="frutta">
        <input name="myCheck[]" type="checkbox" />
        <p>
          <input name="" type="submit" />
        </p>
      </div>
    </form>
    <!-- InstanceEndEditable --></div>
  <div id="navigation_dx"><!-- InstanceBeginEditable name="navigazione_dx" --><!-- InstanceEndEditable --></div>
  <div id="footer"><!-- InstanceBeginEditable name="footer" -->footer<!-- InstanceEndEditable --></div>
</div>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../blogger/SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../blogger/SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
<!-- InstanceEnd -->
</html>
<?php
mysql_free_result($Rs_aperitivi);

mysql_free_result($Rs_antipasti_carne);

mysql_free_result($Rs_antipasti_pesce);

mysql_free_result($Rs_primi_carne);

mysql_free_result($Rs_primi_pesce);

mysql_free_result($Rs_secondi_carne);
?>


e questa è la pagina dei preventivi:
PHP:
<?php 
session_start();
require_once('../Connections/pastauovo.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;
}
}

$colname_DetailRS1 = "-1";
if (isset($_GET['recordID'])) {
  $colname_DetailRS1 = $_GET['recordID'];
}
mysql_select_db($database_pastauovo, $pastauovo);
$query_DetailRS1 = sprintf("SELECT * FROM preventivi WHERE id = %s", GetSQLValueString($colname_DetailRS1, "int"));
$DetailRS1 = mysql_query($query_DetailRS1, $pastauovo) or die(mysql_error());
$row_DetailRS1 = mysql_fetch_assoc($DetailRS1);
$totalRows_DetailRS1 = mysql_num_rows($DetailRS1);
?><!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"><!-- InstanceBegin template="/Templates/7evennighte.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Documento senza titolo</title>
<!-- InstanceEndEditable -->
<link href="../blogger/css/master_7evennighte.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script src="../blogger/SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="../blogger/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
	background-color: #F3F3F3;
}
a:link {
	color: #333;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #333;
}
a:hover {
	text-decoration: underline;
	color: #999;
}
a:active {
	text-decoration: none;
	color: #333;
}
</style>
</head>

<body>
<div class="container">
  <div id="header"></div>
  <div id="menu">
    <ul id="MenuBar1" class="MenuBarHorizontal">
      <li><a href="../blogger/index.php">HOME</a>      </li>
      <li><a href="../blogger/computers.php">COMPUTERS</a></li>
      <li><a href="../blogger/internet.php">INTERNET</a>      </li>
      <li><a href="../blogger/develomper.php">DEVELOMPER</a></li>
      <li><a href="../blogger/grafica.php">GRAFICA</a></li>
<li><a href="../blogger/contatti.php">CONTATTI</a></li>
    </ul>
     
  </div>
  <div id="content"><!-- InstanceBeginEditable name="content" -->
    <div id="news">
   <?php

if($_POST['myCheck']!= NULL){//oppure prova con $_POST['myCheck']!= "" oppure !is_array($_POST['myCheck'])
    $_SESSION['myCheck']=$_POST['myCheck'] ;
    foreach ($_SESSION['myCheck'] as $key => $value) { 
        echo "$value<br />"; 
    }
    echo "<a href=\"portate.php\"> modifica dati </a>";
}else{
    echo "<a href=\"portate.php\"> devi fare almeno una scelta </a>";
}
?> 
  </div>
  <!-- InstanceEndEditable --></div>
  <div id="navigation_dx"><!-- InstanceBeginEditable name="navigazione_dx" --><!-- InstanceEndEditable --></div>
  <div id="footer"><!-- InstanceBeginEditable name="footer" -->footer<!-- InstanceEndEditable --></div>
</div>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../blogger/SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../blogger/SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
<!-- InstanceEnd -->
</html><?php
mysql_free_result($DetailRS1);
?>

ti ringrazio anticipatamente, io intanto....:book:
 

ertrottola

Utente Attivo
10 Ago 2011
81
0
0
ok grazie borgo italia
e son ce la fai buon viaggio.

ps
spero sia una zona di mare perchè fa un caldo
 

ertrottola

Utente Attivo
10 Ago 2011
81
0
0
Ciao ragazzi e ben tornati dalle ferie,
ero rimasto che non riuscivo a tenere le variabili di sessione in memoria ,"o meglio non rimanevano fleggate nella check una volta che tornavo indietro per la modifica"
ecco e li sono rimasto:rolleyes:
ho apportato delle modifiche, ma nulla estraggo i dati ma non rimangono fleggate tornando indietro potete aiutarmi?
vi posto il codice delle due pagine,
ps
apprezzerei se non è troppo disturbo anche una breve spiegazione il perchè non riesco a farle funzionare,
grazie di cuore a tutti.


Pagina1
PHP:
<?php 
session_start();
 $_POST['var']=$_SESSION['aperitivi'];
require_once('../Connections/pastauovo.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;
}
}

mysql_select_db($database_pastauovo, $pastauovo);
$query_Rs_aperitivi = "SELECT aperitivi FROM preventivi";
$Rs_aperitivi = mysql_query($query_Rs_aperitivi, $pastauovo) or die(mysql_error());
$row_Rs_aperitivi = mysql_fetch_assoc($Rs_aperitivi);
$totalRows_Rs_aperitivi = mysql_num_rows($Rs_aperitivi);
 
 
require_once('../Connections/pastauovo.php'); ?>
<!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"><!-- InstanceBegin template="/Templates/7evennighte.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Documento senza titolo</title>
<!-- InstanceEndEditable -->
<link href="css/master_7evennighte.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script src="../blogger/SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="../blogger/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
	background-color: #F3F3F3;
}
a:link {
	color: #333;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #333;
}
a:hover {
	text-decoration: underline;
	color: #999;
}
a:active {
	text-decoration: none;
	color: #333;
}
</style>
</head>

<body>
<div class="container">
  <div id="header"></div>
  <div id="menu">
    <ul id="MenuBar1" class="MenuBarHorizontal">
      <li><a href="../blogger/index.php">HOME</a>      </li>
      <li><a href="../blogger/computers.php">COMPUTERS</a></li>
      <li><a href="../blogger/internet.php">INTERNET</a>      </li>
      <li><a href="../blogger/develomper.php">DEVELOMPER</a></li>
      <li><a href="../blogger/grafica.php">GRAFICA</a></li>
<li><a href="../blogger/contatti.php">CONTATTI</a></li>
    </ul>
     
  </div>
  <div id="content"><!-- InstanceBeginEditable name="content" -->
  
     <h4>Aperitivi </h4>
     <form action="preventivo.php" method="post">
     <?php do { ?>
       <div id="aperitivi">
       <?php 
	   
	   echo $row_Rs_aperitivi['aperitivi']; ?>
         <input name="var[]" type="checkbox"value="<?php echo $row_Rs_aperitivi['aperitivi']; ?>" />
        
      </div>
       <?php } while ($row_Rs_aperitivi = mysql_fetch_assoc($Rs_aperitivi)); ?>
<div id="antipasti_carne">              
        
  </div>     
        <h4>Antipasti di Pesce </h4>
        <div id="antipasti_pesce">       
      </div>      
        <h4>Primi di Carne </h4>
        <div id="primi_carne">    
      </div>    
        <h4>Primi di Pesce </h4>
        <div id="primi_pesce">      
      </div>     
        <h4>Secondi di Carne </h4>
        <div id="secondi_carne">       
      </div>      
     <h4>Secondi di Pesce </h4>
      <div id="secondi_pesce">    
     <h4>Contorni </h4>
      <div id="contorni">       
      </div>     
     <h4>Dolci </h4>
      <div id="dolci">       
      </div>   
      <h4>Frutta</h4>
<div id="frutta">        
           
 <input name="aggiungi" type="submit" /></div></form>
           
    
   <!-- InstanceEndEditable --></div>
  <div id="navigation_dx"><!-- InstanceBeginEditable name="navigazione_dx" --><!-- InstanceEndEditable --></div>
  <div id="footer"><!-- InstanceBeginEditable name="footer" -->footer<!-- InstanceEndEditable --></div>
</div>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../blogger/SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../blogger/SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
<!-- InstanceEnd -->

</html>
<?php
mysql_free_result($Rs_aperitivi);
?>

pagina2

PHP:
<?php 
session_start();

require_once('../Connections/pastauovo.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;
}
}

mysql_select_db($database_pastauovo, $pastauovo);
$query_Recordset1 = "SELECT aperitivi FROM preventivi";
$Recordset1 = mysql_query($query_Recordset1, $pastauovo) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

require_once('../Connections/pastauovo.php'); ?>
<!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"><!-- InstanceBegin template="/Templates/7evennighte.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Documento senza titolo</title>
<!-- InstanceEndEditable -->
<link href="css/master_7evennighte.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script src="../blogger/SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="../blogger/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
	background-color: #F3F3F3;
}
a:link {
	color: #333;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #333;
}
a:hover {
	text-decoration: underline;
	color: #999;
}
a:active {
	text-decoration: none;
	color: #333;
}
</style>
</head>

<body>
<div class="container">
  <div id="header"></div>
  <div id="menu">
    <ul id="MenuBar1" class="MenuBarHorizontal">
      <li><a href="../blogger/index.php">HOME</a>      </li>
      <li><a href="../blogger/computers.php">COMPUTERS</a></li>
      <li><a href="../blogger/internet.php">INTERNET</a>      </li>
      <li><a href="../blogger/develomper.php">DEVELOMPER</a></li>
      <li><a href="../blogger/grafica.php">GRAFICA</a></li>
<li><a href="../blogger/contatti.php">CONTATTI</a></li>
    </ul>
     
  </div>
  <div id="content"><!-- InstanceBeginEditable name="content" -->
    <div id="news">
   <?php
$var=$_SESSION['aperitivi'];
if(is_array($_SESSION['aperitivi']=$_POST['var']))
{
   foreach($_POST['var'] as $value)
   {
      echo "Hai selezionato la checkbox:  con valore: $value<br />"; 
   }
     echo "<a href=\"portate.php\"> modifica dati </a>";
}else{
    echo "<a href=\"portate.php\"> devi fare almeno una scelta </a>"; 
} 

?>
 

   </div>
  <!-- InstanceEndEditable --></div>
  <div id="navigation_dx"><!-- InstanceBeginEditable name="navigazione_dx" --><!-- InstanceEndEditable --></div>
  <div id="footer"><!-- InstanceBeginEditable name="footer" -->footer<!-- InstanceEndEditable --></div>
</div>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../blogger/SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../blogger/SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($Recordset1);
?>
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
affinchè un checkbox sia ceccato deve avere la clausola checked, es.
<input name="uno" type="checkbox" value="1" checked>
puoi provare in questa maniera

PHP:
<?php
 do {
 ?> 
       <div id="aperitivi"> 
<?php  
	//innizio verifiche check
	$ch="";
	//verifichi che esista la sessione
	if(isset($_SESSION['aperitivi'])){
		//se esiste verifiche che dentro ci sia il valore del check
		if(in_array($_SESSION['aperitivi'], $row_Rs_aperitivi['aperitivi'])){
			$ch="checked";
		}else{
			$ch="";
		}
	}
	//fine verifiche
	echo $row_Rs_aperitivi['aperitivi']; ?> 
	<input name="var[]" type="checkbox" value="<?php echo $row_Rs_aperitivi['aperitivi']; ?>" <?php echo $ch; ?>/>    
	</div> 
<?php
 } while ($row_Rs_aperitivi = mysql_fetch_assoc($Rs_aperitivi)); 
?>
prova al massimo togli tutto, se funzia scrivi meglio lo script
 

ertrottola

Utente Attivo
10 Ago 2011
81
0
0
salve carissimo, non sò se è possibile usare questa espressione nel forum:
********* non funziona....
come torno indietro con il pulsante modifica, mi da questo errore

Warning: in_array() expects parameter 2 to be array, string given in C:\Programmi\EasyPHP-5.3.8.0\www\pastauovo\portate.php on line 107
crodino

Warning: in_array() expects parameter 2 to be array, string given in C:\Programmi\EasyPHP-5.3.8.0\www\pastauovo\portate.php on line 107
campari

guarda sto letterarmente impazzendo.....
 
Ultima modifica di un moderatore:

ertrottola

Utente Attivo
10 Ago 2011
81
0
0
se questo rigo:
if(in_array($_SESSION['aperitivi'], $row_Rs_aperitivi['aperitivi']))

lo scrivo cosi:

if( array($_SESSION['var'], $row_Rs_aperitivi['aperitivi']))

mi lascia selezionate tutte le check :incazz:quando torno indietro, ne deseleziono una invio , torno indietro e le ritrovo tutte selezionate
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
prova a mettere dopo il while l'istruzione per annullare l'array


PHP:
<?php 
//....................
 } while ($row_Rs_aperitivi = mysql_fetch_assoc($Rs_aperitivi));  
$_SESSION['aperitivi']=array();//dovrebbe annullarti la vecchia selezione
?>
comunque provo a dare meglio un occhio poi ti so dire (spero)
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
alex direbbe che sono arteriosclerotico (a ragione), avevo sbagliato in_array invertendo i termini
semplificando(non ho fatto il db) ecco questo funzia
nella prima pagina (l'ho chiamata aperitivi.php per fare il ritorna)
PHP:
<?php
session_start();
//......
?>
<!-- ecc... -->
<h4>Aperitivi </h4> 
<form action="preventivo.php" method="post">
<!-- ecc... -->
<?php
/*
questa parte simula il db, poi al posto del forheach metti il tuo do while
e la varibile  $row_Rs_aperitivi['aperitivi'] al posto di $a
*/
$ape=array("campari","spritz","rosso antico","negroni");
//.......
$ch="";
foreach($ape as $a){
	if(isset($_SESSION['aperitivi'])){ 
        //se esiste verifiche che dentro ci sia il valore del check 
		if(in_array($a, $_SESSION['aperitivi'])){ 
            $ch="checked"; 
        }else{ 
            $ch=""; 
        } 
    } 
	echo $a;
	echo "<input name=\"var[]\" type=\"checkbox\" value=\"".$a."\" $ch /><br>";        
}
if(isset($_SESSION['aperitivi'])){$_SESSION['aperitivi']=array();}
?> 
<br>
<input type="submit" name="Submit" value="invia">
<!-- eccc..... -->
</form>
e la pagina preventivo.php

PHP:
<?php session_start(); 
//..............
if($_POST['var'] != NULL){//se è stata fatta almeno una selezione
	//creo la sessione array
	$_SESSION['aperitivi']=$_POST['var'];
	foreach($_POST['var'] as $valore){
		echo "hai scelto: $valore <br>";
	}
}else{
echo "devi fare almeno una selezione";
}
//..............
?>
<br> 
<a href="aperitivi.php">torna</a>
se provi queste due paginette vedrai che i chec si modificano, poi le adatti al tuo script
 

ertrottola

Utente Attivo
10 Ago 2011
81
0
0
io dico che sei un genio, non sò come ringraziarti guarda guarda...:love::love::love::love::love::love::love:
 

ertrottola

Utente Attivo
10 Ago 2011
81
0
0
questa parte simula il db, poi al posto del forheach metti il tuo do while
e la varibile $row_Rs_aperitivi['aperitivi'] al posto di $a
*/
$ape=array("campari","spritz","rosso antico","negroni");
//.......
$ch="";
foreach($ape as $a){
if(isset($_SESSION['aperitivi'])){


io non riesco a mettere il do while......:incazz2:
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
se non ricordo male, dovrebbe esser così

PHP:
<?php 
//dati di connessione
// la query al db 
//....... 
$ch=""; 
while($row_Rs_aperitivi=mysql_fetch_array($query)){ //qui c'era il foreach
    if(isset($_SESSION['aperitivi'])){  
        //se esiste verifiche che dentro ci sia il valore del check  
        if(in_array($row_Rs_aperitivi['aperitivi'], $_SESSION['aperitivi'])){  
            $ch="checked";  
        }else{  
            $ch="";  
        }  
    }  
    echo $a; 
    echo "<input name=\"var[]\" type=\"checkbox\" value=\"".$row_Rs_aperitivi['aperitivi']."\" $ch /><br>";         
} 
if(isset($_SESSION['aperitivi'])){$_SESSION['aperitivi']=array();} 
?>
 

ertrottola

Utente Attivo
10 Ago 2011
81
0
0
PHP:
<table width="460" border="1" align="center">
      <tr>
        <th scope="col"><?php echo $row_Rs_portate['antipasti_carne']; ?></th>
        <th scope="col">
          <?php 
		  $ape=array($row_Rs_portate['antipasti_carne']); 
    $ch=""; 
while($row_Rs_portate = mysql_fetch_assoc($Rs_portate)){ //qui c'era il foreach
    if(isset($_SESSION['antipasti_carne'])){  
        //se esiste verifiche che dentro ci sia il valore del check  
        if(in_array( $row_Rs_portate['antipasti_carne'], $_SESSION['antipasti_carne'])){  
            $ch="checked";  
        }else{  
            $ch="";  
        }  
    }  

    echo "<input name=\"var[]\" type=\"checkbox\" value=\"". $row_Rs_portate['antipasti_carne']."\" $ch /><br>";         
} 
if(isset($_SESSION['antipasti_carne'])){$_SESSION['antipasti_carne']=array();} ?> </th>
        </tr>
    </table>

cosi sparisce la casella di controllo....
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
cosa intendi per "cosi sparisce la casella di controllo.... "?
comunque metti quei due var_dump e dimmi cosa risulta
PHP:
<?php  
          //$ape=array($row_Rs_portate['antipasti_carne']);  qusta riga non serve
    $ch="";  
var_dump(mysql_fetch_assoc($Rs_portate)); //poi la togli
while($row_Rs_portate = mysql_fetch_assoc($Rs_portate)){ //qui c'era il foreach 
	if(isset($_SESSION['antipasti_carne'])){   
        //se esiste verifiche che dentro ci sia il valore del check   
        if(in_array( $row_Rs_portate['antipasti_carne'], $_SESSION['antipasti_carne'])){   
            $ch="checked";   
        }else{   
            $ch="";   
        }   
    }
	var_dump($ch);//po la togli
    echo "<input name=\"var[]\" type=\"checkbox\" value=\"". $row_Rs_portate['antipasti_carne']."\" $ch /><br>";          
}  
if(isset($_SESSION['antipasti_carne'])){$_SESSION['antipasti_carne']=array();}
?>
 
Discussioni simili
Autore Titolo Forum Risposte Data
E perdita di dati con variabili di sessione PHP 18
J Passare oggetti con le variabili di sessione PHP 0
S Utilizzo variabili di sessione tra PC e server PHP 0
N [PHP] Utilizzo variabili di sessione [Risolto] PHP 13
G Uso variabili di sessione PHP 4
K Problema variabili sessione e ...forse header PHP 6
V Consiglio sul controllo variabili di sessione PHP 1
M Variabili di sessione che non funzionano su Aruba Hosting 5
C variabili di sessione PHP 2
A Creazione variabili di sessione PHP 3
C Variabili Di Sessione $_session PHP 3
M Array e variabili di sessione Classic ASP 1
G Scadenza Variabili di Sessione Classic ASP 1
R [PHP] - Variabili di sessione PHP 1
P Variabili di sessione e cookie Classic ASP 1
A Redirect 301 genera url statico con variabili Web Server 0
G file CSS contenente variabili HTML e CSS 1
M Passaggio variabili array php su un tasto jq PHP 3
K [PHP] Problema con variabili concatenate. PHP 1
MarcoGrazia Metodi static e passaggio di variabili PHP 1
N Problema passaggio variabili tra pagine PHP 4
T Circolo vizioso di variabili PHP 1
X Dichiarare variabili solo al caricamento della pagina PHP 3
R passaggio variabili tra modulo genitore a figlio jQuery 3
L [Javascript] input variabili di scrittura con canvas Javascript 2
maxnegri Eliminare url index.php con variabili e reindirizzare alla home del sito PHP 7
zorro [PHP] passaggio di variabili PHP 7
Domenico_Falco1 Rendere dinamico un sito web con chiamate ajax e php e variabili json PHP 12
S [PHP] Estrarre elementi array su più variabili PHP 5
M Inviare variabili da menu a tendina a pagina php con post PHP 6
M [PHP] Selezione da menu a discesa con 2 variabili PHP 0
B [Visual Basic] Passaggio variabili da un progetto all'altro (Visual Studio 2017 C#/SQL) Visual Basic 0
A php echo get con variabili PHP 4
S [Javascript] come estrarre valori array e inserirli in diverse variabili Javascript 1
N [PHP] Registrare variabili all'interno di un ciclo PHP 3
F [PHP] Cercare voci uguali nel db e unire alcune variabili PHP 0
F [PHP] if(isset($_POST['Invia'])) non mi riconosce le variabili PHP 3
K [PHP] variabili di tipo numerico nei Form PHP 1
B [PHP] variabili globali in chiamate ajax PHP 0
otto9due Concatenazione variabili jQuery 1
K [PHP] Passaggio Variabili Senza Refresh Di Pagina PHP 1
Emix [PHP] Check - Select e recupero variabili PHP 40
F Come funziona in javascript l'accesso alle variabili dell'array Programmazione 1
P [PHP] link con variabili e while PHP 5
C [RISOLTO][PHP] Passaggio variabili senza refresh di pagina PHP 7
Paparazzo2017 [HTML] Impaginazione Articolo con variabili in Wordpress WordPress 5
Mangiuz Variabili semplici PHP su Javascript Ajax 1
A [PHP] Passare variabili tra pagine diverse PHP 2
elpirata [PHP] Passaggio di dati tra variabili PHP 1
A Problema con getCurrentPosition e passaggio variabili da javascript a PHP Javascript 3

Discussioni simili