Page 1 of 1

Inserting info from FORM into database.

Posted: Tue Jun 10, 2003 7:41 pm
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!

Posted: Tue Jun 10, 2003 9:02 pm
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 ;)