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

Link to comment
Share on other sites

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);
}
?>

Link to comment
Share on other sites

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'");

Link to comment
Share on other sites

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  ;)

Link to comment
Share on other sites

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);
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.