I'm working on an storing form where I can store data but getting information from the same database.
The Form is doing part of what I intended which is retrieving the information from other tables on the Data Base.
I use this code for this form:
<?php require_once('connectiononly.php'); ?>
<?php
$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 jugadores (nombre, no_camisa, posicion, edad, peso, estatura, nacionalidad, procedencia, foto) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['nombre'], "text"),
GetSQLValueString($_POST['no_camisa'], "int"),
GetSQLValueString($_POST['posicion'], "text"),
GetSQLValueString($_POST['edad'], "int"),
GetSQLValueString($_POST['peso'], "int"),
GetSQLValueString($_POST['estatura'], "text"),
GetSQLValueString($_POST['nacionalidad'], "text"),
GetSQLValueString($_POST['procedencia'], "text"),
GetSQLValueString($_POST['foto'], "bloob"));
mysql_select_db($database_TRS, $TRS);
$Result1 = mysql_query($insertSQL, $TRS) or die(mysql_error());
}
mysql_select_db($database_TRS, $TRS);
$query_Procedencia = "SELECT id, nombre FROM procedencia";
$Procedencia = mysql_query($query_Procedencia, $TRS) or die(mysql_error());
$row_Procedencia = mysql_fetch_assoc($Procedencia);
$totalRows_Procedencia = mysql_num_rows($Procedencia);
mysql_select_db($database_TRS, $TRS);
$query_Posicion = "SELECT id, nombre FROM posicion";
$Posicion = mysql_query($query_Posicion, $TRS) or die(mysql_error());
$row_Posicion = mysql_fetch_assoc($Posicion);
$totalRows_Posicion = mysql_num_rows($Posicion);
?>
<!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>
<title> Creacion Ficha de Jugador </title>
<meta charset="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="Estilos.css"/>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>
</head>
<body>
<div class="contenedor">
<body>
<header>
<div id="subheader">
<div id="logotipo"> <p><img class="thumb1" src="alianzafc.jpg" alt="thumbail #2" />
</p>
</div>
</div>
</div>
</header>
</br>
<section id="contenido">
<article>
<hgroup><h2 class="Titulo1" align="center">Crear
nueva Ficha de Jugador</h2></hgroup>
</br>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Nombre:</td>
<td><input type="text" name="nombre" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">No. de Uniforme:</td>
<td><input type="text" name="no_camisa" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Posicion:</td>
<td><select name="posicion" id="id">
<?php
do {
?>
<option value="<?php echo $row_Posicion['id']?>"><?php echo $row_Posicion['nombre']?></option>
<?php
} while ($row_Posicion = mysql_fetch_assoc($Posicion));
$rows = mysql_num_rows($Posicion);
if($rows > 0) {
mysql_data_seek($Posicion, 0);
$row_Posicion = mysql_fetch_assoc($Posicion);
}
?>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Edad:</td>
<td><input type="text" name="edad" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Peso:</td>
<td><input type="text" name="peso" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Estatura:</td>
<td><input type="text" name="estatura" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Nacionalidad:</td>
<td><input type="text" name="nacionalidad" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Procedencia:</td>
<td><select name="procedencia" id="id">
<?php
do {
?>
<option value="<?php echo $row_Procedencia['id']?>"><?php echo $row_Procedencia['nombre']?></option>
<?php
} while ($row_Procedencia = mysql_fetch_assoc($Procedencia));
$rows = mysql_num_rows($Procedencia);
if($rows > 0) {
mysql_data_seek($Procedencia, 0);
$row_Procedencia = mysql_fetch_assoc($Procedencia);
}
?>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Foto:</td>
<td><input type="file" name="foto" value=""/></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insertar Jugador" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>
<?php
mysql_free_result($Procedencia);
mysql_free_result($Posicion);
?>
But I'm getting an Error when Submitting the Form.
It says about issues with GetSQLValueString(), and I try this code which was used in another app before:
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;
}
This I set it up in the beginning of the PHP code underneath the request of the connection.
And it doesn't even load the form saying that the ending was not expected.
Any Ideas on how to save those?