Solved

Validating Input Data

Posted on 2003-11-07
11
388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web Application Architecture 6 80
xml attribute DTD attribute differences 3 79
CSS Question.. 3 97
CSS (line height?) issue 2 74
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

756 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