Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 09-25-2008, 06:57 AM   #1 (permalink)
Registered User
 
Join Date: Sep 2008
Posts: 1
OS: Windows XP SP3


Question newbie having trouble with php and forms

hello guys!
i'm newbie to php and now trying to make some nice stuff.
i'm developing a project to manage some data related to public health using php and xml.
well, but going to the point, i have a page with forms like this:

Code:
<html>
<head>
<title>Incluir Estabelecimento</title>
</head>
<body>
<form action="salva.php" method="post">
<p><b>Nome*: </b> <input type="text" name="nome" /></p>
<p><b>Respons&aacute;vel*: </b> <input type="text" name="resp" /></p>
<p><b>Endere&ccedil;o*: </b> <input type="text" name="ende" /></p>
<p><b>Telefone: </b> <input type="text" name="tele" /></p>
<p><b>Ramo de atividade: </b> <input type="text" name="ramo" /></p>
<p><b>Emiss&atilde;o do &uacute;ltimo alvar&aacute;: </b> <input type="text" name="emis" /></p>
<p><b>Vencimento do alvar&aacute;: </b> <input type="text" name="venc" /></p>
<input type="hidden" value="OK" name="esco" />
<p><input type="submit" value="Incluir dados" name="incl" /></p>
</body>
</html>
and this one submits data from the form to salva.php:

Code:
<?php
$tabela = new DOMDocument('1.0', 'utf8');
	$tabela->formatOutput = true;
	
$nomes = trim($_POST['nome']);
$resps = trim($_POST['resp']);
$endes = trim($_POST['ende']);
$teles = trim($_POST['tele']);
$ramos = trim($_POST['ramo']);
$emiss = trim($_POST['emis']);
$vencs = trim($_POST['venc']);

$spn = strlen($nomes);
$spr = strlen($resps);
$spe = strlen($endes);

// ---------------------------------

function escreveNovo() {
if (!isset($nomes) || !isset($resps) || !isset($endes)) {
	echo("Preencha os campos obrigatórios! <a href=\"http://localhost/visa/inclui.php\">Voltar </a>");
	exit;
}
else {	
	header("Content-type: text/xml");
	$indi = strpos($resps, " ");
	$espa = $indi - 1;
	$titu = substr($resps, 0, $espa);

	$pri = $tabela->createElement("estabelecimento");
	$tabela->appendChild($pri);
	$sec = $tabela->createAttr("dono");
	$pri->appendChild($sec);
	$ter = $tabela->createElement("nome");
	$pri->appendChild($ter);
	$qua = $tabela->createElement("responsavel");
	$pri->appendChild($qua);
	$qui = $tabela->createElement("endereco");
	$pri->appendChild($qui);
	$sex = $tabela->createElement("telefone");
	$pri->appendChild($sex);
	$set = $tabela -> createElement("ramo");
	$pri->appendChild($set);
	$oit = $tabela -> createElement("emissao");
	$pri->appendChild($oit);
	$non = $tabela -> createElement("vencimento");
	$pri->appendChild($non);

	$utit = $tabela->createTextNode($titu);
	$sec->appendChild($utit);
	$enom = $tabela->createTextNode($nomes);
	$ter->appendChild($enom);
	$pser = $tabela->createTextNode($resps);
	$qua->appendChild($pser);
	$edne = $tabela->createTextNode($endes);
	$qui->appendChild($edne);
	$elet = $tabela->createTextNode($teles);
	$sex->appendChild($elet);
	$omar = $tabela->createTextNode($ramos);
	$set->appendChild($omar);
	$sime = $tabela->reateTextNode($emiss);
	$oit->appendChild($sime);
	$cnev = $tabela->createTextNode($vencs);
	$non->appendChild($cnev);
}
}

// -----------------------------------------

escreveNovo();
$tabela->save('estab.xml');
?>
i'm in trouble, becuase even when all text fields are filled, the script ends up to the first "if" clause in function escreveNovo(), and returns the message (which should appear only if one of the first three fields were empty).

i'm really stuck with that. Another important thing is that i've already tried to echo the strings from the forms, and they are actually there, working perfectly!

thanks in advance for the support!
demiancalixto is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 09-25-2008, 03:39 PM   #2 (permalink)
Moderator: Design
 
dm01's Avatar
 
Join Date: Oct 2006
Location: Richmond, B.C.; Canada
Posts: 1,446
OS: Windows XP [Version 5.1.2600] SP3 | Ubuntu Jaunty Jackalope | Windows 7 BETA

My System

Re: newbie having trouble with php and forms

Try this:

Replace
PHP Code:
if (!isset($nomes) || !isset($resps) || !isset($endes)) {
    echo(
"Preencha os campos obrigatórios! <a href=\"http://localhost/visa/inclui.php\">Voltar </a>");
    exit;

with

PHP Code:
if (!isset($nomes) {
    echo(
"Preencha os campo Nomes! <a href=\"http://localhost/visa/inclui.php\">Voltar </a>");
    exit;
}
elseif (!isset(
$resps) {
    echo(
"Preencha os campo Respons&aacute;vel! <a href=\"http://localhost/visa/inclui.php\">Voltar </a>");
    exit;

elseif (!isset(
$endes) {
    echo(
"Preencha os campo Endere&ccedil;o <a href=\"http://localhost/visa/inclui.php\">Voltar </a>");
    exit;

The elseif statement is used if there is more than one condition that needs to be checked. In this case, !isset(nomes), !isset(resps), and !isset(endes) all need to be FALSE in order for the program to continue nomally. The elseif statement works just like the if statement, checking the conditions for truth. If any of the statments are TRUE, then the message "Preencha o campo <field>!" is returned. Please note I am guessing at the Portuguese grammar with some help with an on-line translator.
__________________


Validate your Markup Validate your CSS Notepad++
Please use [html], [php], and [code] when posting code or markup.
I do not help by Private Message or e-mail. If for some reason I have over-looked a reply to a thread that I have previously replied to, then send me a message.
dm01 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 06:26 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85