Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Validating Input Data

Posted on 2003-11-07
11
Medium Priority
?
398 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 750 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

688 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