Wait what? I think I've gotten the idea of what you need. Basically you need the database, but first you need to connect to the database... So I think I've done this right if not someone can correct me.
First of all to connect to the database you're going to need two files, database.php and config.php
Database.php:
PHP Code:
<?PHP
require_once ( 'config.php' );
$MYSQL_HANDLE = mysql_connect( $config['db_host'], $config['db_user'], $config['db_pass'] );
mysql_select_db( $config['db_name'] );
?>
Now you need Config.php:
PHP Code:
<?PHP
$config = array();
$config['db_host'] = 'localhost';
$config['db_user'] = 'YOUR_DATABASE_USERNAME';
$config['db_pass'] = 'YOUR_DATABASE_PASSWORD';
$config['db_name'] = 'YOUR_DATABASE_NAME';
?>
Now your index code:
PHP Code:
<?PHP
require_once('db.php');
session_start();
$_SESSION['code'] = md5(rand(1,1000));
$_SESSION['user'] = $user2;
$_SESSION['nickname'] = $nickname;
$res = mysql_query("SELECT * FROM guidtech WHERE user='". $_SESSION['user'] ."'")or die(mysql_error());
//$data = mysql_fetch_assoc($res);
if(mysql_num_rows($res) >= 1) {
mysql_query("UPDATE guidtech SET code='" . $_SESSION['code'] ."', user='". $_SESSION['user'] . "', nickname='". $_SESSION['nickname']."' WHERE user='" . $_SESSION['user'] ."'")or die(mysql_error());
}
else {
mysql_query("INSERT INTO guidtech (user, nickname, code) VALUES ('". $_SESSION['user'] ."', '". $_SESSION['nickname']."', '" .$_SESSION['code'] ."')")or die(mysql_error());
}
header("Location: settings.php");
ob_end_flush();
?>
Oh.. I've miss-spelled the table I thought it was "guildtech" but it was GUITech, so the I've changed GUITech inside the script to guildtech so it should work now..
And BTW you need to have a settings.php because after this script has been ran, it's going to redirect you to settings.php (that's what header(""); does..)
The SQL that I have for this is:
Code:
-- phpMyAdmin SQL Dump
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `guild`
--
-- --------------------------------------------------------
--
-- Table structure for table `guidtech`
--
CREATE TABLE IF NOT EXISTS `guidtech` (
`code` varchar(20) NOT NULL,
`user` varchar(25) NOT NULL,
`nickname` varchar(25) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `guidtech`
--
INSERT INTO `guidtech` (`code`, `user`, `nickname`) VALUES
('7f24d240521d99071c93', '', '');
Hope that works, if not then sorry :P
I tested it and it redirected me to settings.php so hopefully it'll do the same for you.