Ill try to give a short account of what i need help with.
Im currently in the process of building my own forums from scratch using PHP+MySQL.
I have the signup.php page and the create_cat.php page. I also have the connect.php which is used to connect to the MySQL database when every page loads.
But for some reason it will not let me select which database I want to use.
Every page loads fine untill i tell it to include the connect.php.
im using PHP 5 and MySQL 5.5.
i also created a test page to see if it could connect to just the main MySQL database using this syntax:
And that connects fine.
Im also including a copy of the signup.php page just incase the mysql part of that form could have errors i am not seeing.
and it says it connects fine.
anyone have an easy solution to this? (besides getting a pre-made forum)
Im using Apache 2.2 as well.
Im currently in the process of building my own forums from scratch using PHP+MySQL.
I have the signup.php page and the create_cat.php page. I also have the connect.php which is used to connect to the MySQL database when every page loads.
But for some reason it will not let me select which database I want to use.
Every page loads fine untill i tell it to include the connect.php.
Code:
<?php
//connect.php
$server = 'localhost';
$username = 'root';
$password = 'salamander';
$database = 'website';
if(!mysql_connect($server, $username, $password, $database))
{
exit('Error: could not establish database connection');
}
?>
i also created a test page to see if it could connect to just the main MySQL database using this syntax:
Code:
<?php
$link = mysql_connect(
'localhost',
'root',
'salamander',
'website'
);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
Im also including a copy of the signup.php page just incase the mysql part of that form could have errors i am not seeing.
Code:
<?php
//signup.php
include 'connect.php';
include 'header.php';
echo '<h3>Sign up</h3>';
if($_SERVER['REQUEST_METHOD'] != 'POST')
{
echo '<form method="post" action="">
Username: <input type="text" name="user_name" /><br />
Password: <input type="password" name="user_pass"><br />
Password again: <input type="password" name="user_pass_check"><br />
E-mail: <input type="email" name="user_email"><br />
<input type="submit" value="Register" /><br />
</form>';
}
else
{
$errors = array();
if(isset($_POST['user_name']))
{
if(!ctype_alnum($_POST['user_name']))
{
$errors[] = 'The username can only contain letters and digits.';
}
if(strlen($_POST['user_name']) > 30)
{
$errors[] = 'The username cannot be longer than 30 characters.';
}
}
else
{
$errors[] = 'The username field must not be empty.';
}
if(isset($_POST['user_pass']))
{
if($_POST['user_pass'] != $_POST['user_pass_check'])
{
$errors[] = 'The two passwords did not match.';
}
}
else
{
$errors[] = 'The password field cannot be empty.';
}
if(!empty($errors))
{
echo 'Uh-oh.. a couple of fields are not filled in correctly..';
echo '<ul>';
foreach($errors as $key => $value)
{
echo '<li>' . $value . '</li>';
}
echo '</ul>';
}
else
{
$sql = "INSERT INTO
users(user_name, user_pass, user_email ,user_date, user_level)
VALUES('" . mysql_real_escape_string($_POST['user_name']) . "',
'" . sha1($_POST['user_pass']) . "',
'" . mysql_real_escape_string($_POST['user_email']) . "',
NOW(),
0)";
$result = mysql_query($sql);
if(!$result)
{
echo 'Something went wrong while registering. Please try again later.';
}
else
{
echo 'Successfully registered. You can now <a href="signin.php">sign in</a> and start posting! :-)';
}
}
}
include 'footer.php';
?>
anyone have an easy solution to this? (besides getting a pre-made forum)
Im using Apache 2.2 as well.


Comment