hi, i have one database employer, where i m gone found datas, so i want one script in javascript and php, when i clic in name of employer list then show me all information, like number, photo... that belongs to folowing employer. please help me. i uprociate any help.:'(
toydiaz 0 Light Poster
Jayavardhan -2 Light Poster
It's nothing but dynamic selection. The below code may helps you to retrieve the data from the database when u click on the particular employer.
function Retrieve(query) {
// Get document head element
var head = document.getElementsByTagName('head').item(0);
// Create new script element and set attributes
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'MySQL.Retrieve.Data.php' + query);
head.insertBefore(script, head.firstChild);
}
scrappedcola 11 Posting Whiz in Training
There are two ways you can go about this you can do a form submit that would refresh the page or you can use an ajax call to post back to the server, wait for a response, and display the content. In the form post method it's a full page refresh meaning you are sending data to a url and loading that url in the browser. In the ajax method you are still sending data to a url but the code just waits for the response and does something with it so you can just update a particular piece. This link is an example of an ajax call with php that queries a database. http://www.w3schools.com/PHP/php_ajax_database.asp
toydiaz 0 Light Poster
thanks for everybory, but i still with that problem...i keep trying here. if can help -me will be very good.
<?php
require_once('class_bd.php');
$_bd = new ClassConnectBd();
$_bd->connectBD();
$f_terceiro = $_bd->query('SELECT * FROM T_Terceiros');
$rst_terceiro = mssql_num_rows($f_terceiro);
?>
<html>
<head>
<script language="javascript">
function valida(){
d = document.form1;
if (d.numero.value == ""){
alert("O campo " + d.numero.name + " deve ser preenchido!");
d.numero.focus();
return false;
}
if(d.nome1.value==''){
alert("O campo " + d.nome1.name + " Funcionario deve ser preenchido!");
d.nome1.focus();
return false;
}
if (d.data1.value == ""){
alert("O campo " + d.data1.name + " deve ser preenchido!");
d.data1.focus();
return false;
}
if (d.doc.value == ""){
alert("O campo " + d.doc.name + " deve ser preenchido!");
d.doc.focus();
return false;
}
if (d.nomebeneficiario.value == ""){
alert("O campo " + d.nomebeneficiario.name + " deve ser preenchido!");
d.nomebeneficiario.focus();
return false;
}
if (d.dependencia.value == ""){
alert("O campo " + d.dependencia.name + " deve ser preenchido!");
d.dependencia.focus();
return false;
}
if (d.datanascimento.value == ""){
alert("O campo " + d.datanascimento.name + " deve ser preenchido!");
d.datanascimento.focus();
return false;
}
if (d.docescolar.value == ""){
alert("O campo " + d.datanascimento.name + " deve ser preenchido!");
d.datanascimento.focus();
return false;
}
if (d.anoescolar.value == ""){
alert("O campo " + d.anoescolar.name + " deve ser preenchido!");
d.anoescolar.focus();
return false;
}
return true;
}
</script>
<script>
function idade(object, birthDay){
now = new Date();
bD = birthDay.value.split('/');
if(bD.length==3){
born = new Date(bD[2], bD[1]*1-1, bD[0]);
years = new Date(now.getTime() - born.getTime());
base = new Date(0);
document.all['AGE'].value = years.getFullYear()-base.getFullYear();
}
}
</script>
<script>
function countAge(_id, birthDay){
id_v = "AGE"+_id;
now = new Date();
bD = birthDay.value.split('/');
if(bD.length==3){
born = new Date(bD[2], bD[1]*1-1, bD[0]);
years = new Date(now.getTime() - born.getTime());
base = new Date(0);
document.getElementById(id_v).value = years.getFullYear()-base.getFullYear();
document.all['AGE'].value = years.getFullYear()-base.getFullYear();
}
}
</script>
<script type="text/javascript">
/*<![CDATA[*/
function addRow()
{
var tbl = document.getElementById('mySampleTable');
var lastRow = tbl.rows.length;
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
var cellLeft = row.insertCell(0);
var doc = document.createElement('input');
doc.type = 'text';
doc.name = 'doc[]';
doc.id = 'doc' + iteration;
doc.style.width="100%";
cellLeft.appendChild(doc);
var id_age = "AGE"+iteration;
var func = row.insertCell(1);
var nome = document.createElement('input');
nome.type = 'text';
nome.name = 'nome[]';
nome.id = 'nome' + iteration;
nome.style.width="100%";
func.appendChild(nome);
var cellRightSel = row.insertCell(2);
var sel = document.createElement('select');
sel.name = 'relacao[]';
sel.id = 'relacao' + iteration;
sel.options[0] = new Option('Selecciona', '');
sel.options[1] = new Option('Espaoso/a', 'Espaoso/a');
sel.options[2] = new Option('Filho/a', 'Filho/a');
sel.options[3] = new Option('Entiado/a', 'Entiado/a');
cellRightSel.appendChild(sel);
var direita = row.insertCell(3);
var inp = document.createElement('input');
inp.type = 'text';
inp.name = 'data[]';
inp.id = 'data' + iteration;
inp.setAttribute("onchange","countAge("+iteration+", this);");
inp.style.width="100%";
direita.appendChild(inp);
var idade= row.insertCell(4);
var age1 = document.createElement('input');
age1.type = 'text';
age1.setAttribute("name","AGE[]");
// the exact same thing with a unique id
age1.setAttribute("id",""+id_age);
// set it to size of 40. setting sizes is good.
age1.style.width="100%";
idade.appendChild(age1);
var esc = row.insertCell(5);
var desc = document.createElement('input');
desc .type = 'checkbox';
desc .name = 'desc[]';
desc.value='True';
desc .id = 'desc ' + iteration;
// set it to size of 40. setting sizes is good.
desc .style.width="100%";
esc.appendChild(desc);
var ano = row.insertCell(6);
var ano1 = document.createElement('input');
ano1 .type = 'text';
ano1 .name = 'ano1[]';
// the exact same thing with a unique id
ano1 .id = 'ano1 ' + iteration;
// set it to size of 40. setting sizes is good.
ano1 .style.width="100%";
ano.appendChild(ano1);
var reg = row.insertCell(7);
var reg1 = document.createElement('input');
reg1.type = 'checkbox';
reg1.name = ' registo[]';
// the exact same thing with a unique id
reg1.id = ' registo' + iteration;
reg1.value='True';
// set it to size of 40. setting sizes is good.
reg1.style.width="100%";
reg.appendChild(reg1);
var dt = row.insertCell(8);
var dt1 = document.createElement('input');
dt1.type = 'checkbox';
dt1.name = 'tribunal[]';
// the exact same thing with a unique id
dt1.id = 'tribunal' + iteration;
reg1.value='True'
// set it to size of 40. setting sizes is good.
dt1.style.width="100%";
dt.appendChild( dt1);
}
function removeRow()
{
// grab the element again!
var tbl = document.getElementById('mySampleTable');
// grab the length!
var lastRow = tbl.rows.length;
// delete the last row if there is more than one row!
if (lastRow > 1) tbl.deleteRow(lastRow - 1);
}
/*]]>*/
</script>
<style>
.dia {font-family: helvetica, arial; font-size: 8pt; color: #FFFFFF}
.data {font-family: helvetica, arial; font-size: 8pt; text-decoration:none; color:#191970}
.mes {font-family: helvetica, arial; font-size: 8pt}
.Cabecalho_Calendario {font-family: helvetica, arial; font-size: 10pt; color: #000000; text-decoration:none; font-weight:bold}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registo de Funcionarios</title>
<script type="text/javascript">
var maxWidth=110;
// height to resize large images to
var maxHeight=110;
// valid file types
var fileTypes=["bmp","gif","png","jpg","jpeg"];
// the id of the preview image tag
var outImage="previewField";
// what to display when the image is not valid
var defaultPic="spacer.gif";
/***** DO NOT EDIT BELOW *****/
function preview(what){
var source=what.value;
var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
for (var i=0; i<fileTypes.length; i++){
if (fileTypes[i]==ext){
break;
}
}
globalPic=new Image();
if (i<fileTypes.length){
//Obtenemos los datos de la imagen de firefox
try{
globalPic.src=what.files[0].getAsDataURL();
}catch(err){
globalPic.src=source;
}
}else {
globalPic.src=defaultPic;
alert("ESTA NO ES UNA IMAGEN VALIDA por favor escoge una imagen de tipo:nn"+fileTypes.join(", "));
}
setTimeout("applyChanges()",200);
}
var globalPic;
function applyChanges(){
var field=document.getElementById(outImage);
var x=parseInt(globalPic.width);
var y=parseInt(globalPic.height);
if (x>maxWidth) {
y*=maxWidth/x;
x=maxWidth;
}
if (y>maxHeight) {
x*=maxHeight/y;
y=maxHeight;
}
field.style.display=(x<1 || y<1)?"none":"";
field.src=globalPic.src;
field.width=x;
field.height=y;
}
// End -->
</script>
<script language='Javascript'>
function popdate(obj,div,tam,ddd)
{
if (ddd)
{
day = ""
mmonth = ""
ano = ""
c = 1
char = ""
for (s=0;s<parseInt(ddd.length);s++)
{
char = ddd.substr(s,1)
if (char == "/")
{
c++;
s++;
char = ddd.substr(s,1);
}
if (c==1) day += char
if (c==2) mmonth += char
if (c==3) ano += char
}
ddd = mmonth + "/" + day + "/" + ano
}
if(!ddd) {today = new Date()} else {today = new Date(ddd)}
date_Form = eval (obj)
if (date_Form.value == "") { date_Form = new Date()} else {date_Form = new Date(date_Form.value)}
ano = today.getFullYear();
mmonth = today.getMonth ();
day = today.toString ().substr (8,2)
umonth = new Array ("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro")
days_Feb = (!(ano % 4) ? 29 : 28)
days = new Array (31, days_Feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
if ((mmonth < 0) || (mmonth > 11)) alert(mmonth)
if ((mmonth - 1) == -1) {month_prior = 11; year_prior = ano - 1} else {month_prior = mmonth - 1; year_prior = ano}
if ((mmonth + 1) == 12) {month_next = 0; year_next = ano + 1} else {month_next = mmonth + 1; year_next = ano}
txt = "<table bgcolor='#efefff' style='border:solid #330099; border-width:2' cellspacing='0' cellpadding='3' border='0' width='"+tam+"' height='"+tam*1.1 +"'>"
txt += "<tr bgcolor='#FFFFFF'><td colspan='7' align='center'><table border='0' cellpadding='0' width='100%' bgcolor='#FFFFFF'><tr>"
txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano-1).toString())+"') class='Cabecalho_Calendario' title='Ano Anterior'><<</a></td>"
txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_prior+1).toString() + "/" + year_prior.toString())+"') class='Cabecalho_Calendario' title='Mês Anterior'><</a></td>"
txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_next+1).toString() + "/" + year_next.toString())+"') class='Cabecalho_Calendario' title='Próximo Mês'>></a></td>"
txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano+1).toString())+"') class='Cabecalho_Calendario' title='Próximo Ano'>>></a></td>"
txt += "<td width=20% align=right><a href=javascript:force_close('"+div+"') class='Cabecalho_Calendario' title='Fechar Calendário'><b>X</b></a></td></tr></table></td></tr>"
txt += "<tr><td colspan='7' align='right' bgcolor='#ccccff' class='mes'><a href=javascript:pop_year('"+obj+"','"+div+"','"+tam+"','" + (mmonth+1) + "') class='mes'>" + ano.toString() + "</a>"
txt += " <a href=javascript:pop_month('"+obj+"','"+div+"','"+tam+"','" + ano + "') class='mes'>" + umonth[mmonth] + "</a> <div id='popd' style='position:absolute'></div></td></tr>"
txt += "<tr bgcolor='#330099'><td width='14%' class='dia' align=center><b>Dom</b></td><td width='14%' class='dia' align=center><b>Seg</b></td><td width='14%' class='dia' align=center><b>Ter</b></td><td width='14%' class='dia' align=center><b>Qua</b></td><td width='14%' class='dia' align=center><b>Qui</b></td><td width='14%' class='dia' align=center><b>Sex<b></td><td width='14%' class='dia' align=center><b>Sab</b></td></tr>"
today1 = new Date((mmonth+1).toString() +"/01/"+ano.toString());
diainicio = today1.getDay () + 1;
week = d = 1
start = false;
for (n=1;n<= 42;n++)
{
if (week == 1) txt += "<tr bgcolor='#efefff' align=center>"
if (week==diainicio) {start = true}
if (d > days[mmonth]) {start=false}
if (start)
{
dat = new Date((mmonth+1).toString() + "/" + d + "/" + ano.toString())
day_dat = dat.toString().substr(0,10)
day_today = date_Form.toString().substr(0,10)
year_dat = dat.getFullYear ()
year_today = date_Form.getFullYear ()
colorcell = ((day_dat == day_today) && (year_dat == year_today) ? " bgcolor='#FFCC00' " : "" )
txt += "<td"+colorcell+" align=center><a href=javascript:block('"+ d + "/" + (mmonth+1).toString() + "/" + ano.toString() +"','"+ obj +"','" + div +"') class='data'>"+ d.toString() + "</a></td>"
d ++
}
else
{
txt += "<td class='data' align=center> </td>"
}
week ++
if (week == 8)
{
week = 1; txt += "</tr>"}
}
txt += "</table>"
div2 = eval (div)
div2.innerHTML = txt
}
// função para exibir a janela com os meses
function pop_month(obj, div, tam, ano)
{
txt = "<table bgcolor='#CCCCFF' border='0' width=80>"
for (n = 0; n < 12; n++) { txt += "<tr><td align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+("01/" + (n+1).toString() + "/" + ano.toString())+"')>" + umonth[n] +"</a></td></tr>" }
txt += "</table>"
popd.innerHTML = txt
}
// função para exibir a janela com os anos
function pop_year(obj, div, tam, umonth)
{
txt = "<table bgcolor='#CCCCFF' border='0' width=160>"
l = 1
for (n=1991; n<2012; n++)
{ if (l == 1) txt += "<tr>"
txt += "<td align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+(umonth.toString () +"/01/" + n) +"')>" + n + "</a></td>"
l++
if (l == 4)
{txt += "</tr>"; l = 1 }
}
txt += "</tr></table>"
popd.innerHTML = txt
}
// função para fechar o calendário
function force_close(div)
{ div2 = eval (div); div2.innerHTML = ''}
// função para fechar o calendário e setar a data no campo de data associado
function block(data, obj, div)
{
force_close (div)
obj2 = eval(obj)
obj2.value = data
}
</script>
<script language="javascript">
function getNumFunc(obj, idElement)
{
document.getElementById(idElement).value = obj.value;
}
</script>
<script type="text/javascript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<style type="text/css">
<!--
.style5 {font-size: 12px}
.style6 {font-size: 14px}
.style13 {font-size: medium}
.style14 {color: #FF0000}
-->
</style>
</head>
<body bgcolor="#F5F5F5" >
<form id="form1" name="form1" method="post" onSubmit="return valida(this)" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'] ?>?a=gravar">
<table width="100%" border="3" cellspacing="0" cellpadding="0">
<tr>
<th scope="col" bgcolor="#666666"><span class="style13"><font size="+3">TACV - Registo de Funcionários e Beneficiários</font></span></th>
</tr>
</table>
<table width="100%" border="3" cellspacing="2" cellpadding="2">
<tr>
<th colspan="4" scope="col" bgcolor="#3399FF">Dados de Procura </th>
<th width="34%" rowspan="2" scope="col"> </th>
<th width="18%" rowspan="2" scope="col" bgcolor="#3399FF"><font size="+3">Procurar</font></th>
</tr>
<tr>
<th width="7%" scope="row">Nome</th>
<td width="22%">
<label>
<select name="nome" style="width:100%" onChange="getNumFunc(this, 'Func_Num_TACV')">
<option value="">Seleciona Nome do Funcionario</option>
<?php
for($i=0; $i < $rst_terceiro; $i++)
{
echo '<option value="'.trim(mssql_result($f_terceiro,$i,"Func_Num_TACV")).'">'.trim(mssql_result($f_terceiro,$i,"Func_Nome")).' </option>';
}
?>
</select>
</label>
</td>
<td width="6%">Numero</td>
<td width="13%">
<label>
<input name="Func_Num_TACV" id="Func_Num_TACV" type="text" readonly="true" style="width:100px" value=""/>
</label>
</td>
</tr>
</table>
<table width="100%" border="3" cellspacing="0" cellpadding="0">
<tr>
<th width="82%" height="141" scope="col"><table width="101%" height="65" border="3" cellpadding="2" cellspacing="2">
<tr>
<th colspan="8" scope="col"><div align="left"><strong><font color="#3399FF">Funcionário</font></strong></div></th>
</tr>
<tr>
<th width="22%" height="28" scope="col"><div align="left" class="style5">Num TACV/Nome </div></th>
<th width="15%" scope="col">
<label>
<input type="text" name="numero" style="width:100%">
</label></th>
<th width="23%" scope="col">
<label><input type="text" name="nome1" style="width:100%"></label> </th>
<th width="6%" scope="col"><div align="left" class="style14">Activo</div></th>
<th width="6%" scope="col"><input name="Activo" type="checkbox" value="True" style="width:100%"></th>
<th width="8%" scope="col"> </th>
<th width="13%" scope="col">Fotografia</th>
<th width="7%" scope="col"> </th>
</tr>
</table>
<table width="100%" border="3" cellspacing="2" cellpadding="2">
<tr>
<th width="22%" height="25" scope="col"><div align="left"><span class="style5">Data Admissao/Categoria/Vinc </span></div></th>
<th width="17%" scope="col"><label>
<input NAME="data1" SIZE="10" MAXLENGTH="10" value="" />
<input TYPE="button" NAME="btnData1" VALUE="..." Onclick="javascript:popdate('document.form1.data1','pop1','150',document.form1.data1.value)">
<span id="pop1" style="position:absolute"></span>
</label></th>
<th colspan="3" scope="col"><label>
<select name="Categoria" style="width:100%" id="Categoria">
<?php
$consulta = mssql_query("SELECT * FROM T_Aux_Categorias");
while( $row = mssql_fetch_assoc($consulta) )
{
echo "<option value=\"{$row['Cat_Prof']}\">{$row['Cat_Prof']}</option>\n";
}
?>
</select>
</label></th>
<th width="5%" scope="col"><label>
</label></th>
<th width="3%" rowspan="4" scope="col">
<th width="12%" rowspan="3" scope="col">
<div>
<img alt="" id="previewField" src="Images/foto.gif"></div>
</th>
<th width="6%" scope="col"></th>
</tr>
<tr>
<th height="25" scope="col"><div align="left"><span class="style5">Diereccao/Depart/Delegacoes</span></div></th>
<th scope="col"><label>
<select name="Direccao" style="width:100%">
<?php
$cons = mssql_query("SELECT * FROM T_Aux_Direccao");
while( $row = mssql_fetch_assoc($cons) )
{
echo "<option value=\"{$row['Direccao']}\">{$row['Direccao']}</option>\n";
}
?>
</select>
</label></th>
<th width="11%" scope="col"><label>
<select name="Depart" style="width:100PX">
<?php
$co = mssql_query("SELECT * FROM T_Aux_Departamentos");
while( $row = mssql_fetch_assoc($co) )
{
echo "<option value=\"{$row['Dept']}\">{$row['Dept']}</option>\n";
}
?>
</select></label></th>
<th width="11%" scope="col"><label>
<select name="Delegacao" style="width:100PX">
<?php
$co = mssql_query("SELECT * FROM T_Aux_Delegacao");
while( $row = mssql_fetch_assoc($co) )
{
echo "<option value=\"{$row['Merc_Cod_Mercado']}\">{$row['Merc_Cod_Mercado']}</option>\n";
}
?>
</select></label></th>
<th colspan="2" scope="col"> </th>
<th scope="col">Eliminar</th>
</tr>
<tr>
<th height="25" scope="col"><div align="left" class="style5">
<blockquote>
<p>Observacao:</p>
</blockquote>
</div></th>
<th colspan="5" scope="col">
<div align="left">
<textarea name="textarea" style="width:80%"></textarea>
</div>
</th>
<th scope="col"> </th>
</tr>
<tr>
<th height="25" scope="col">Inserir Fotografia</th>
<th colspan="5" scope="col">
<div align="left" style="line-height: 1.9em;">
<!-- Colocar aqui a chamada da Função "PREVIEW" no evento "onchange" -->
<input type="file" id="picField" onChange="preview(this)">
</div>
</th>
<th scope="col"> </th>
</tr>
</table>
<table width="100%" border="3" cellspacing="2" cellpadding="2">
<tr>
<th scope="col"><div align="left" class="style6"><font color="#3399FF">Beneficiarios</font></div></th>
</tr>
</table>
<table width="100%" height="36" border="3" cellpadding="2" cellspacing="2" id="mySampleTable">
<tr>
<th width="9%" class="style5" scope="col"><div align="left">Doc Ident</div></th>
<th width="26%" scope="col"><div align="left" class="style5">Nome</div></th>
<th width="13%" scope="col"><div align="left" class="style5">Dependencia</div></th>
<th width="12%" scope="col"><div align="left" class="style5">Data Nasc</div></th>
<th width="7%" scope="col"><div align="left" class="style5">Idade</div></th>
<th width="7%" scope="col"><div align="left" class="style5">DocEsc</div></th>
<th width="10%" class="style5" scope="col">Ano DocEsc</th>
<th width="6%" class="style5" scope="col">RegCas</th>
<th width="10%" class="style5" scope="col">DocTrib/Cart</th>
</tr>
<tr>
<td><input name="doc" type="text" width="100%"></td>
<td><input name="nomebeneficiario" type="text" style="width:100%"></td>
<td>
<select name="dependencia" style="width:100%">
<option selected="selected">Selecciona</option>
<option value="Esposo/a">Esposo/a</option>
<option value="Filho/a">Filho/a</option>
<option value="Entiado/a">Entiado/a</option>
</select></td>
<td><input name="datanascimento" type="text" style="width:100%" onChange="idade(this.form, this);"/></td>
<td><input name="AGE" type="text" style="width:100%"></td>
<td><input name="docesc" type="checkbox" style="width:100%"></td>
<td><input name="anoescolar" type="text" style="width:100%"></td>
<td><input name="regcas" type="checkbox" style="width:100%"></td>
<td><input name="doctrib" type="checkbox" style="width:100%"></td></tr>
</table>
<p align="right">
<input type="button" value="Adicionar" onClick="addRow();" />
<input type="button" value="Remover" onClick="removeRow();" />
</p>
<p> </p></th>
<th width="18%" valign="top" scope="col" >
<select name="nomm" size="20" multiple="MULTIPLE" style="width:100%" onChange="getNumFunc(this, 'Func_Foto')">
<?php
$co = mssql_query("SELECT * FROM T_Terceiros order by Func_Nome ");
while( $row = mssql_fetch_assoc($co) )
{
echo "<option value=\"{$row['Func_Nome']}\">{$row['Func_Nome']}</option>\n";
}
?>
</select> </th>
</tr>
</table>
<table width="60%" >
<tr>
<td><input name="fechar" type="button" id="fechar" value="Fechar" onClick="location. href= 'Menu_principal.php' "/></td>
<td><input name="Gravar" type="submit" value="Gravar/Inserir"/>
</td>
<td><input name="cancelar" type="button" value="Cancelar" /></td>
<td><input name="Prim" type="button" value="|<Prim" /></td>
<td><input name="Ant" type="button" value="<Ant" /></td>
<td><input name="Prox" type="button" value="Prox>" /></td>
<td><input name="Ult" type="button" value="<|Prim" /></td>
<td><input name="Imprimir" type="button" value="Impimir Ficha Funcionário" /></td>
</tr>
</table>
</form>
<?php
// Recuperamos a ação enviada pelo formulário
$a = $_GET['a'];
// Verificamos se a ação é de busca
if ($a == "gravar")
{
$num = trim($_POST['numero']);
$nom = trim($_POST['nome1']);
$data = trim($_POST['data1']);
$activo= trim($_POST['Activo']);
$Direccao= trim($_POST['Direccao']);
$departamento=trim($_POST['Depart']);
$delegacao=trim($_POST['Delegacao']);
$categoria = trim($_POST['Categoria']);
$vinculo = trim($_POST['vinculo']);
$obs = trim($_POST['obs']);
$nome = trim($_POST['nome'][0]);
$dependencia = trim($_POST['Dependencia'][0]);
$Data= trim($_POST['Datanasc'][0]);
$Idade = trim($_POST['Idade'][0]);
$ano_escolar = trim($_POST['ano_escolar'][0]);
$doc_escolar = trim($_POST['doc_escolar'][0]);
$regcas = trim($_POST['regcas'][0]);
$doc_tribunal = trim($_POST['doc_tribunal'][0]);
$arquivo = trim($_FILES["arquivo"][0]);
$pasta_dir = "arquivos/";//diretorio dos arquivos
//se não existir a pasta ele cria uma
if(!file_exists($pasta_dir)){
mkdir($pasta_dir);
}
$arquivo_nome = $pasta_dir . $arquivo["name"];
move_uploaded_file($arquivo["tmp_name"], $arquivo_nome);
$seleciona = mssql_query("SELECT Func_Num_TACV from T_Terceiros where Func_Num_TACV = '$num'");
$select = mssql_num_rows($seleciona);
if ($select != 0)
{
echo '<script language="javascript">alert("Ja existe um funcionario com este numero!");
</script>';
}
else
$sql= "INSERT INTO T_Terceiros
VALUES ('$num', '$nom','$data','$categoria','$Direccao','$departamento', '','$delegacao','$obs','','','','$arquivo_nome','$activo','$vinculo')";
$i = 0;
foreach($_POST["doc"] as $doc) {
$sql1 = "INSERT INTO T_Dependentes Values('$doc','','{$_POST['nome'][$i]}','{$_POST['data'][$i]}',
'{$_POST['relacao'][$i]}','{$_POST['desc'][$i]}','{$_POST['ano1'][$i]}',
'{$_POST['registo'][$i]}','{$_POST['tribunal'][$i]}')";
$result1 = mssql_query($sql1);
++$i;
}
$result = mssql_query($sql);
if(!$result){
die("Falha ao executar o comando: " . mssql_error());
header('Location: .php');
exit;
}
else
{
echo '<script language="javascript">alert("Dados salvos com sucesso!");</script>';
}
}
?>
</body>
</html>
toydiaz 0 Light Poster
thanks for everybory, but i still with that problem...i keep trying here. if can help -me will be very good.
<?php
require_once('class_bd.php');
$_bd = new ClassConnectBd();
$_bd->connectBD();
$f_terceiro = $_bd->query('SELECT * FROM T_Terceiros');
$rst_terceiro = mssql_num_rows($f_terceiro);
?>
<html>
<head>
<script language="javascript">
function valida(){
d = document.form1;
if (d.numero.value == ""){
alert("O campo " + d.numero.name + " deve ser preenchido!");
d.numero.focus();
return false;
}
if(d.nome1.value==''){
alert("O campo " + d.nome1.name + " Funcionario deve ser preenchido!");
d.nome1.focus();
return false;
}
if (d.data1.value == ""){
alert("O campo " + d.data1.name + " deve ser preenchido!");
d.data1.focus();
return false;
}
if (d.doc.value == ""){
alert("O campo " + d.doc.name + " deve ser preenchido!");
d.doc.focus();
return false;
}
if (d.nomebeneficiario.value == ""){
alert("O campo " + d.nomebeneficiario.name + " deve ser preenchido!");
d.nomebeneficiario.focus();
return false;
}
if (d.dependencia.value == ""){
alert("O campo " + d.dependencia.name + " deve ser preenchido!");
d.dependencia.focus();
return false;
}
if (d.datanascimento.value == ""){
alert("O campo " + d.datanascimento.name + " deve ser preenchido!");
d.datanascimento.focus();
return false;
}
if (d.docescolar.value == ""){
alert("O campo " + d.datanascimento.name + " deve ser preenchido!");
d.datanascimento.focus();
return false;
}
if (d.anoescolar.value == ""){
alert("O campo " + d.anoescolar.name + " deve ser preenchido!");
d.anoescolar.focus();
return false;
}
return true;
}
</script>
<script>
function idade(object, birthDay){
now = new Date();
bD = birthDay.value.split('/');
if(bD.length==3){
born = new Date(bD[2], bD[1]*1-1, bD[0]);
years = new Date(now.getTime() - born.getTime());
base = new Date(0);
document.all['AGE'].value = years.getFullYear()-base.getFullYear();
}
}
</script>
<script>
function countAge(_id, birthDay){
id_v = "AGE"+_id;
now = new Date();
bD = birthDay.value.split('/');
if(bD.length==3){
born = new Date(bD[2], bD[1]*1-1, bD[0]);
years = new Date(now.getTime() - born.getTime());
base = new Date(0);
document.getElementById(id_v).value = years.getFullYear()-base.getFullYear();
document.all['AGE'].value = years.getFullYear()-base.getFullYear();
}
}
</script>
<script type="text/javascript">
/*<![CDATA[*/
function addRow()
{
var tbl = document.getElementById('mySampleTable');
var lastRow = tbl.rows.length;
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
var cellLeft = row.insertCell(0);
var doc = document.createElement('input');
doc.type = 'text';
doc.name = 'doc[]';
doc.id = 'doc' + iteration;
doc.style.width="100%";
cellLeft.appendChild(doc);
var id_age = "AGE"+iteration;
var func = row.insertCell(1);
var nome = document.createElement('input');
nome.type = 'text';
nome.name = 'nome[]';
nome.id = 'nome' + iteration;
nome.style.width="100%";
func.appendChild(nome);
var cellRightSel = row.insertCell(2);
var sel = document.createElement('select');
sel.name = 'relacao[]';
sel.id = 'relacao' + iteration;
sel.options[0] = new Option('Selecciona', '');
sel.options[1] = new Option('Espaoso/a', 'Espaoso/a');
sel.options[2] = new Option('Filho/a', 'Filho/a');
sel.options[3] = new Option('Entiado/a', 'Entiado/a');
cellRightSel.appendChild(sel);
var direita = row.insertCell(3);
var inp = document.createElement('input');
inp.type = 'text';
inp.name = 'data[]';
inp.id = 'data' + iteration;
inp.setAttribute("onchange","countAge("+iteration+", this);");
inp.style.width="100%";
direita.appendChild(inp);
var idade= row.insertCell(4);
var age1 = document.createElement('input');
age1.type = 'text';
age1.setAttribute("name","AGE[]");
// the exact same thing with a unique id
age1.setAttribute("id",""+id_age);
// set it to size of 40. setting sizes is good.
age1.style.width="100%";
idade.appendChild(age1);
var esc = row.insertCell(5);
var desc = document.createElement('input');
desc .type = 'checkbox';
desc .name = 'desc[]';
desc.value='True';
desc .id = 'desc ' + iteration;
// set it to size of 40. setting sizes is good.
desc .style.width="100%";
esc.appendChild(desc);
var ano = row.insertCell(6);
var ano1 = document.createElement('input');
ano1 .type = 'text';
ano1 .name = 'ano1[]';
// the exact same thing with a unique id
ano1 .id = 'ano1 ' + iteration;
// set it to size of 40. setting sizes is good.
ano1 .style.width="100%";
ano.appendChild(ano1);
var reg = row.insertCell(7);
var reg1 = document.createElement('input');
reg1.type = 'checkbox';
reg1.name = ' registo[]';
// the exact same thing with a unique id
reg1.id = ' registo' + iteration;
reg1.value='True';
// set it to size of 40. setting sizes is good.
reg1.style.width="100%";
reg.appendChild(reg1);
var dt = row.insertCell(8);
var dt1 = document.createElement('input');
dt1.type = 'checkbox';
dt1.name = 'tribunal[]';
// the exact same thing with a unique id
dt1.id = 'tribunal' + iteration;
reg1.value='True'
// set it to size of 40. setting sizes is good.
dt1.style.width="100%";
dt.appendChild( dt1);
}
function removeRow()
{
// grab the element again!
var tbl = document.getElementById('mySampleTable');
// grab the length!
var lastRow = tbl.rows.length;
// delete the last row if there is more than one row!
if (lastRow > 1) tbl.deleteRow(lastRow - 1);
}
/*]]>*/
</script>
<style>
.dia {font-family: helvetica, arial; font-size: 8pt; color: #FFFFFF}
.data {font-family: helvetica, arial; font-size: 8pt; text-decoration:none; color:#191970}
.mes {font-family: helvetica, arial; font-size: 8pt}
.Cabecalho_Calendario {font-family: helvetica, arial; font-size: 10pt; color: #000000; text-decoration:none; font-weight:bold}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registo de Funcionarios</title>
<script type="text/javascript">
var maxWidth=110;
// height to resize large images to
var maxHeight=110;
// valid file types
var fileTypes=["bmp","gif","png","jpg","jpeg"];
// the id of the preview image tag
var outImage="previewField";
// what to display when the image is not valid
var defaultPic="spacer.gif";
/***** DO NOT EDIT BELOW *****/
function preview(what){
var source=what.value;
var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
for (var i=0; i<fileTypes.length; i++){
if (fileTypes[i]==ext){
break;
}
}
globalPic=new Image();
if (i<fileTypes.length){
//Obtenemos los datos de la imagen de firefox
try{
globalPic.src=what.files[0].getAsDataURL();
}catch(err){
globalPic.src=source;
}
}else {
globalPic.src=defaultPic;
alert("ESTA NO ES UNA IMAGEN VALIDA por favor escoge una imagen de tipo:nn"+fileTypes.join(", "));
}
setTimeout("applyChanges()",200);
}
var globalPic;
function applyChanges(){
var field=document.getElementById(outImage);
var x=parseInt(globalPic.width);
var y=parseInt(globalPic.height);
if (x>maxWidth) {
y*=maxWidth/x;
x=maxWidth;
}
if (y>maxHeight) {
x*=maxHeight/y;
y=maxHeight;
}
field.style.display=(x<1 || y<1)?"none":"";
field.src=globalPic.src;
field.width=x;
field.height=y;
}
// End -->
</script>
<script language='Javascript'>
function popdate(obj,div,tam,ddd)
{
if (ddd)
{
day = ""
mmonth = ""
ano = ""
c = 1
char = ""
for (s=0;s<parseInt(ddd.length);s++)
{
char = ddd.substr(s,1)
if (char == "/")
{
c++;
s++;
char = ddd.substr(s,1);
}
if (c==1) day += char
if (c==2) mmonth += char
if (c==3) ano += char
}
ddd = mmonth + "/" + day + "/" + ano
}
if(!ddd) {today = new Date()} else {today = new Date(ddd)}
date_Form = eval (obj)
if (date_Form.value == "") { date_Form = new Date()} else {date_Form = new Date(date_Form.value)}
ano = today.getFullYear();
mmonth = today.getMonth ();
day = today.toString ().substr (8,2)
umonth = new Array ("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro")
days_Feb = (!(ano % 4) ? 29 : 28)
days = new Array (31, days_Feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
if ((mmonth < 0) || (mmonth > 11)) alert(mmonth)
if ((mmonth - 1) == -1) {month_prior = 11; year_prior = ano - 1} else {month_prior = mmonth - 1; year_prior = ano}
if ((mmonth + 1) == 12) {month_next = 0; year_next = ano + 1} else {month_next = mmonth + 1; year_next = ano}
txt = "<table bgcolor='#efefff' style='border:solid #330099; border-width:2' cellspacing='0' cellpadding='3' border='0' width='"+tam+"' height='"+tam*1.1 +"'>"
txt += "<tr bgcolor='#FFFFFF'><td colspan='7' align='center'><table border='0' cellpadding='0' width='100%' bgcolor='#FFFFFF'><tr>"
txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano-1).toString())+"') class='Cabecalho_Calendario' title='Ano Anterior'><<</a></td>"
txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_prior+1).toString() + "/" + year_prior.toString())+"') class='Cabecalho_Calendario' title='Mês Anterior'><</a></td>"
txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_next+1).toString() + "/" + year_next.toString())+"') class='Cabecalho_Calendario' title='Próximo Mês'>></a></td>"
txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano+1).toString())+"') class='Cabecalho_Calendario' title='Próximo Ano'>>></a></td>"
txt += "<td width=20% align=right><a href=javascript:force_close('"+div+"') class='Cabecalho_Calendario' title='Fechar Calendário'><b>X</b></a></td></tr></table></td></tr>"
txt += "<tr><td colspan='7' align='right' bgcolor='#ccccff' class='mes'><a href=javascript:pop_year('"+obj+"','"+div+"','"+tam+"','" + (mmonth+1) + "') class='mes'>" + ano.toString() + "</a>"
txt += " <a href=javascript:pop_month('"+obj+"','"+div+"','"+tam+"','" + ano + "') class='mes'>" + umonth[mmonth] + "</a> <div id='popd' style='position:absolute'></div></td></tr>"
txt += "<tr bgcolor='#330099'><td width='14%' class='dia' align=center><b>Dom</b></td><td width='14%' class='dia' align=center><b>Seg</b></td><td width='14%' class='dia' align=center><b>Ter</b></td><td width='14%' class='dia' align=center><b>Qua</b></td><td width='14%' class='dia' align=center><b>Qui</b></td><td width='14%' class='dia' align=center><b>Sex<b></td><td width='14%' class='dia' align=center><b>Sab</b></td></tr>"
today1 = new Date((mmonth+1).toString() +"/01/"+ano.toString());
diainicio = today1.getDay () + 1;
week = d = 1
start = false;
for (n=1;n<= 42;n++)
{
if (week == 1) txt += "<tr bgcolor='#efefff' align=center>"
if (week==diainicio) {start = true}
if (d > days[mmonth]) {start=false}
if (start)
{
dat = new Date((mmonth+1).toString() + "/" + d + "/" + ano.toString())
day_dat = dat.toString().substr(0,10)
day_today = date_Form.toString().substr(0,10)
year_dat = dat.getFullYear ()
year_today = date_Form.getFullYear ()
colorcell = ((day_dat == day_today) && (year_dat == year_today) ? " bgcolor='#FFCC00' " : "" )
txt += "<td"+colorcell+" align=center><a href=javascript:block('"+ d + "/" + (mmonth+1).toString() + "/" + ano.toString() +"','"+ obj +"','" + div +"') class='data'>"+ d.toString() + "</a></td>"
d ++
}
else
{
txt += "<td class='data' align=center> </td>"
}
week ++
if (week == 8)
{
week = 1; txt += "</tr>"}
}
txt += "</table>"
div2 = eval (div)
div2.innerHTML = txt
}
// função para exibir a janela com os meses
function pop_month(obj, div, tam, ano)
{
txt = "<table bgcolor='#CCCCFF' border='0' width=80>"
for (n = 0; n < 12; n++) { txt += "<tr><td align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+("01/" + (n+1).toString() + "/" + ano.toString())+"')>" + umonth[n] +"</a></td></tr>" }
txt += "</table>"
popd.innerHTML = txt
}
// função para exibir a janela com os anos
function pop_year(obj, div, tam, umonth)
{
txt = "<table bgcolor='#CCCCFF' border='0' width=160>"
l = 1
for (n=1991; n<2012; n++)
{ if (l == 1) txt += "<tr>"
txt += "<td align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+(umonth.toString () +"/01/" + n) +"')>" + n + "</a></td>"
l++
if (l == 4)
{txt += "</tr>"; l = 1 }
}
txt += "</tr></table>"
popd.innerHTML = txt
}
// função para fechar o calendário
function force_close(div)
{ div2 = eval (div); div2.innerHTML = ''}
// função para fechar o calendário e setar a data no campo de data associado
function block(data, obj, div)
{
force_close (div)
obj2 = eval(obj)
obj2.value = data
}
</script>
<script language="javascript">
function getNumFunc(obj, idElement)
{
document.getElementById(idElement).value = obj.value;
}
</script>
<script type="text/javascript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<style type="text/css">
<!--
.style5 {font-size: 12px}
.style6 {font-size: 14px}
.style13 {font-size: medium}
.style14 {color: #FF0000}
-->
</style>
</head>
<body bgcolor="#F5F5F5" >
<form id="form1" name="form1" method="post" onSubmit="return valida(this)" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'] ?>?a=gravar">
<table width="100%" border="3" cellspacing="0" cellpadding="0">
<tr>
<th scope="col" bgcolor="#666666"><span class="style13"><font size="+3">TACV - Registo de Funcionários e Beneficiários</font></span></th>
</tr>
</table>
<table width="100%" border="3" cellspacing="2" cellpadding="2">
<tr>
<th colspan="4" scope="col" bgcolor="#3399FF">Dados de Procura </th>
<th width="34%" rowspan="2" scope="col"> </th>
<th width="18%" rowspan="2" scope="col" bgcolor="#3399FF"><font size="+3">Procurar</font></th>
</tr>
<tr>
<th width="7%" scope="row">Nome</th>
<td width="22%">
<label>
<select name="nome" style="width:100%" onChange="getNumFunc(this, 'Func_Num_TACV')">
<option value="">Seleciona Nome do Funcionario</option>
<?php
for($i=0; $i < $rst_terceiro; $i++)
{
echo '<option value="'.trim(mssql_result($f_terceiro,$i,"Func_Num_TACV")).'">'.trim(mssql_result($f_terceiro,$i,"Func_Nome")).' </option>';
}
?>
</select>
</label>
</td>
<td width="6%">Numero</td>
<td width="13%">
<label>
<input name="Func_Num_TACV" id="Func_Num_TACV" type="text" readonly="true" style="width:100px" value=""/>
</label>
</td>
</tr>
</table>
<table width="100%" border="3" cellspacing="0" cellpadding="0">
<tr>
<th width="82%" height="141" scope="col"><table width="101%" height="65" border="3" cellpadding="2" cellspacing="2">
<tr>
<th colspan="8" scope="col"><div align="left"><strong><font color="#3399FF">Funcionário</font></strong></div></th>
</tr>
<tr>
<th width="22%" height="28" scope="col"><div align="left" class="style5">Num TACV/Nome </div></th>
<th width="15%" scope="col">
<label>
<input type="text" name="numero" style="width:100%">
</label></th>
<th width="23%" scope="col">
<label><input type="text" name="nome1" style="width:100%"></label> </th>
<th width="6%" scope="col"><div align="left" class="style14">Activo</div></th>
<th width="6%" scope="col"><input name="Activo" type="checkbox" value="True" style="width:100%"></th>
<th width="8%" scope="col"> </th>
<th width="13%" scope="col">Fotografia</th>
<th width="7%" scope="col"> </th>
</tr>
</table>
<table width="100%" border="3" cellspacing="2" cellpadding="2">
<tr>
<th width="22%" height="25" scope="col"><div align="left"><span class="style5">Data Admissao/Categoria/Vinc </span></div></th>
<th width="17%" scope="col"><label>
<input NAME="data1" SIZE="10" MAXLENGTH="10" value="" />
<input TYPE="button" NAME="btnData1" VALUE="..." Onclick="javascript:popdate('document.form1.data1','pop1','150',document.form1.data1.value)">
<span id="pop1" style="position:absolute"></span>
</label></th>
<th colspan="3" scope="col"><label>
<select name="Categoria" style="width:100%" id="Categoria">
<?php
$consulta = mssql_query("SELECT * FROM T_Aux_Categorias");
while( $row = mssql_fetch_assoc($consulta) )
{
echo "<option value=\"{$row['Cat_Prof']}\">{$row['Cat_Prof']}</option>\n";
}
?>
</select>
</label></th>
<th width="5%" scope="col"><label>
</label></th>
<th width="3%" rowspan="4" scope="col">
<th width="12%" rowspan="3" scope="col">
<div>
<img alt="" id="previewField" src="Images/foto.gif"></div>
</th>
<th width="6%" scope="col"></th>
</tr>
<tr>
<th height="25" scope="col"><div align="left"><span class="style5">Diereccao/Depart/Delegacoes</span></div></th>
<th scope="col"><label>
<select name="Direccao" style="width:100%">
<?php
$cons = mssql_query("SELECT * FROM T_Aux_Direccao");
while( $row = mssql_fetch_assoc($cons) )
{
echo "<option value=\"{$row['Direccao']}\">{$row['Direccao']}</option>\n";
}
?>
</select>
</label></th>
<th width="11%" scope="col"><label>
<select name="Depart" style="width:100PX">
<?php
$co = mssql_query("SELECT * FROM T_Aux_Departamentos");
while( $row = mssql_fetch_assoc($co) )
{
echo "<option value=\"{$row['Dept']}\">{$row['Dept']}</option>\n";
}
?>
</select></label></th>
<th width="11%" scope="col"><label>
<select name="Delegacao" style="width:100PX">
<?php
$co = mssql_query("SELECT * FROM T_Aux_Delegacao");
while( $row = mssql_fetch_assoc($co) )
{
echo "<option value=\"{$row['Merc_Cod_Mercado']}\">{$row['Merc_Cod_Mercado']}</option>\n";
}
?>
</select></label></th>
<th colspan="2" scope="col"> </th>
<th scope="col">Eliminar</th>
</tr>
<tr>
<th height="25" scope="col"><div align="left" class="style5">
<blockquote>
<p>Observacao:</p>
</blockquote>
</div></th>
<th colspan="5" scope="col">
<div align="left">
<textarea name="textarea" style="width:80%"></textarea>
</div>
</th>
<th scope="col"> </th>
</tr>
<tr>
<th height="25" scope="col">Inserir Fotografia</th>
<th colspan="5" scope="col">
<div align="left" style="line-height: 1.9em;">
<!-- Colocar aqui a chamada da Função "PREVIEW" no evento "onchange" -->
<input type="file" id="picField" onChange="preview(this)">
</div>
</th>
<th scope="col"> </th>
</tr>
</table>
<table width="100%" border="3" cellspacing="2" cellpadding="2">
<tr>
<th scope="col"><div align="left" class="style6"><font color="#3399FF">Beneficiarios</font></div></th>
</tr>
</table>
<table width="100%" height="36" border="3" cellpadding="2" cellspacing="2" id="mySampleTable">
<tr>
<th width="9%" class="style5" scope="col"><div align="left">Doc Ident</div></th>
<th width="26%" scope="col"><div align="left" class="style5">Nome</div></th>
<th width="13%" scope="col"><div align="left" class="style5">Dependencia</div></th>
<th width="12%" scope="col"><div align="left" class="style5">Data Nasc</div></th>
<th width="7%" scope="col"><div align="left" class="style5">Idade</div></th>
<th width="7%" scope="col"><div align="left" class="style5">DocEsc</div></th>
<th width="10%" class="style5" scope="col">Ano DocEsc</th>
<th width="6%" class="style5" scope="col">RegCas</th>
<th width="10%" class="style5" scope="col">DocTrib/Cart</th>
</tr>
<tr>
<td><input name="doc" type="text" width="100%"></td>
<td><input name="nomebeneficiario" type="text" style="width:100%"></td>
<td>
<select name="dependencia" style="width:100%">
<option selected="selected">Selecciona</option>
<option value="Esposo/a">Esposo/a</option>
<option value="Filho/a">Filho/a</option>
<option value="Entiado/a">Entiado/a</option>
</select></td>
<td><input name="datanascimento" type="text" style="width:100%" onChange="idade(this.form, this);"/></td>
<td><input name="AGE" type="text" style="width:100%"></td>
<td><input name="docesc" type="checkbox" style="width:100%"></td>
<td><input name="anoescolar" type="text" style="width:100%"></td>
<td><input name="regcas" type="checkbox" style="width:100%"></td>
<td><input name="doctrib" type="checkbox" style="width:100%"></td></tr>
</table>
<p align="right">
<input type="button" value="Adicionar" onClick="addRow();" />
<input type="button" value="Remover" onClick="removeRow();" />
</p>
<p> </p></th>
<th width="18%" valign="top" scope="col" >
<select name="nomm" size="20" multiple="MULTIPLE" style="width:100%" onChange="getNumFunc(this, 'Func_Foto')">
<?php
$co = mssql_query("SELECT * FROM T_Terceiros order by Func_Nome ");
while( $row = mssql_fetch_assoc($co) )
{
echo "<option value=\"{$row['Func_Nome']}\">{$row['Func_Nome']}</option>\n";
}
?>
</select> </th>
</tr>
</table>
<table width="60%" >
<tr>
<td><input name="fechar" type="button" id="fechar" value="Fechar" onClick="location. href= 'Menu_principal.php' "/></td>
<td><input name="Gravar" type="submit" value="Gravar/Inserir"/>
</td>
<td><input name="cancelar" type="button" value="Cancelar" /></td>
<td><input name="Prim" type="button" value="|<Prim" /></td>
<td><input name="Ant" type="button" value="<Ant" /></td>
<td><input name="Prox" type="button" value="Prox>" /></td>
<td><input name="Ult" type="button" value="<|Prim" /></td>
<td><input name="Imprimir" type="button" value="Impimir Ficha Funcionário" /></td>
</tr>
</table>
</form>
<?php
// Recuperamos a ação enviada pelo formulário
$a = $_GET['a'];
// Verificamos se a ação é de busca
if ($a == "gravar")
{
$num = trim($_POST['numero']);
$nom = trim($_POST['nome1']);
$data = trim($_POST['data1']);
$activo= trim($_POST['Activo']);
$Direccao= trim($_POST['Direccao']);
$departamento=trim($_POST['Depart']);
$delegacao=trim($_POST['Delegacao']);
$categoria = trim($_POST['Categoria']);
$vinculo = trim($_POST['vinculo']);
$obs = trim($_POST['obs']);
$nome = trim($_POST['nome'][0]);
$dependencia = trim($_POST['Dependencia'][0]);
$Data= trim($_POST['Datanasc'][0]);
$Idade = trim($_POST['Idade'][0]);
$ano_escolar = trim($_POST['ano_escolar'][0]);
$doc_escolar = trim($_POST['doc_escolar'][0]);
$regcas = trim($_POST['regcas'][0]);
$doc_tribunal = trim($_POST['doc_tribunal'][0]);
$arquivo = trim($_FILES["arquivo"][0]);
$pasta_dir = "arquivos/";//diretorio dos arquivos
//se não existir a pasta ele cria uma
if(!file_exists($pasta_dir)){
mkdir($pasta_dir);
}
$arquivo_nome = $pasta_dir . $arquivo["name"];
move_uploaded_file($arquivo["tmp_name"], $arquivo_nome);
$seleciona = mssql_query("SELECT Func_Num_TACV from T_Terceiros where Func_Num_TACV = '$num'");
$select = mssql_num_rows($seleciona);
if ($select != 0)
{
echo '<script language="javascript">alert("Ja existe um funcionario com este numero!");
</script>';
}
else
$sql= "INSERT INTO T_Terceiros
VALUES ('$num', '$nom','$data','$categoria','$Direccao','$departamento', '','$delegacao','$obs','','','','$arquivo_nome','$activo','$vinculo')";
$i = 0;
foreach($_POST["doc"] as $doc) {
$sql1 = "INSERT INTO T_Dependentes Values('$doc','','{$_POST['nome'][$i]}','{$_POST['data'][$i]}',
'{$_POST['relacao'][$i]}','{$_POST['desc'][$i]}','{$_POST['ano1'][$i]}',
'{$_POST['registo'][$i]}','{$_POST['tribunal'][$i]}')";
$result1 = mssql_query($sql1);
++$i;
}
$result = mssql_query($sql);
if(!$result){
die("Falha ao executar o comando: " . mssql_error());
header('Location: .php');
exit;
}
else
{
echo '<script language="javascript">alert("Dados salvos com sucesso!");</script>';
}
}
?>
</body>
</html>
Jayavardhan -2 Light Poster
Toydyiaz, i can't help out with this one. Because, i didn't get your actual requirement tillnow. Sorry!!!
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.