Solved

Validating Input Data

Posted on 2003-11-07
11
376 Views
Last Modified: 2010-04-06
Hi

Can someone tell me how can i Validate data input in php?? i have done this in html

<FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
        <!--webbot bot="Validation" s-display-name="Razón Social" s-data-type="Integer" s-number-separators="x" b-value-required="TRUE" i-minimum-length="1" i-maximum-length="3" s-validation-constraint="Greater than or equal to" s-validation-value="1" --><INPUT name="C1" id="username8" size="3" maxlength="3" value="1"></TD>
        <TD width="757" align="left">
        <FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
        <FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
        <INPUT name="DESCRIPCION1" id="password0" size="60" maxlength="60"></TD>
        <TD width="284" align="left">

but if i save page with extension .php it does not work

thanks
0
Comment
Question by:Alejandro_Lopez
  • 4
  • 3
  • 2
  • +1
11 Comments
 

Expert Comment

by:temporo
Comment Utility
to address the last statment if you save a page with a .php extension it does not work.

well does the host of the webpage have php as a service?

if not then .php will not work and u may have to use a diff language or move to a diff host.

-- temporo
0
 

Author Comment

by:Alejandro_Lopez
Comment Utility
yes i do have a php intalled on server, in fact i have to save the code in php because there are lot of statements in php
0
 

Expert Comment

by:temporo
Comment Utility
ok

what do you mean by it does not work then, cause if i help to validate the input and you can't see the output, it is not going to help. So you have to get php to work first.
0
 

Expert Comment

by:temporo
Comment Utility
to easily test to see if php is working on the server or any server use this code.

<?php

phpinfo();

?>

will show you all about the version and what modules are installed.

Ps. some servers with php may disable this function as it could be security risk, that others know what is installed.

you can always use hello world
eg

<?Php

echo "Hello World!";

?>

and see if it prints out   Hello World!
0
 
LVL 6

Expert Comment

by:aolXFT
Comment Utility
That doesn't  look like PHP.

The only non-html thing I can see there is:
<!--webbot bot="Validation" s-display-name="Razón Social" s-data-type="Integer" s-number-separators="x" b-value-required="TRUE" i-minimum-length="1" i-maximum-length="3" s-validation-constraint="Greater than or equal to" s-validation-value="1" -->

Are you sure that is not, something else, like FrontPage extension, or SSI? I don't really know much about Frontpage Extensions, but that looks like one. It certainly isn't PHP.

Validation is a varied topic.
I could take you through various functions in PHP like htmlentities, mysql_escape_string, addslashes, or perhaps even preg* regular expression functions, but I don't think that is what you want.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Alejandro_Lopez
Comment Utility
Sorry maybe i haven't been clear..

My server is working just fine, there are applications in php &mysql running, the output have no problem.

Yes it is maybe a Frontpage Extension, because i used it to edit the page.

My question is about doing the same thing (validate input) but using php code (or javascript) because when i save the code <!--webbot bot=.........> with php extension it does not work.
0
 
LVL 6

Expert Comment

by:aolXFT
Comment Utility
That piece of html is a good example of why you shouldn't use frontpage.

What exactly do you want to validate?

You don't have any forms on that page, and from what I can see, besides from looking at the Frontpage thing(and I don't understand Frontpage Extensions), there isn't anything dynamic.

Could you give us an example of valid, and invalid input?
0
 

Author Comment

by:Alejandro_Lopez
Comment Utility
I Know....  well i didn't put all code here but here it is:

<FORM ACTION="factura_add.php" METHOD="post" name="Forma_Factura" onsubmit="return Forma_Factura_Validator(this)" language="JavaScript">
  <FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">

    <FONT SIZE="3">

    <TABLE WIDTH="766" BORDER="0" ALIGN="left" CELLPADDING="4" CELLSPACING="0">
      <TR>
        <FONT SIZE="2">
        <TD WIDTH="321" align="left">
        <b>
        <font color="#FFFFFF" face="Bookman Old Style">Cant</font></b></TD>
      <FONT SIZE="2">
        <TD WIDTH="757" align="left">
        <b>
        <font color="#FFFFFF" face="Bookman Old Style">Descripción</font></b></TD>
        <TD WIDTH="284" align="left">
