Jump to content

Insert Variables into MySQL?


hatchergraphics

Recommended Posts

Hi!

 

I'm having a problem inserting html form data into my database (using variables). How should I solve this problem?

 

The HTML form:

 

<pre>

 

<form action="mysql.php" method="post">

<input name="firstname" type="text" value="First Name"><br/>

<input name="lastname" type="text" value="Last Name"><br/>

<input name="email" type="text" value="Email"><br/>

<input name="age" type="text" value="Age"><br/>

<input type="submit">

</form>

</pre>

 

The PHP/MySQL:

 

<pre>

//MySQL Database connection

mysql_connect("localhost", "eric", "eric") or die(mysql_error());

mysql_select_db("zabboh") or die(mysql_error());

 

//Fetch HTML form data

$fname = $_POST['firstname'];

$lname = $_POST['lastname'];

$email = $_POST['email'];

$age = $_POST['age'];

 

//Insert Form Data into Database

mysql_query("INSERT INTO users

(fname, lname, email, age) VALUES('$fname', '$lname', '$email', '$age') ")

or die(mysql_error());

 

</pre>

 

Thanks in advance!!

Link to comment
https://forums.phpfreaks.com/topic/206749-insert-variables-into-mysql/
Share on other sites

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.