GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Jan-2005, 13:13
petenyce405 petenyce405 is offline
New Member
 
Join Date: Jan 2005
Posts: 3
petenyce405 is on a distinguished road

Form Validation Issue


Hello
Iam new to this forum and hope i can get this awnsered. I have a form that lets users submit data online. Now i check my sql database to see if they arent submitting a duplicate username.

How can i get the error message to appear on the form? You have this done when you register for this forum. I need to connect to the database and if there is a error display it on the form??? Below is a simple form can i have an example with thsi form where an dhow would i add the php to A check the database field(userid) and B) Submit the form into the database. I think i have to use php echo self

thanks
pete

Form:

<meta http-equiv="Content-Language" content="en-us">
<form method="POST" action="--WEBBOT-SELF--">
<p>Name: <input type="text" name="T1" size="20"></p>
<p>Username: <input type="text" name="T3" size="20"></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
  #2  
Old 10-Jan-2005, 21:49
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by petenyce405
Hello
Iam new to this forum and hope i can get this awnsered. I have a form that lets users submit data online. Now i check my sql database to see if they arent submitting a duplicate username.

How can i get the error message to appear on the form? You have this done when you register for this forum. I need to connect to the database and if there is a error display it on the form??? Below is a simple form can i have an example with thsi form where an dhow would i add the php to A check the database field(userid) and B) Submit the form into the database. I think i have to use php echo self

thanks
pete

Form:

<meta http-equiv="Content-Language" content="en-us">
<form method="POST" action="--WEBBOT-SELF--">
<p>Name: <input type="text" name="T1" size="20"></p>
<p>Username: <input type="text" name="T3" size="20"></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

One way is to redisplay your form passing it an error code. Then in the PHP if error code exists you add a line above the form itself indicating what's wrong.

In essence:
Code:
$errline = ""; if ($err == 1) { $errline = "Name Error"; } else if ($err == 2) { $errline = "Address Error"; } print $errline print "<FORM ..."
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
  #3  
Old 11-Jan-2005, 06:32
petenyce405 petenyce405 is offline
New Member
 
Join Date: Jan 2005
Posts: 3
petenyce405 is on a distinguished road

almost their


Ok so now i have the code you gave me but how do i tie it in with my mysql. below you will find the sql im checking for in my database




You guys gave me this example, how do i tie in mysql with you code. Im checking for a duplicate username, if duplicate want the message to show on the form.

$errline = "";
if ($err == 1) { $errline = "Name Error"; }
else
if ($err == 2) { $errline = "Address Error"; }

print $errline
print "<FORM ..."




heres my COde:

$query1 = "SELECT * from test WHERE name = '$user'";
$result1 = mysql_query($query1) or exit(mysql_error());
if (mysql_num_rows($result1))


PS Great Forum
  #4  
Old 11-Jan-2005, 21:35
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
How do you know if there's an error? I assume you know how to test for this. So when you get one, set the error code, and reload the form with the error as part of the query string.
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP form needs validation jabesign MySQL / PHP Forum 16 05-Jan-2005 00:23
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 03:38
PHP/MySQL coding issue cmarti MySQL / PHP Forum 3 26-Jul-2004 08:01
help with form orbitel MySQL / PHP Forum 11 21-Jan-2004 15:29
Why doesnt my form work correctly? rhino1616 Web Design Forum 2 06-Nov-2003 17:21

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:29.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.