Inserting info from FORM into database.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
immortalsix
Forum Newbie
Posts: 2
Joined: Tue Jun 10, 2003 11:01 am

Inserting info from FORM into database.

Post by immortalsix »

Does anyone have any tutorials or code I can look at?

I am trying to create a file that will insert information from a web app into my database.

http://www.immortalsix.com/add_alumni.php is my basic schema of what I am trying to accomplish.

Then it will output into http://www.immortalsix.com/alumni_2.php

Thanks!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Let's say you have/want two fields, email and name, your form will look something like

Code: Select all

<form method="POST" action="another.script.php">
	<input type="text" name="name" /><br/>
	<input type="text" name="email" /><br/>
	<input type="submit" />
</form>
another.script.php will receive the two (named) parameters if they have been submitted, in recent versions of php they will be stored in $_POST['name'] and $_POST['email'] as strings.
A basic insert script might look like

Code: Select all

<?php
/** <- checking values -> **/
/** <- checking values -> **/
$name = mysql_escape_string($_POST['name']);
$email = mysql_escape_string($_POST['email']);
$query = "INSERT INTO myTable (name, email) VALUES('$name', '$email')";
$mysql_query($query, $TheMysqlConnectionId);
?>
For more specific answer ask more specific questions ;)
Post Reply