Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Problem POSTING to SQL database(quick reply)

$
0
0
Im trying to post something to my database. The only way that i can possibly do it at this point is with this code.

<?php

include_once('config.php');

mysql_connect('localhost','admin','password');
mysql_select_db('news');
?>



With this code, it will post to the SQL database;however, this is not my goal.

As you noticed, I have a config.php file.
This file holds all of my SQL login data.

<?php

$config['db_host'] = 'localhost';
$config['db_user'] = 'admin';
$config['db_pass'] = 'password';
$config['db_name'] = 'news';

foreach ( $config as $k => $v ) {
		define (strtoupper($k), $v);
}
?>


I am trying to use my config.php file within my init.php file with this code.

<?php

include_once('config.php');

mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_NAME);

?>


When i input this code I get the an error

********
Notice: Use of undefined constant DB_HOST - assumed 'DB_HOST' in C:\xampp\htdocs\resources\init.php on line 5
Notice: Use of undefined constant DB_USER - assumed 'DB_USER' in C:\xampp\htdocs\resources\init.php on line 5
Notice: Use of undefined constant DB_PASS - assumed 'DB_PASS' in C:\xampp\htdocs\resources\init.php on line 5
********

What can i do to fix this problem?
If anyone could help i would greatly appreciate it.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>