Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving info to a database?

Status
Not open for further replies.

BittenApple

Programmer
Jan 4, 2005
7
GB
Hi, ive got a HTML form all sorted, and you type in your name/e-mail/mobile and a comment, would this be a correct script to add it to a database?
Code:
<?
$username="username";
$password="password";
$database="your_database";

$first=$_POST['first'];
$last=$_POST['last'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];
$message=$_POST['message'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO contacts VALUES ('','$first','$last','$mobile','$email','$message')";
mysql_query($query);

mysql_close();
?>
My friend gave me that script, but hes not a php genius and neither am I - I found a tutorial similar to that but it's not very helpful. I've only been looking at php tutorials for about 3 days.. anyone care to give me a hand.
 
it looks good, but you need to read the manuals/tutorials... do you have any problem?
 
Umm...
Code:
mysql_connect([red]$database[/red],$username,$password);
or
mysql_connect([red]"[/red]localhost[red]"[/red],$username,$password);

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
BittenApple, you may want to take a look at phpbuilder.com. They have a good forum and tutorials :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top