Error getting forms to send information

Reply

Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Error getting forms to send information

 
0
  #1
Jun 13th, 2004
heres the code to send the info

  1. <html>
  2. <HEAD>
  3. <title> form Handling with PHP </title>
  4. </head>
  5. <body bgcolor="#FFFFFF">
  6. <center>
  7. <form method=post action="submittedinfo.php">
  8. <input type="hidden" name="id" value="NULL">
  9. <table>
  10. <tr>
  11. <td colspan="2"><font SIZE="+0" face="verdana">
  12. Lets see if we cant get this form to work!
  13. </td>
  14. </tr>
  15. <tr>
  16. <td>
  17. </td>
  18. </tr>
  19. <tr>
  20. <td align="left"><font SIZE="+0" face="verdana">
  21. <b>Your name <br \>Your E-Mail Address</b>
  22. </td>
  23. <td>
  24. <input type="text" name="name" id="name">
  25. <br />
  26. <input type="text" name="email" id="email">
  27. </td>
  28. </tr>
  29. <tr>
  30. <td colspan="2"><center>
  31. <SELECT name="opinion" id="opinion">
  32. <option value="is great">I like your site</option>
  33. <option value="is OK">Your Site is OK</option>
  34. <option value="is horrible">Your Site is horrible</option>
  35. </SELECT><p><input type="submit" value="Tell us!">
  36. </td>
  37. </tr>
  38. </table>
  39. </form>
  40. </body>
  41. </html>

and here is the code to show the information entered by the user

[php]<?
$DBhost = "localhost";
$DBuser = "michael";
$DBpass = "koolaide";
$DBName = "phpforms";
$table = "information";


mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
$sqlquery = "INSERT INTO $table VALUES('$id','$name','$email','$opinion')";
$results = mysql_query($sqlquery);
mysql_close();
echo "
<html>
<head>
<title> PHP and MySQL </title>
</head>
<body>
<center>
<table border='0' width='500'>
<tr>";
echo " <td>
<font face='verdana' size='+0'>
<center>
<p>You Just Entered This Information Into the Database</p>
</center>";

echo " <blockquote>
<center>
<p>
Name :<p> $name E-Mail :</p> $email <p>Opinion :</p> $opinion
</p>
</center>
</blockquote>
</td>
</tr>
</table>
</center>
</body>
</html>";
?>
[/php]

heres the problem, when i run the HTML on the first page and fill out the form, i press send the info, it should bring up another page saying You entered so and so information. but instead i get you entered so and so info but it doesnt list the info, adding to that, im very noob to PHP, this is another tutorial that i found, and im begining to think that alot of tutorials have errors in them or somthing. i even went into my mysql and added the database and lines of info needed (again using his tutorial on how to) any help would be greatly appreciated.


ok, so i was able to fix the form, and ill post how i did it too.

[php]$name = "$_POST[name]";
$email = "$_POST[email]";
$opinion = "$_POST[opinion]";[/php]

needed to be defined at the top of the page. now when i view my databases via phpmyadmin, i can see that the information has been added to the database, but now i need to write a script that will print out all data in the database to onscreen.
Last edited by samaru; Jun 15th, 2004 at 2:00 am.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 1,135
Reputation: samaru is just really nice samaru is just really nice samaru is just really nice samaru is just really nice 
Solved Threads: 6
Team Colleague
samaru's Avatar
samaru samaru is offline Offline
a.k.a inscissor

Re: Error getting forms to send information

 
0
  #2
Jun 13th, 2004
Glad you were able to help yourself, but remember, don't double post. If you need help with displaying the data, give us a holler.
Check out my blog at http://www.shinylight.com for more stuff about web dev.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 6
Reputation: fEcAlMaTteR is an unknown quantity at this point 
Solved Threads: 0
fEcAlMaTteR fEcAlMaTteR is offline Offline
Newbie Poster

Re: Error getting forms to send information

 
0
  #3
Jun 13th, 2004
What i like to do with form submissions...

First off, you never want to put your SQL login info directly in your script instead make a file like db.cnnt.php
Inside, write something like this...
  1. <?PHP
  2. // No direct call...
  3. if(ereg('db.cnnt.php', $_SERVER['SCRIPT_NAME']))
  4. {
  5. die("Access Denied! No Direct Call!");
  6. }
  7. // Set DB login vars...
  8. $SQL_Host = 'localhost:3306';
  9. $SQL_Usr = 'Your_Username';
  10. $SQL_Pss = 'Your_Password';
  11. $SQL_DB = 'Database_Name';
  12. // Now connect to the database server...
  13. if(!$SQL_LNK = @mysql_pconnect($SQL_Host, $SQL_Usr, $SQL_Pss))
  14. {
  15. die("Couldn't Connect to Database Server...");
  16. }
  17. // Now select the database...
  18. if(!$SQL_SLT = @mysql_select_db($SQL_DB))
  19. {
  20. die("Couldn't Connect to database");
  21. }
  22. // Or if you use multiple databases/users you can just set the different login Vars here and call connect function in the script.
  23. ?>

Now make a functions file to house the functions you use on many different pages...
functions.inc.php
  1. <?PHP
  2. //functions
  3. function ControlContent($string)
  4. {
  5. //You can set more vars to this one. for instance if you want to only strip_tags from certain inputs...You could add $HTML to the function vars. If $HTML == 0 or $HTML == NULL then strip_tags ELSE dont strip_tags. But in this example im just gonna fix the strings
  6.  
  7. $string = strip_tags(trim(stripslashes(urldecode($string))));
  8. return $string;
  9. } //End of function
  10.  
  11. function NoGET($METHOD)
  12. {
  13. if(eregi('get', $METHOD))
  14. {
  15. die("Access denied! Post method only");
  16. }
  17. }
  18.  
  19. //Of course there are many more functions you could make but I'll stop there.
  20. ?>

Now finally
ForumHandle.php
  1. <?PHP
  2. require_once("db.cnnt.php");
  3. require("functions.inc.php");
  4. NoGET($_SERVER['REQUEST_METHOD']);
  5. // takes takes all vars out of the $_POST array. Now $_POST[email] becomes $email
  6. extract($_POST);
  7. // This function to clean the input string...
  8. ControlContent($email);
  9.  
  10. // Now that the strings are clean you can insert them into your database.
  11.  
  12. // After inserting the data close Mysql connection and exit script.
  13. mysql_close();
  14. exit();
  15. ?>
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 1,135
Reputation: samaru is just really nice samaru is just really nice samaru is just really nice samaru is just really nice 
Solved Threads: 6
Team Colleague
samaru's Avatar
samaru samaru is offline Offline
a.k.a inscissor

Re: Error getting forms to send information

 
0
  #4
Jun 13th, 2004
Originally Posted by fEcAlMaTteR
What i like to do with form submissions...

First off, you never want to put your SQL login info directly in your script instead make a file like db.cnnt.php
Yeah I agree. I usually set aside a separate php file where I include global variables and settings. Here I include the passwords. However, I think Killer_Typo is doing this now because it's only an example to show how to get data from forms and do stuff with it.
Check out my blog at http://www.shinylight.com for more stuff about web dev.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC