Jump to content

Total Newb: Need PHP Form to MySQL help


Ollie

Recommended Posts

Hi all,

 

Im totally new to this site, PHP and MySql.

 

Anyhow I have a Mysql DB up with tables constructed and modified and etc.

 

I just started with PHP today and constructed my first Form in Dreamweaver to submit data via text fields to the MySQl DB.

 

I guess what Im looking for is a code snippet I can reuse that submits the text in the form field to the corresponding DB field, in some cases some of the form field may be blank while others are populated.

 

Anyone have a URL or code suggestion? (Ive looks through the library and tutorials I didnt see much)

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/53518-total-newb-need-php-form-to-mysql-help/
Share on other sites

Here you go:

 

<?
$done=$_POST["done"];
if ($done=="yes") {
	 //This what the screen would look like after clicked "submit"
 $name=$_POST["name"];
 $email=$_POST["email"];
 $other=$_POST["other"];
 include "connect.php"; //Connect to your DB... Either via "Include File" or just the connect query code
 mysql_query("INSERT INTO users(name, email, other) VALUES('$name', '$email', '$other')") or die(mysql_error());
 echo "done!";
} else {
 ?>
 <form action="THE URL OF THIS PAGE" method="post">
 Name: <input name="name"><br>
 E-mail: <input name="email"><br>
 Other: <input name="other"><br>
 <input type="submit">	 
 </form>
 <?
}
?>

 

Just change the "name", "email" and "other" to your own needed values. you can add as much more values as you want - just copy/paste rows.

 

Note that it's recommend to use ID in the DB, which is genarated automaticly and don't needed to be added manually by the mysql query.

 

Eyal

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.