| | |
Error getting forms to send information
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
heres the code to send the info
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.
PHP Syntax (Toggle Plain Text)
<html> <HEAD> <title> form Handling with PHP </title> </head> <body bgcolor="#FFFFFF"> <center> <form method=post action="submittedinfo.php"> <input type="hidden" name="id" value="NULL"> <table> <tr> <td colspan="2"><font SIZE="+0" face="verdana"> Lets see if we cant get this form to work! </td> </tr> <tr> <td> </td> </tr> <tr> <td align="left"><font SIZE="+0" face="verdana"> <b>Your name <br \>Your E-Mail Address</b> </td> <td> <input type="text" name="name" id="name"> <br /> <input type="text" name="email" id="email"> </td> </tr> <tr> <td colspan="2"><center> <SELECT name="opinion" id="opinion"> <option value="is great">I like your site</option> <option value="is OK">Your Site is OK</option> <option value="is horrible">Your Site is horrible</option> </SELECT><p><input type="submit" value="Tell us!"> </td> </tr> </table> </form> </body> </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!
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.
•
•
Join Date: Jun 2004
Posts: 6
Reputation:
Solved Threads: 0
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...
Now make a functions file to house the functions you use on many different pages...
functions.inc.php
Now finally
ForumHandle.php
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...
PHP Syntax (Toggle Plain Text)
<?PHP // No direct call... if(ereg('db.cnnt.php', $_SERVER['SCRIPT_NAME'])) { die("Access Denied! No Direct Call!"); } // Set DB login vars... $SQL_Host = 'localhost:3306'; $SQL_Usr = 'Your_Username'; $SQL_Pss = 'Your_Password'; $SQL_DB = 'Database_Name'; // Now connect to the database server... if(!$SQL_LNK = @mysql_pconnect($SQL_Host, $SQL_Usr, $SQL_Pss)) { die("Couldn't Connect to Database Server..."); } // Now select the database... if(!$SQL_SLT = @mysql_select_db($SQL_DB)) { die("Couldn't Connect to database"); } // Or if you use multiple databases/users you can just set the different login Vars here and call connect function in the script. ?>
Now make a functions file to house the functions you use on many different pages...
functions.inc.php
PHP Syntax (Toggle Plain Text)
<?PHP //functions function ControlContent($string) { //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 $string = strip_tags(trim(stripslashes(urldecode($string)))); return $string; } //End of function function NoGET($METHOD) { if(eregi('get', $METHOD)) { die("Access denied! Post method only"); } } //Of course there are many more functions you could make but I'll stop there. ?>
Now finally
ForumHandle.php
PHP Syntax (Toggle Plain Text)
<?PHP require_once("db.cnnt.php"); require("functions.inc.php"); NoGET($_SERVER['REQUEST_METHOD']); // takes takes all vars out of the $_POST array. Now $_POST[email] becomes $email extract($_POST); // This function to clean the input string... ControlContent($email); // Now that the strings are clean you can insert them into your database. // After inserting the data close Mysql connection and exit script. mysql_close(); exit(); ?>
•
•
•
•
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
Check out my blog at http://www.shinylight.com for more stuff about web dev.
![]() |
Similar Threads
- windows live 2009 error message 'send error' (Viruses, Spyware and other Nasties)
- ASP Form error (ASP)
- Unreliable startup, black screen, shutdown problems (Troubleshooting Dead Machines)
- cannot find server + dns error, IE (Web Browsers)
- 2 forms on a website interfering with each other (HTML and CSS)
Other Threads in the PHP Forum
- Previous Thread: Fun with Forms
- Next Thread: New to PHP
| Thread Tools | Search this Thread |
301 access apache api array autocomplete beginner binary broken button cakephp checkbox class cms code compression cron curl data database dataentry date display dropdown dropdownlist duplicates dynamic echo email error execution file files folder form forms function functions google href htaccess html htmlspecialchars httppost image include insert integration ip javascript joomla jquery limit link links login mail md5 menu methods mlm multiple mysql oop paypal pdf pdfdownload php phpvotingscript query radio random recursion remote script search secure server session sessions source space sql subscription syntax system table tutorial tutorials update upload url validator variable video virus volume votedown web youtube






