Connecting Tech Pros Worldwide Help | Site Map

Error msg cannot showed in php & txt box matching not work

mmarif4u's Avatar
Newbie
 
Join Date: Sep 2006
Location: Malaysia
Posts: 23
#1: Dec 20 '06
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.dtd">
<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="JavaScript"><!--
function validateForm()
{
var okSoFar=true
with (document.admin)
{

if (icnumber.value=="" && okSoFar)
{
okSoFar=false
alert("Please enter IC Number.")
icnumber.focus()
}
if (cicnumber.value=="" && 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="orangered" 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="orangered" 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="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>



<tr>
<td align="right" colspan="2">
<hr noshade="noshade" />
<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($sql);
if (!$result) {
error('A database error occurred in processing your '.
'submission.\\nIf 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,9999999990);


$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.\\nIf 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.dtd">
<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","root","adil");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("db", $con);

$result = mysql_query("SELECT icnumber,accesscode,actdate FROM m_user where
icnumber = '$_POST[icnumber]'
");

echo "<table align=Center CELLSPACING='0'BORDERCOLOR='#007FFF' BGCOLOR='cornsilk' 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($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['icnumber'] . "</td>";
echo "<td>" . $row['accesscode'] . "</td>";
echo "<td>" . $row['actdate'] . "</td>";

echo "</tr>";
}
echo "</table>";mysql_close($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="JavaScript">
<!--
alert("<? =$msg ?> ");
history.back();
-->
</script>
</head>

</html>
<?php
exit;
}
?>
[/PHP]

Plz some body help me on this,
Thanks.
Newbie
 
Join Date: Dec 2006
Posts: 4
#2: Dec 20 '06

re: Error msg cannot showed in php & txt box matching not work


For your first question,

u did that thru JavaScript, then y u r expecting the same in PHP. That u don't need.

For your third question,
y u have created a PHP function, instead of Java Script function to display a alert message.

in the common.php file just remove the <html>,<body> tags and just keep the <script tag>. That also should be inside a ECHO statment.

then only that code will printed as a PHP code when u r including the file.
mmarif4u's Avatar
Newbie
 
Join Date: Sep 2006
Location: Malaysia
Posts: 23
#3: Dec 20 '06

re: Error msg cannot showed in php & txt box matching not work


Thanks for ur reply subbukumararaja
I want to remove javascript for Q 1 that only php check the validation But
How .....,When i input some value without confirm it, the data stored in
the database.

Other i remove the tags but how to echo the msg plz can explain it
with common.php code.where to put ECHO statement.
mmarif4u's Avatar
Newbie
 
Join Date: Sep 2006
Location: Malaysia
Posts: 23
#4: Dec 20 '06

re: Error msg cannot showed in php & txt box matching not work


Yes I got it subbukumararaja,
Thanks for ur help Error msg now ok.
But others still have....

If u dont mind can i ask another question Can i insert Date with
coming 1 month to mysql, have u any idea on this.

I am working on it may be i will do it.

but if u have idea plz share it with me.

Thankss...
mmarif4u's Avatar
Newbie
 
Join Date: Sep 2006
Location: Malaysia
Posts: 23
#5: Dec 20 '06

re: Error msg cannot showed in php & txt box matching not work


Hey man i solve the other problem now php code checks the
two fields for confirmation.
Only one problem remain where to put the print button code.
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#6: Dec 20 '06

re: Error msg cannot showed in php & txt box matching not work


You can print from within your PHP script. Just place the following statement on your page.
[php]
echo '<a href="javascript:window.print();">Print this page</a>';
[/php]
If you want to use a button, use an image instead of text.

Ronald :cool:
mmarif4u's Avatar
Newbie
 
Join Date: Sep 2006
Location: Malaysia
Posts: 23
#7: Dec 23 '06

re: Error msg cannot showed in php & txt box matching not work


Thanks ronverdonk its working.

Now every thing is clear.
Reply