Jump to content

Database Addition Issues


Hagbard

Recommended Posts

I have been trying to set up a table that will allow me to add info to a database. When the submit button is pressed it posts using this add.php however, when I do so all I get is "Database Not Selected" which makes no sense as its defined in the config include. Any thoughts or suggestions would be GREATLY appreciated.

 

<?php require("login_success.php"); ?>

<?php

$pgtitle = "admin";

$tbl = $_POST['tbl'];

include('../_include/config.php');

?>

<?php

//Dig Page Addition

if ( isset($_POST['submit']) && $tbl=="dig" ) {

 

$name     = $_POST['name'];

$address = $_POST['address'];

$address2         = $_POST['address2'];

$city                   = $_POST['city'];

$state = $_POST['state'];

$zip           = $_POST['zip'];

$link           = $_POST['link'];

$grows         = $_POST['grows'];

$gis_data = $_POST['gis_data'];

$ready_now       = $_POST['ready_now'];

$ready_next       = $_POST['ready_next'];

$text = $_POST['text'];

$text_short       = $_POST['text_short'];

$image = $_POST['image'];

$image1 = $_POST['image1'];

$image2 = $_POST['image2'];

$image3 = $_POST['image3'];

 

 

  mysql_connect("$host", "$user", "$password") or die(mysql_error());

  mysql_select_db("$db") or die(mysql_error());

 

  mysql_query("INSERT INTO $tbl VALUES (

'0',

'$name',

'$address',

'$address2',

'$city',

'$state',

'$zip',

'$link',

'$grows',

'$gis_data',

'$ready_now',

'$ready_next',

'$text',

'$text_short',

'$image',

'$image1',

'$image2',

'$image3'

)") or die(mysql_error());

 

mysql_close();

 

  header("location:index.php");

 

//Item Addition

} else if ( isset($_POST['submit']) && $tbl=="item" ) {

 

$text_short     = $_POST['text_short'];

$where       = $_POST['where'];

$biology       = $_POST['biology'];

$storage       = $_POST['storage'];

$recipe = $_POST['recipe'];

$more_options     = $_POST['more_options'];

$link1 = $_POST['link1'];

$link2         = $_POST['link2'];

$link3                 = $_POST['link3'];

$image       = $_POST['image'];

$item                               = $_POST['item'];

 

  mysql_connect("$host", "$user", "$password") or die(mysql_error());

  mysql_select_db("$db") or die(mysql_error());

 

  mysql_query("INSERT INTO $tbl VALUES (

  '0',

'$text_short',

'$where',

'$biology',

'$storage',

'$recipe',

'$more_options',

'$link1',

'$link2',

'$link3',

'$image',

'$item'

)") or die(mysql_error());

mysql_close();

 

  header("location:index.php");

 

//seasons addition

} else if ( isset($_POST['submit']) && $tbl=="seasons" ) {

 

$title                   = $_POST['title'];

$text           = $_POST['text'];

$text_short         = $_POST['text_short'];

$image = $_POST['image'];

$link             = $_POST['link'];

$tags           = $_POST['tags'];

$postdate = $_POST['postdate'];

 

  mysql_connect("$host", "$user", "$password") or die(mysql_error());

  mysql_select_db("$db") or die(mysql_error());

 

  mysql_query("INSERT INTO $tbl VALUES ('0', '$title', '$text', '$text_short', '$image', '$link', '$tags', '$postdate',)") or die(mysql_error());

mysql_close();

 

  header("location:index.php");

 

//What Addition

} else if ( isset($_POST['submit']) && $tbl=="what" ) {

 

$text         = $_POST['text'];

$link       = $_POST['link'];

$image     = $_POST['image'];

$tags     = $_POST['tags'];

$source     = $_POST['source'];

$subject     = $_POST['subject'];

 

  mysql_connect("$host", "$user", "$password") or die(mysql_error());

  mysql_select_db("$db") or die(mysql_error());

 

  mysql_query("INSERT INTO $tbl VALUES ('0', '$text_short', '$where', '$biology', '$storage', '$recipe', '$more_options', '$link1', '$link2', '$link3', '$image', '$item')") or die(mysql_error());

mysql_close();

 

  header("location:index.php");

  mysql_close();

}

?>

Link to comment
https://forums.phpfreaks.com/topic/104541-database-addition-issues/
Share on other sites

First use [ code ] tags to highlight your code. Is that the code of only one file? Are u sure ure using the right relative path for including config.php? Why dont u run mysql_connect() and mysql_select_db() in config.php, instead of running them in every script (or portions of it). Probably u havent heard of sql injections before, so u dont know that u should run mysql_real_escape_string() on any input string that is going to be used in a query. And by the way, your INSERT syntax isnt right, it should be:

 

INSERT INTO $tbl (column1, column2,....) VALUES ($valColumn1, $valColumn2,....)

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.