Pessoal preciso muito da ajuda de vocês, Preciso criar um cadastro de Laudos e dos Itens dos Laudos. Eu criei um form com uma tabela para inserir o laudo e uma tabela para os itens, este form que criei já esta gravando nas duas tabelas, mas ele grava apenas um item por vez, eu preciso de algo tipo um FOR no INSERT na tabela de itens para permitir a insercao de varios itens de uma só vez, inicialmente o usuario deve ter como opcao 10 compos para insercao, para isso criei um Repeat Region, mas como disse anteriormente apenas um (o ultimo) esta sendo gravado na tabela de itens, tambem preciso permitir que o usuario possa acrescentar ou apagar os itens ( ou seja, um botao que ao clicado repete os campos de insercao). segue abaixo o codigo completo. desde já agradeço. <?php require_once('Connections/conexao.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']);
}
// Insercao do Laudo
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO laudos (id_laudo, id_paciente, responsavel, data_hora, historico, assinatura, cat) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_laudo'], "int"),
GetSQLValueString($_POST['id_paciente'], "int"),
GetSQLValueString($_POST['responsavel'], "text"),
GetSQLValueString($_POST['data_hora'], "date"),
GetSQLValueString($_POST['historico'], "text"),
GetSQLValueString($_POST['assinatura'], "text"),
GetSQLValueString($_POST['cat'], "text"));
mysql_select_db($database_conexao, $conexao);
$Result1 = mysql_query($insertSQL, $conexao) or die(mysql_error());
$insertGoTo = "laudo_cadastrar.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")) {
// Insercao de Itens do Laudo
$insertSQL = sprintf("INSERT INTO laudos_itens (id_laudo_item, id_laudo, subtitulo, titulo, descricao) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_laudo_item'], "int"),
mysql_insert_id(),
//GetSQLValueString($_POST['id_laudo'], "int"),
GetSQLValueString($_POST['subtitulo'], "text"),
GetSQLValueString($_POST['titulo'], "text"),
GetSQLValueString($_POST['descricao'], "text"));
mysql_select_db($database_conexao, $conexao);
$Result1 = mysql_query($insertSQL, $conexao) or die(mysql_error());
$insertGoTo = "laudo_cadastrar.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_conexao, $conexao);
$query_Recordset1 = "SELECT laudos_itens.subtitulo, laudos_itens.titulo, laudos_itens.descricao FROM laudos_itens";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $conexao) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="padrão.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="Scripts/mascara_data.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.3.2.min.js"></script>
</head>
<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Id_paciente:</td>
<td><input type="text" name="id_paciente" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Responsavel:</td>
<td><input type="text" name="responsavel" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Data_hora:</td>
<td><input type="text" name="data_hora" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Historico:</td>
<td><input type="text" name="historico" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Assinatura:</td>
<td><input type="text" name="assinatura" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Cat:</td>
<td><input type="text" name="cat" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td></td>
</tr>
</table>
<?php do { ?>
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Subtitulo:</td>
<td><input type="text" name="subtitulo" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Titulo:</td>
<td><input type="text" name="titulo" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Descricao:</td>
<td><input type="text" name="descricao" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td></td>
</tr>
</table>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<input type="hidden" name="MM_insert" value="form1">
</p>
<p><input type="submit" value="Insert record"></p>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>