Salve a tutti!
Vorrei realizzare uno stupido giochetto, diciamo una specie del paroliere.
In pratica ho un semplice form dove inserisco una parola di 4 lettere e l'altro utente dovrà sostiuire la parola cambiandone una sola lettera.
Fin qui tutto ok, il problema sta quando voglio diciamo 'resettare' il gioco, volevo inserire dei checkbox, e una volta selezionati cancellare tutto il contenuto della tabella, attualmente mi cancella solo 1 riga alla volta, come posso fare?
la tabella mysql è composta da:
id auto_increment
game varchar 50 unique
questo è il codice
Codice PHP:
<?php require_once('Connections/conn.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;
}
}
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="index.php";
$loginUsername = $_POST['game'];
$LoginRS__query = sprintf("SELECT game FROM game WHERE game=%s", GetSQLValueString($loginUsername, "text"));
mysql_select_db($database_conn, $conn);
$LoginRS=mysql_query($LoginRS__query, $conn) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}
}
$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 game (id, game) VALUES (%s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['game'], "text"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
}
if ((isset($_POST['hiddenField'])) && ($_POST['hiddenField'] != "")) {
$deleteSQL = sprintf("DELETE FROM game WHERE id=%s",
GetSQLValueString($_POST['hiddenField'], "int"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($deleteSQL, $conn) or die(mysql_error());
}
mysql_select_db($database_conn, $conn);
$query_rs_gioco = "SELECT * FROM game ORDER BY id DESC";
$rs_gioco = mysql_query($query_rs_gioco, $conn) or die(mysql_error());
$row_rs_gioco = mysql_fetch_assoc($rs_gioco);
$totalRows_rs_gioco = mysql_num_rows($rs_gioco);
?>
e questo è il form dove si trova il checkbox
Codice PHP:
<form id="form4" name="form4" method="post" action="">
<input type="submit" name="elimina" id="elimina" value="elimina" />
<input name="hiddenField" type="hidden" id="hiddenField" value="<?php echo $row_rs_gioco['id']; ?>" />
</p>
<table width="538" border="1" align="center">
<?php do { ?>
<tr>
<td width="247"><?php echo $row_rs_gioco['game']; ?></td>
<td width="66""><input name="<?php echo $row_rs_gioco['id']; ?>" type="checkbox" id="<?php echo $row_rs_gioco['id']; ?>" value="<?php echo $row_rs_gioco['id']; ?>" />
<label for="<?php echo $row_rs_gioco['id']; ?>"></label></td>
</tr>
<?php } while ($row_rs_gioco = mysql_fetch_assoc($rs_gioco)); ?>
</table>
</p>
</form>