Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.