Jump to content

How to make a submission form into Database?


anon

Recommended Posts

So whole INSERT script would look like:

<?
if(isset($_POST['name'])){
$name = $_POST['name'];
$url = $_POST['url'];
$description = $_POST['description'];

$query = "INSERT INTO `db_table` (`id`,`name`) VALUES ('','$name')";
$run = mysql_query($query);
}
?>

What do i add at the "INSERT INTO 'db_table' ....... part. It only lists the name variable

The whole insert statement would look like this:

 

<?
if(isset($_POST['name'])){
$name = $_POST['name'];
$url = $_POST['url'];
$description = $_POST['description'];

$query = "INSERT INTO `db_table` (`id`,`name`,`url`,`description`) VALUES ('','$name','$url','$description')";
$run = mysql_query($query);
}
?>

For best practice you'd usually put that information into a file and include it.  The code itself would need to be above the insert query.  Here's how to connect:

 

define("DB_USER","username");
define("DB_PASS","password");
define("DB_DATABASE","database");

mysql_connect('localhost',DB_USER,DB_PASS);
@mysql_select_db(DB_DATABASE) or die("Unable to select database!");
mysql_query("SET NAMES 'utf8'");

Here it is:

 

define("DB_USER","*****");
define("DB_PASS","****");
define("DB_DATABASE","direx");

mysql_connect('localhost',DB_USER,DB_PASS);
@mysql_select_db(DB_DATABASE) or die("Unable to select database!");
mysql_query("SET NAMES 'utf8'");


if(isset($_POST['name'])){
$name = $_POST['name'];
$url = $_POST['url'];
$description = $_POST['description'];

$query = "INSERT INTO `addtable` (`id`,`Name`,`URL`,`Description`) VALUES ('','$name','$url','$description')";
$run = mysql_query($query);
}
?>

I did substitute the user and password; just keeping private  ;)

There's html syntax in the code that must have been placed when you copied it.

 

It must look identical to this:

 

define("DB_USER","*****");
define("DB_PASS","****");
define("DB_DATABASE","direx");

mysql_connect('localhost',DB_USER,DB_PASS);
@mysql_select_db(DB_DATABASE) or die("Unable to select database!");
mysql_query("SET NAMES 'utf8'");


if(isset($_POST['name'])){
$name = $_POST['name'];
$url = $_POST['url'];
$description = $_POST['description'];

$query = "INSERT INTO `addtable` (`id`,`Name`,`URL`,`Description`) VALUES ('','$name','$url','$description')";
$run = mysql_query($query);
}
?>

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.