Jump to content

Archived

This topic is now archived and is closed to further replies.

CyDrive

Need help

Recommended Posts

Ok im making a user managment system. Now this is only a test one to see if i can make it work before i make one for my real website. Though i keep getting an error on line 18 in my register2.php file. Here is the code.

[code]
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$picture = $_POST["picture"];
$ip = $REMOTE_ADDR;
$username = strip_tags($username);
$email = strip_tags($email);
$picture = strip_tags($picture);
$password = md5($password);
if ( !$username || !$password || !$email || !$picture) {
die( "All fields are required!" );
}
$connect = mysql_connect( "x", "x", "x" );
if ( ! $connect ) {
die( "Could not connect to SQL server" );
}
$insertstatement = "INSERT INTO Users VALUES ('$username', '$password', '$email')";
mysql_select_db( "cydrive_test", $connect )
or die ("Could not open database:" .mysql_error() );
$selectresult = mysql_query( "SELECT * FROM Users WHERE username=’$username’", $connect );
$numrows = mysql_num_rows( $result );
if ( $numrows > 0 ) {
print "The username you have chosen is in use. Please choose another one.";
} else {
mysql_query($insertstatment, $connect )or die( "Couldn't add data to table" );
print "Registration successful! Login <a href="login.php">
here</a>";
}
?>
[/code]

Heres the code for register.php is it helps any.

[code]
<HTML>
<TITLE>Index Page</title>
<BODY bgcolor="#ffffff">
<html>
<body bgcolor = "black">
<?
session_start();
if($_SESSION["username"] = null) {
?>
<form action="register2.php" method="post">
Username: <input type="text" name="username" size="15"><br>
Password: <input type="password" name="password" size="32"><br>
Email: <input type="text" name="email" size="50";><br>
Picture: <input type="text" name="pictures" size="1000";><br>
<center><input type="submit"><input type="reset"></center>
</form>
<?
}else{
print"You are already logged in";
?>
</body>
</html>
</BODY>
</HTML>
[/code]

Heres a link to register.php
[url=http://h1.ripway.com/cydrive/]http://h1.ripway.com/cydrive/[/url]

[b]edit(shoz): removed login details[/b]

Share this post


Link to post
Share on other sites
Not being that experienced in mySql, I have had a quick look for you and I think I may have spotted your problem

lines 14 - 17 connect to your database server

your line 18 is trying to insert into the database, but you are not yet connected to the database untill line 19

try this
[code]<?php
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$picture = $_POST["picture"];
$ip = $REMOTE_ADDR;
$username = strip_tags($username);
$email = strip_tags($email);
$picture = strip_tags($picture);
$password = md5($password);
if ( !$username || !$password || !$email || !$picture) {
die( "All fields are required!" );
}
$connect = mysql_connect( "x", "x", "x" );
if ( ! $connect ) {
die( "Could not connect to SQL server" );
}
mysql_select_db( "cydrive_test", $connect ) or die ("Could not open database:" .mysql_error() );
$insertstatement = "INSERT INTO Users VALUES ('$username', '$password', '$email')";
$selectresult = mysql_query( "SELECT * FROM Users WHERE username=’$username’", $connect );
$numrows = mysql_num_rows( $result );
if ( $numrows > 0 ) {
print "The username you have chosen is in use. Please choose another one.";
} else {
mysql_query($insertstatment, $connect )or die( "Couldn't add data to table" );
print "Registration successful! Login <a href="login.php">
here</a>";
}
?>[/code]

Share this post


Link to post
Share on other sites
Incidentally, you can put the DB name into your connection line as well, AFAIK.

Share this post


Link to post
Share on other sites

×

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.