<FONT SIZE="2">
        <b>
        <font color="#FFFFFF" face="Bookman Old Style">Precio Unitario</font></b></TD>
        <TD WIDTH="252" align="left">
        <b>
        <font color="#FFFFFF" face="Bookman Old Style">Total</font></b></TD>
      </TR>
        <FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
<FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
<FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
<FONT SIZE="3">
      <TR>
        <FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
        <TD width="321" align="left">
<FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
        <!--webbot bot="Validation" s-display-name="Razón Social" s-data-type="Integer" s-number-separators="x" b-value-required="TRUE" i-minimum-length="1" i-maximum-length="3" s-validation-constraint="Greater than or equal to" s-validation-value="1" --><INPUT name="C1" id="username8" size="3" maxlength="3" value="1"></TD>
        <TD width="757" align="left">
        <FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
        <FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
        <INPUT name="DESCRIPCION1" id="password0" size="60" maxlength="60"></TD>
        <TD width="284" align="left">
<FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
        <!--webbot bot="Validation" s-display-name="Precio Unitario" s-data-type="Number" s-number-separators="x." b-value-required="TRUE" i-minimum-length="1" i-maximum-length="10" s-validation-constraint="Greater than or equal to" s-validation-value="1" --><INPUT name="P1" id="username18" size="10" maxlength="10" value="0"></TD>
        <TD width="252" align="left">
        <FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
        <!--webbot bot="Validation" s-display-name="Precio Unitario" s-data-type="Number" s-number-separators="x." b-value-required="TRUE" i-minimum-length="1" i-maximum-length="10" s-validation-constraint="Greater than or equal to" s-validation-value="1" --><INPUT name="T1" id="username28" size="10" maxlength="10" value="0"></TD>
      </TR>
<FONT FACE="PrimaSans BT, Verdana, sans-serif" SIZE="3">
        <INPUT TYPE="submit" name="Generar " VALUE="Generar Factura" size="20"></TD>
        <TD width="284" align="left">&nbsp;</TD>
        <TD width="252" align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </TD>
      </TR>
    </TABLE>
    </FORM>

The important thing is to avoid empty values or negative ones or in some cases greater than 1 etc..etc..

thanks
0
 
LVL 12

Expert Comment

by:Dean OBrien
Comment Utility
You need a javascript function declared in the head section of your HTML document.  Then change the submit button to

<input type='button' value='Submit' onclick='check()'>

function check()
{
  if (form1.C1.value == "")
  {
     alert("Please enter c1");
  }
  else
  {
    if (form1.P1.value == "")
     {
       alert("Please enter P1");
     }
     else
     {
       if (form1.T1.value == "")
       {
         alert("Please enter T1");
       }
       else
       {
         Forma_Factura.submit()
         alert("Database updated!");
       }
     }
  }
}

Hope this helps.

Easynow
0
 
LVL 12

Accepted Solution

by:
Dean OBrien earned 250 total points
Comment Utility
This is the function, changed for your page! (changed form name and values etc.)

function check()
{
  alert();
  if (Forma_Factura.C1.value == "1")
  {
     alert("Please enter c1");
  }
  else
  {
    if (Forma_Factura.P1.value == "0")
     {
       alert("Please enter P1");
     }
     else
     {
       if (Forma_Factura.T1.value == "0")
       {
         alert("Please enter T1");
       }
       else
       {
         Forma_Factura.submit()
         alert("Database updated!");
       }
     }
  }
}

Easynow
0
 

Author Comment

by:Alejandro_Lopez
Comment Utility
thanks it's what i was looking for

regards
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now