PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 15th, 2003, 10:36 AM
fearx24 fearx24 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 9 fearx24 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP SQL Form Entry??

How to put into a form so some fields are required and wont let the user enter the data into the database they will need certain fields filled in first. How do you do that with a form? Im using PHP with this form.

example I have set up a form that uses PHP to enter the data into MYSQL and if someone accidently hits enter before they are finished filling out form it submits it and saves the record, I dont want it to be able to do this.

thanks Nick

Reply With Quote
  #2  
Old April 15th, 2003, 05:15 PM
hadley hadley is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 63 hadley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
You'll need to run some validation code on the submitted data first.

eg.
PHP Code:
if (empty($form['name'])) {
  
$err[] = "Name is required";
}
...

//display all the errors

//on submit data if ok, otherwise redisplay with errors

if (count($err)>0) {
  
//redisplay
} else {
 
//submit



Hadley

Reply With Quote
  #3  
Old April 16th, 2003, 09:39 AM
fearx24 fearx24 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 9 fearx24 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP Code:
<?php include("Auth.php"); ?>
 
 <head>
 <title>CWD</title>
 </head>
 <body bgcolor="white">
</body>


 <?
 
//------Database Login-----------//
$dbuser 'root';
$dbhost 'localhost';
$dbpass 'pass';
$dbname 'db';
$dbtable 'record';

//------ DATABASE CONNECTION --------//
$conn mysql_connect($dbhost$dbuser$dbpass);

//pick the database to use
mysql_select_db($dbname,$conn);

    
$thedate date('Y-m-d'strtotime($_POST[date]));
//create the SQL statement
$sql "INSERT INTO $dbtable values ('', '$_POST[Counselor]', '$_POST[f_name]',
 '
$_POST[l_name]', '$thedate', '$_POST[Meth]', '$_POST[Sex]', '$_POST[Facility]',
 '
$_POST[SessType]', '$_POST[NoShow]', '$_POST[BAL]', '$_POST[Length]',
 '
$_POST[LOC]', '$_POST[IndSess]', '$_POST[FileLoc]', '$_POST[GroupSess]',
 '
$_POST[CD]', '$_POST[Comments]', '$_POST[InsMed]','$_POST[SlidingFee]',
  '
$_POST[AmtPaid]', '$_POST[PayAgree]', '$_POST[NonPay]')";

//execute the SQL statement
if (mysql_query($sql$conn)) {
    echo 
"<p>Record $_POST[f_name] $_POST[l_name] Added Successfully<br>";
    echo 
'<a href="new_form.php">Add Another Record</a>';

} else {
    echo 
"<p>Contact Administrator <strong>tech@tech.org</strong>, Error Saving Record";
}
?>



here is a example of the add record code. say I want to make it so if 'f_name' = Nick then it will not add the record. how do I get this to work, I cant seem to figure it out.

Reply With Quote
  #4  
Old April 16th, 2003, 08:24 PM
hadley hadley is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 63 hadley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Before you run the SQL, check if $_POST[f_name] == "nick", if it does run the sql. If it doesn't display an error.

Hadley

Reply With Quote
  #5  
Old April 22nd, 2003, 12:22 AM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via ICQ to avit
Code:
foreach ( ('f_name','l_name','Sex') as $field ) {
  if ( isempty($_POST[$field]) ) {
    $form_err[] = $field;
  }
}

if (isset($form_err)) {
  include(form.php);
  exit;
}


In your form.php, you can have:

Code:
if (isset($form_err)) {
  echo '<h3>There are errors in the form!</h3>';
  foreach ($form_err as $field) {
    echo "$field is not set.<br>";
  }
}


Or something like that... Warning: Off the top of my head, but I hope you get the idea...

Reply With Quote
  #6  
Old April 22nd, 2009, 05:33 AM
allozysob allozysob is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Location: Switzerland
Posts: 7 allozysob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 44 sec
Reputation Power: 0
Send a message via ICQ to allozysob
Hey

Como estas :P ! Ca fait un bou que j'vous li mais l je choisix de m'inscrire pour vous demander c'est quoi le site au juste du magazine de decouvertes plein-air . J'ai entendu du dire qu'il y avait plusieurs de photos faire sur ce site..! a+!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP SQL Form Entry??


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap