Solved

Validating Input Data

Posted on 2003-11-07
11
384 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google adds suggestions 3 63
JQuery tracking event. 3 68
Getting dynamic value from 3rd party page and passing to a function on another page 1 108
React or Angular? 6 73
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

809 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