Código PHP:
<?php require_once('Connections/dinorpg.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 .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO dinos (NDino, Maestro, PFuego, PAgua, PMadera, PElec, PAire, Nivel, HP, AFuego, AAgua, AMadera, Aelec, AAire, Imagen) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['NDino'], "text"),
GetSQLValueString($_POST['Maestro'], "text"),
GetSQLValueString($_POST['PFuego'], "int"),
GetSQLValueString($_POST['PAgua'], "int"),
GetSQLValueString($_POST['PMadera'], "int"),
GetSQLValueString($_POST['PElec'], "int"),
GetSQLValueString($_POST['PAire'], "int"),
GetSQLValueString($_POST['Nivel'], "int"),
GetSQLValueString($_POST['HP'], "int"),
GetSQLValueString($_POST['AFuego'], "text"),
GetSQLValueString($_POST['AAgua'], "text"),
GetSQLValueString($_POST['AMadera'], "text"),
GetSQLValueString($_POST['Aelec'], "text"),
GetSQLValueString($_POST['AAire'], "text"),
GetSQLValueString($_POST['Imagen'], "text"));
mysql_select_db($database_dinorpg, $dinorpg);
$Result1 = mysql_query($insertSQL, $dinorpg) or die(mysql_error());
$insertGoTo = "listado.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO dinos (NDino, Maestro, PFuego, PAgua, PMadera, PElec, PAire, Nivel, HP, AFuego, AAgua, AMadera, Aelec, AAire, Imagen) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['NDino'], "text"),
GetSQLValueString($_POST['Maestro'], "text"),
GetSQLValueString($_POST['PFuego'], "int"),
GetSQLValueString($_POST['PAgua'], "int"),
GetSQLValueString($_POST['PMadera'], "int"),
GetSQLValueString($_POST['PElec'], "int"),
GetSQLValueString($_POST['PAire'], "int"),
GetSQLValueString($_POST['Nivel'], "int"),
GetSQLValueString($_POST['HP'], "int"),
GetSQLValueString($_POST['AFuego'], "text"),
GetSQLValueString($_POST['AAgua'], "text"),
GetSQLValueString($_POST['AMadera'], "text"),
GetSQLValueString($_POST['Aelec'], "text"),
GetSQLValueString($_POST['AAire'], "text"),
GetSQLValueString($_POST['Imagen'], "text"));
mysql_select_db($database_dinorpg, $dinorpg);
$Result1 = mysql_query($insertSQL, $dinorpg) or die(mysql_error());
}
mysql_select_db($database_dinorpg, $dinorpg);
$query_alta = "SELECT * FROM dinos";
$alta = mysql_query($query_alta, $dinorpg) or die(mysql_error());
$row_alta = mysql_fetch_assoc($alta);
$totalRows_alta = mysql_num_rows($alta);
?>