• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

submitting a form

I looking for a PHP script that allows me to enter information into a form, and add it to a the PHP page I choose.

Example:

I have a page called (viewsignups.php)

A user types in his/her *name*(Carl Jones), *email*(carl44@anything.com), and *referral id*(carl25) and click (submit)

The user information will be added to the (viewsignups.php) page

PREVIEW OF HOW (viewsignups.php) page WILL LOOK NOW when you visit it

---------------------------(viewsignups.php)-----------------------

        Name:                 Email:                           Referral ID:
     Carl Jones        carl44@anything.com               carl25

---------------------------(end of viewsignups.php)----------------

Another user types in his/her *name*(Kelly Sims), *email*(kell05@something.com), and *referral id*(kel55) and click (submit)

The user information will be added to the (viewsignups.php) page

PREVIEW OF HOW (viewsignups.php) page WILL LOOK NOW when you visit it

---------------------------(viewsignups.php)-----------------------

        Name:                 Email:                           Referral ID:
     Carl Jones        carl44@anything.com               carl25
    Kelly Sims        kell05@something.com             kel55

---------------------------(end of viewsignups.php)----------------

The form is what is really important, it submits all the information and tells which page the information should be added to.....example, the page you want the information to be submitted to will be optional, if I want the information on the same list as (viewsignups.php) or on a new page (viewsignups2.php)

Please help me!!!!
0
melvinbrad20
Asked:
melvinbrad20
  • 8
  • 7
1 Solution
 
kamermansCommented:
The correct way to do this is to put the data in a database and then pull it back out and display it on viewsignups.php.  If you have access to a MySQL database this would be very easy.  Alternatively you could put the data in a plain .txt file or something.  Which would you rather do?
0
 
melvinbrad20Author Commented:
yes, I have access to MySQL
0
 
kamermansCommented:
Just POST the form to viewsignups.php - this should get you started - let me know if you need help making the tables in MySQL

viewsignups.php
-----------------------------------------------------------
<?php
$user = "someuser";
$pass = "somepass";
$host = "mysql-server.com";
$database = "databaseName";
$link = mysql_connect($host,$user,$pass) or die("Could not connect to DB: ".mysql_error());
mysql_select_db($database) or die("Could not select database: ".mysql_error());
$name = $_POST['name'];
$email = $_POST['email'];
$refID = $_POST['refID'];

if(isset($_POST['submit']){
     $query = mysql_query("INSERT INTO users (name, email, refID) VALUES ($name, $email, $refID)") or die("Could not add user ($name): ".mysql_error());
}
echo "<table><tr><th>Name</th><th>Email</th><th>RefID</th></tr>";
$users_res = mysql_query("SELECT name, email, refID FROM users");
while($row = mysql_fetch_assoc($users_res)){
    echo "<tr><td>{$row['name']}</td><td>{$row['email']}</td><td>{$row['refID']}</td></tr>";
}
echo "</table>";

?>

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
melvinbrad20Author Commented:
When I test, it says.....

Parse error: parse error, unexpected '{' in /home/test/public_html/viewsignups.php on line 12
0
 
kamermansCommented:
change this:

if(isset($_POST['submit']){

to this:

if(isset($_POST['submit'])){
0
 
melvinbrad20Author Commented:
when I tried to add the user test.....it said...........

Could not add user (test): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@test.com, testid)' at line 1
0
 
kamermansCommented:
Sorry, I haven't tested the code = you just need some single quotes around the variables:

 $query = mysql_query("INSERT INTO users (name, email, refID) VALUES ('$name', '$email', '$refID')") or die("Could not add user ($name): ".mysql_error());
0
 
melvinbrad20Author Commented:
Now it says this below when I try again....

Could not add user (test): Table 'melvinb_signups.users' doesn't exist

I didn't name my table with the (.users) at the end
0
 
kamermansCommented:
This is saying that the Database "melvinb_signups" does not have a table named "users" in it. Does it?
0
 
melvinbrad20Author Commented:
I think? so should I create one? if so....how?
0
 
kamermansCommented:
You need to go into a mysql client (phpMyAdmin, mysql command, Navicat, MySQL Query Browser, etc...) and run this command in the melvinb_signups database:

CREATE TABLE `users` (
  `userID` int(5) NOT NULL auto_increment,
  `name` varchar(50) NOT NULL,
  `email` varchar(100) NOT NULL,
  `refID` varchar(20) NOT NULL,
  PRIMARY KEY  (`userID`)
)
0
 
melvinbrad20Author Commented:
WORKS PERFERCTLY!!!! TRUE LIFE SAVER!!!
0
 
kamermansCommented:
Good deal - glad it worked out for you!
0
 
kamermansCommented:
Please beware that the way I designed the table will not let you insert a record if it does not have all the parts to it (name, email, refid) but it WILL let you put in 2 indentical records because the userID is automatically generated.
0
 
melvinbrad20Author Commented:
okay, that you for the notice
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now