Jump to content


Photo

Need help


  • Please log in to reply
3 replies to this topic

#1 CyDrive

CyDrive
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 05 August 2006 - 07:19 AM

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.

<?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>";
}
?>

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

<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>

Heres a link to register.php
http://h1.ripway.com/cydrive/

edit(shoz): removed login details

#2 paul2463

paul2463
  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 05 August 2006 - 10:26 AM

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
<?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>";
}
?>

you cannot affect the past but you can ruin a perfectly good present by worrying about the future

*********************************************************************
The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource

#3 CyDrive

CyDrive
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 05 August 2006 - 11:14 AM

Thanks alot it worked.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 05 August 2006 - 03:23 PM

Incidentally, you can put the DB name into your connection line as well, AFAIK.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users