473,414 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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

mmarif4u
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.
Dec 20 '06 #1
6 1821
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.
Dec 20 '06 #2
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.
Dec 20 '06 #3
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...
Dec 20 '06 #4
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.
Dec 20 '06 #5
ronverdonk
4,258 Expert 4TB
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:
Dec 20 '06 #6
Thanks ronverdonk its working.

Now every thing is clear.
Dec 23 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: jason | last post by:
Is there a way to avoid On Error Resume Next for: cnn.Open strCon SQL = "EXEC Customer @txtEmail='" & email_address & "'" set rs = cnn.execute(SQL) 'On error resume next rs("email_address")...
5
by: S.Patten | last post by:
Hi, I have a problem with updating a datetime column, When I try to change the Column from VB I get "Incorrect syntax near '942'" returned from '942' is the unique key column value ...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
5
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This is used for comparing a value enterd by the user against the primary key in the SQL database. IF the VALUE ENTERED BY THE...
10
by: JLuis Estrada | last post by:
Hi there Its my 1st post in this group and I hope we could have a great time. well, this is my problem I was debbuging my app (a website) and the system get stuck and I had to reboot the...
9
by: i | last post by:
#include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> char ch; int n,m; void main(); char check(int,int,char); void cash(int,int,char); void debit_card(int,int,char);
9
by: 2DIL | last post by:
hello all experts, basically, i have a very small project, in which 97% of the work is complete. yet there is an issue which i cannot solve and i have no error to indicate what the problem...
17
by: mandanarchi | last post by:
Access 2003; PC with Windows XP; SBS 2003 I tried searching the forums but it came up with a blank page. I searched Google and found an answer; but the 'problem' doesn't relate to our situation!...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.