Solved

Validating Input Data

Posted on 2003-11-07
11
386 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
ID: 9704720
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
ID: 9704743
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
ID: 9704753
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Expert Comment

by:temporo
ID: 9704814
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
ID: 9707436
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
 

Author Comment

by:Alejandro_Lopez
ID: 9709725
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
ID: 9710190
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
ID: 9715081
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
ID: 9723352
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
ID: 9723416
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
ID: 9725242
thanks it's what i was looking for

regards
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Owl Carousel 6 235
TripAdvisor Widgets on WordPress Websites 10 192
Web Development Tools for MVC 3 98
JavaScript and Regular Expressions - How to implement date validation? 7 86
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

828 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