Hi to All,
I am new to php and and I have created a new php project... and in that I have established a connection to mysql db..
I am receiving 5 fields as user entry.. and stored in the db.... and in this case I want to validate the textbox and email... and all type regular expression validation in this form...
I used javascrip.. but I don't know how to use....... in proper ...? Can anyone tell me how to do this... by viewing the below code.... The below code doesn't validate.... but the javascript is running by displaying the Hello World in Uppercase
I am using Dream Weaver, Xampp as server, Mysql as db.
<?php
//Project : TEST PROJECT
//Author : NK
//Last Updated : 06/10/2008
//Company : 5G Technologies
//error
error_reporting(0);
//session
session_start();
//buffer start
ob_start();
//include WEBCONFIG file
include("includes/webconfig.php");
//Get All Posted Values
$Txt_ClientName = $_POST['Txt_ClientName'];
$Txt_ClientCompany = $_POST['Txt_ClientCompany'];
$Txt_ClientAddress = $_POST['Txt_ClientAddress'];
$Txt_ClientPhone = $_POST['Txt_ClientPhone'];
$Txt_ClientEmail = $_POST['Txt_ClientEmail'];
$Cmd_Submit = $_POST['Cmd_Submit'];
if(trim($Cmd_Submit)==trim("New"))
{
$SQLQry_InsertClient=mysql_query("INSERT INTO tbl_client(var_Name,var_Company,var_Address,int_Phone,var_Email,var_Status) VALUES('$Txt_ClientName','$Txt_ClientCompany','$Txt_ClientAddress','$Txt_ClientPhone','$Txt_ClientEmail','Yes')", $Conn);
$message = "{$Txt_ClientName} Added Successfully";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test Work </title>
<link href="style/ssheet.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {font-size: 22px}
.style2 {font-size: 27px}
-->
</style>
</head>
<body>
<script type = "text/javascript" language="javascript">
var h = "Hello World";
document.write(h.toUpperCase());
function validate(thisform)
{
if(this.document.Frm_Client.Txt_ClientName == "")
{
document.wirte("coming in validate enter name");
alert("Please Enter Name");
document.Frm_Client.Txt_ClientName.focus();
return false;
}
if(this.document.Frm_Client.Txt_ClientCompany == "")
{
alert("Please Enter Company Name");
document.Frm_Client.Txt_ClientCompany.focus();
return false;
}
if(this.doucment.Frm_Client.Txt_ClientPhone == "")
{
alert("Please Enter Phone Number");
document.Frm_Client.Txt_ClientPhone.focus();
return false;
}
if(this.document.Frm_Client.Txt_ClientEmail == "")
{
alert("Please Enter Email id");
document.Frm_Client.Txt_ClientEmail.focus();
return false;
}
}
</script>
<form name="Frm_Client" action="<?php $HTTP_SERVER_VARS['PHP_SELF'];?>" method="POST" onsubmit="return validate()">
<table width="571" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="54" colspan="3"><div align="center" class="tbltitle"><strong>Client Information System </strong></div></td>
</tr>
<tr>
<td width="48%" class="bodybg"><div align="right" class="bodybg">Client Name (required, atleast 2 char)</div></td>
<td width="3%" class="bodybg"> </td>
<td width="49%" class="bodybg"><label for="cname">
<input name="Txt_ClientName" type="text" class="txt-box" id="Txt_ClientName" />
</label></td>
</tr>
<tr>
<td height="40" class="bodybg"><div align="right" class="bodybg">Client Company </div></td>
<td class="bodybg"> </td>
<td class="bodybg"><div align="left">
<label>
<input name="Txt_ClientCompany" type="text" class="txt-box" id="Txt_ClientCompany" />
</label>
</div></td>
</tr>
<tr>
<td class="bodybg"><div align="right" class="bodybg">Client Address </div></td>
<td class="bodybg"> </td>
<td class="bodybg"><div align="left">
<label>
<textarea name="Txt_ClientAddress" class="txt-area" id="Txt_ClientAddress"></textarea>
</label>
</div></td>
</tr>
<tr>
<td class="bodybg"><div align="right" class="bodybg">Phone</div></td>
<td class="bodybg"> </td>
<td class="bodybg"><div align="left">
<label></label>
<label>
<input name="Txt_ClientPhone" type="text" class="txt-box" id="Txt_ClientPhone" />
</label>
</div></td>
</tr>
<tr>
<td class="bodybg"><div align="right" class="bodybg">Email</div></td>
<td class="bodybg"> </td>
<td class="bodybg"><div align="left">
<label>
<input name="Txt_ClientEmail" type="text" class="txt-box" id="Txt_ClientEmail" />
</label>
</div></td>
</tr>
<?php
if($message<>"")
{
?>
<tr>
<td colspan="3" align="center" valign="middle" class="bodybg"><?php echo $message; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="3" class="bodybg"><label>
<div align="center">
<input name="Cmd_Submit" type="submit" class="cmd_submit" id="Cmd_Submit" value="New" />
</div>
</label></td>
</tr>
</table>
</form>
<br />
<table width="88%" height="57" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="21%" class="bodybg"><div align="center">Name</div></th>
<th width="21%" class="bodybg"><div align="center">Company</div></th>
<th width="23%" class="bodybg"><div align="center">Address</div></th>
<th width="15%" class="bodybg"><div align="center">Phone</div></th>
<th width="20%" class="bodybg"><div align="center">Email</div></th>
</tr>
<?php $SQL_Select = mysql_query("SELECT * FROM tbl_client", $Conn);
while($Get_Value = mysql_fetch_array($SQL_Select))
{
?>
<tr>
<td align="center" valign="middle" class="bodybg"><?php echo $Get_Value['var_Name']?></td>
<td align="center" valign="middle" class="bodybg"><?php echo $Get_Value['var_Company']?></td>
<td align="center" valign="middle" class="bodybg"><?php echo $Get_Value['var_Address']?></td>
<td align="center" valign="middle" class="bodybg"><?php echo $Get_Value['int_Phone']?></td>
<td align="center" valign="middle" class="bodybg"><?php echo $Get_Value['var_Email']?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
And also I have a doubt... Is there any possibilities to fix a breakpoint and compile the code like we use in .net.
How to compile my php code.. to fix the error fast....?
And finally How to use jquery instead of using javascript coding for client side validation...... ? explain with example.... please.....
Thanks in Advance...