Hi everyone.
i make a page that a user input thier icnumber with confirm ic number,
it saves the data to mysql db with current date and a random access code
generated automatically, NOW i have some problems facing..
1: How to match both txt box vlaues that r same or not.Is there php code for it.
2: I want to put a print button in the code where the code display the page after
entring the icnumber and after submit.
3: How to show the error msg if the user do some wrong i put javascript code
with common.php but only display this: <? =$msg ?> in popup window.
My coding is :
[PHP]<?php
include("db.php ");
include("common .php");
if (!isset($_POST['submitok'])):
// Display the user signup form
?>
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
(I PUT THIS CODE IN HEAD FOR MATCH THE TXT BOX BUT CANT WORKS
BCOZ IT DISPLAY MAG BUT THE DATA STORED TO THE DB.)
<script language="JavaS cript"><!--
function validateForm()
{
var okSoFar=true
with (document.admin )
{
if (icnumber.value =="" && okSoFar)
{
okSoFar=false
alert("Please enter IC Number.")
icnumber.focus( )
}
if (cicnumber.valu e=="" && okSoFar)
{
okSoFar=false
alert("Please confirm IC Number.")
cicnumber.focus ()
}
var e1 = icnumber.value
var e2 = cicnumber.value
if (!(e1==e2) && okSoFar)
{
okSoFar = false
alert ("IC Numbers does not match. Please re-enter.")
icnumber.focus( )
}
if (okSoFar==true) submitok();
}
}
// --></script>
<title> Access Code Generator Form </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1
</head>
<body>
<h3> Access Code Generator Form </h3>
<p><font color="orangere d" size="+1"><tt>< b>*</b></tt></font>
<u>indicates a required field</u></p>
<form name="admin" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align="center" border="0" cellpadding="0" cellspacing="5" >
<tr>
<td align="right">
<p>IC Number :</p>
</td>
<td>
<input name="icnumber" type="text" maxlength="100" size="25" />
<font color="orangere d" size="+1"><tt>< b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<p>Confirm IC Number :</p>
</td>
<td>
<input name="cicnumber " type="text" maxlength="100" size="25" />
<font color="orangere d" size="+1"><tt>< b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<hr noshade="noshad e" />
<input type="reset" value="Reset Form" />
<input type="submit" name="submitok" value="Generate Code" />
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
else:
// Process submission
dbConnect('db') ;
// Check for existing user with the ic number
$sql = "SELECT COUNT(*) FROM m_user WHERE icnumber = '$_POST[icnumber]'";
$result = mysql_query($sq l);
if (!$result) {
error('A database error occurred in processing your '.
'submission.\\n If this error persists, please '.
'contact you@example.com .');
}
if (mysql_result($ result,0,0)>0) {
error('A user already exists with your chosen userid.\\n'.
'Please try another.');
}
$random = rand(1000000,99 99999990);
$sql = "INSERT INTO m_user SET
icnumber = '$_POST[icnumber]',
accesscode = ('$random'),
Actdate = now();
";
if (!mysql_query($ sql))
error('A database error occurred in processing your '.
'submission.\\n If this error persists, please '.
'contact admin@straight-a.com.my .\\n' . mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Code Generation Complete </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body><center >
<?php
$con = mysql_connect(" localhost","roo t","adil");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db ("db", $con);
$result = mysql_query("SE LECT icnumber,access code,actdate FROM m_user where
icnumber = '$_POST[icnumber]'
");
echo "<table align=Center CELLSPACING='0' BORDERCOLOR='#0 07FFF' BGCOLOR='cornsi lk' border='1'>
<tr><th colspan=12>User Activation details</th>
<tr>
<th>IC Number</th>
<th>Access Code</th>
<th>Current Date</th>
</tr></tr>";while($ro w = mysql_fetch_arr ay($result))
{
echo "<tr>";
echo "<td>" . $row['icnumber'] . "</td>";
echo "<td>" . $row['accesscode'] . "</td>";
echo "<td>" . $row['actdate'] . "</td>";
echo "</tr>";
}
echo "</table>";mysql_c lose($con);
(HERE I WANT PUT PRINT BUTTON CODE, CODE IS IN JAVASCRIPT.)
?></strong></a>
</p>
</body>
</html>
<?php
endif;
?>
[/PHP]
Here is my common.php code:
[PHP]<?php // common.php
function error($msg) {
?>
<html>
<head>
<script language="JavaS cript">
<!--
alert("<? =$msg ?> ");
history.back();
-->
</script>
</head>
</html>
<?php
exit;
}
?>
[/PHP]
Plz some body help me on this,
Thanks.
i make a page that a user input thier icnumber with confirm ic number,
it saves the data to mysql db with current date and a random access code
generated automatically, NOW i have some problems facing..
1: How to match both txt box vlaues that r same or not.Is there php code for it.
2: I want to put a print button in the code where the code display the page after
entring the icnumber and after submit.
3: How to show the error msg if the user do some wrong i put javascript code
with common.php but only display this: <? =$msg ?> in popup window.
My coding is :
[PHP]<?php
include("db.php ");
include("common .php");
if (!isset($_POST['submitok'])):
// Display the user signup form
?>
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
(I PUT THIS CODE IN HEAD FOR MATCH THE TXT BOX BUT CANT WORKS
BCOZ IT DISPLAY MAG BUT THE DATA STORED TO THE DB.)
<script language="JavaS cript"><!--
function validateForm()
{
var okSoFar=true
with (document.admin )
{
if (icnumber.value =="" && okSoFar)
{
okSoFar=false
alert("Please enter IC Number.")
icnumber.focus( )
}
if (cicnumber.valu e=="" && okSoFar)
{
okSoFar=false
alert("Please confirm IC Number.")
cicnumber.focus ()
}
var e1 = icnumber.value
var e2 = cicnumber.value
if (!(e1==e2) && okSoFar)
{
okSoFar = false
alert ("IC Numbers does not match. Please re-enter.")
icnumber.focus( )
}
if (okSoFar==true) submitok();
}
}
// --></script>
<title> Access Code Generator Form </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1
</head>
<body>
<h3> Access Code Generator Form </h3>
<p><font color="orangere d" size="+1"><tt>< b>*</b></tt></font>
<u>indicates a required field</u></p>
<form name="admin" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align="center" border="0" cellpadding="0" cellspacing="5" >
<tr>
<td align="right">
<p>IC Number :</p>
</td>
<td>
<input name="icnumber" type="text" maxlength="100" size="25" />
<font color="orangere d" size="+1"><tt>< b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<p>Confirm IC Number :</p>
</td>
<td>
<input name="cicnumber " type="text" maxlength="100" size="25" />
<font color="orangere d" size="+1"><tt>< b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<hr noshade="noshad e" />
<input type="reset" value="Reset Form" />
<input type="submit" name="submitok" value="Generate Code" />
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
else:
// Process submission
dbConnect('db') ;
// Check for existing user with the ic number
$sql = "SELECT COUNT(*) FROM m_user WHERE icnumber = '$_POST[icnumber]'";
$result = mysql_query($sq l);
if (!$result) {
error('A database error occurred in processing your '.
'submission.\\n If this error persists, please '.
'contact you@example.com .');
}
if (mysql_result($ result,0,0)>0) {
error('A user already exists with your chosen userid.\\n'.
'Please try another.');
}
$random = rand(1000000,99 99999990);
$sql = "INSERT INTO m_user SET
icnumber = '$_POST[icnumber]',
accesscode = ('$random'),
Actdate = now();
";
if (!mysql_query($ sql))
error('A database error occurred in processing your '.
'submission.\\n If this error persists, please '.
'contact admin@straight-a.com.my .\\n' . mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Code Generation Complete </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body><center >
<?php
$con = mysql_connect(" localhost","roo t","adil");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db ("db", $con);
$result = mysql_query("SE LECT icnumber,access code,actdate FROM m_user where
icnumber = '$_POST[icnumber]'
");
echo "<table align=Center CELLSPACING='0' BORDERCOLOR='#0 07FFF' BGCOLOR='cornsi lk' border='1'>
<tr><th colspan=12>User Activation details</th>
<tr>
<th>IC Number</th>
<th>Access Code</th>
<th>Current Date</th>
</tr></tr>";while($ro w = mysql_fetch_arr ay($result))
{
echo "<tr>";
echo "<td>" . $row['icnumber'] . "</td>";
echo "<td>" . $row['accesscode'] . "</td>";
echo "<td>" . $row['actdate'] . "</td>";
echo "</tr>";
}
echo "</table>";mysql_c lose($con);
(HERE I WANT PUT PRINT BUTTON CODE, CODE IS IN JAVASCRIPT.)
?></strong></a>
</p>
</body>
</html>
<?php
endif;
?>
[/PHP]
Here is my common.php code:
[PHP]<?php // common.php
function error($msg) {
?>
<html>
<head>
<script language="JavaS cript">
<!--
alert("<? =$msg ?> ");
history.back();
-->
</script>
</head>
</html>
<?php
exit;
}
?>
[/PHP]
Plz some body help me on this,
Thanks.
Comment