Help Needed.

Status
Not open for further replies.

Xenous

o shi
Nov 15, 2011
383
101
Well I decided I would try and make a cms and I have come along a little problem with mysql.
It won't seem to insert data into the database I know it is probably something simple that I have missed but if you could help me I would appreciate it.
My code is:
register.php:
PHP:
<?php include('/global.php'); ?>
<html>
<head>
<title>
<?php 
print $hotelname;
?>
</title>
</head>
<body>
<?php
if(isset($_SESSION['loggedin'])==1)
{
echo 'You are already logged in please go back';
}
else if(isset($_POST['Register']))
{
$username = strip_tags(mysql_real_escape_string($_POST['username']));
$password = md5(strip_tags(mysql_real_escape_string($_POST['password'])));
$password2 = md5(strip_tags($_POST['password2']));
$email = strip_tags(mysql_real_escape_string($_POST['email']));
$ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
if (empty ($username)||empty($password)||empty($password2)||empty($email))
{
echo 'Please fill in all areas and try again';
}
else if ($password !== $password2)
{
echo 'Passwords do not match please try again';
}
else
{
$usertaken = mysql_query("SELECT * FROM users WHERE `username`='$username' ");
if (mysql_num_rows($usertaken)==1)
{
echo 'This username is already taken please choose a different one';
}
else
$iptaken = mysql_query("SELECT * FROM users WHERE `ip_reg`='$ip' ");
if (mysql_num_rows($iptaken)==3)
{
echo ' You already have the limit of 3 accounts';
}
else
{
$emailtaken = mysql_query("SELECT * FROM users WHERE `mail` = '$email' ");
if (mysql_num_rows($emailtaken)==1)
{
echo 'Sorry this email is taken please try again';
}
else
{
mysql_query("INSERT INTO `users` (`username`, `password`, `mail`, `ip_reg`) VALUES('{$username}','{$password}','{$email}'.'{$ip}')")
or die('Registery failed please re register');
}
    }
        }
            }
           
?>
<form method="post">
Username: <input type="textbox" name="username" maxlength="10"><br>
Password: <input type="password" name="password" maxlength="12"><br>
Password Again: <input type="password" name="password2" maxlength="12"><br>
Email: <input type="textbox" name="email" maxlength="30"><br>
<input type="submit" name="Register" value="Register">
</form>
config.php:
PHP:
<?php
$dbhost = 'localhost'; //Put host here.
$dbuser = 'root'; //Put mysql username here.
$dbpass = '(secret)'; //Put mysql password here.
$dbselect = 'phoenix'; //Put database name here.
$hotelname = 'RetroHotel'; //Put hotel name here.
?>
Global.php:
PHP:
<?php
include ('/config.php');
$mysql = mysql_connect($dbhost,$dbuser,$dbpass);
$mysqldb = mysql_select_db($dbselect,$mysql)
or die('Cant connect to mysql');
?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Change
PHP:
mysql_query("INSERT INTO `users` (`username`, `password`, `mail`, `ip_reg`) VALUES('{$username}','{$password}','{$email}'.'{$ip}')")

to

PHP:
mysql_query("INSERT INTO `users` (`username`, `password`, `mail`, `ip_reg`) VALUES('{$username}','{$password}','{$email}', '{$ip}')");
 

Xenous

o shi
Nov 15, 2011
383
101
Change
PHP:
mysql_query("INSERT INTO `users` (`username`, `password`, `mail`, `ip_reg`) VALUES('{$username}','{$password}','{$email}'.'{$ip}')")

to

PHP:
mysql_query("INSERT INTO `users` (`username`, `password`, `mail`, `ip_reg`) VALUES('{$username}','{$password}','{$email}', '{$ip}')");
No, that would cause a syntax error.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
How would that cause a syntax error? You've asked for help, I've given it to you and now you're dictating to me what is right and wrong.

You put:
PHP:
'{$email}'.'{$ip}')")

And not:
PHP:
'{$email}','{$ip}')");
 

Xenous

o shi
Nov 15, 2011
383
101
How would that cause a syntax error? You've asked for help, I've given it to you and now you're dictating to me what is right and wrong.

You put:
PHP:
'{$email}'.'{$ip}')")

And not:
PHP:
'{$email}','{$ip}')");
We both partially failed there but thanks for the help, the ";" wasnt needed due to the die function but you helped me get it working so thanks again your a great help.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
We both partially failed there but thanks for the help, the ";" wasnt needed due to the die function but you helped me get it working so thanks again your a great help.
Oh yeah, I never seen the die() because it went onto a new line :p

Anyway, no worries. Glad it helped.

Thread closed, problem solved.
 
Status
Not open for further replies.

Users who are viewing this thread

Top