Page 1 of 2
Closed
Posted: Sun Sep 21, 2003 5:57 am
by Ultimadark
Closed
Posted: Sun Sep 21, 2003 7:28 am
by Nay
You connect to the MySQL database. Then first check for the username:
Code: Select all
SELECT * FROM "users" WHERE username = '$_POSTї'username'] AND email = '$_POSTї'email']
Then, count how many rows are returned with mysql_num_rows. If it is 0, which it should be, then continue. If there is 1, then redirect to the page that says username is already taken.
-Nay
Posted: Sun Sep 21, 2003 8:12 am
by Ultimadark
Since im a newb, could u help me out with that code too?
Ive just started with php lol
Posted: Sun Sep 21, 2003 8:44 am
by Nay
Have you even started on the code?
You should do some research. We're here to help, not do-for-you.
Anyhow, the script. Give it a try first. Then post the not-working script here. We'll help you get it to a running stage. Then you can learn from it.
I'll give you some guidelines to go about doing it. The rest is up to you.
- Connect to your MySQL database (mysql_connect(), mysql_select_db)
- Set a variable for the query
- Execute the query (mysql_query())
- Count the number of rows (mysql_num_rows())
- If row is 0, redirect to success page (header(Location: success.php))
- Else if row is 1, then redirect to error page.
-Nay
Posted: Sun Sep 21, 2003 8:56 am
by Ultimadark
<?php $con = mysql_connect("localhost", "ultimadark", "************")or die("Connect Error: ".mysql_error());
$db="ultimadark";
mysql_select_db($db, $con);
SELECT * FROM "users" WHERE username = '$_POST['username'] AND email = '$_POST['email']
if (mysql_num_rows > '0' )
{
(header(Location: failedsign.html))
}
else
{
(header(Location: signup.php))
}
mysql_close($con);
}
?>
'0' ) { (header(Location: failedsign.html)) } else { (header(Location: signup.php)) } mysql_close($con); } ?>
This shows on the top of the page, and the script isnt working.
Yes ive started on the code, but i did it last week im still very very much a newbie in php.
Posted: Sun Sep 21, 2003 9:12 am
by Nay
Okay, good

. Let's see what's wrong. The code below is your code, with certain corrections. Read through it - I left some notes for you.
Code: Select all
<?php
// set sql variables
$host = "localhost";
$user = "ultimadark";
$pass = "************";
$db = "ultimadark";
$con = mysql_connect($host, $user, $pass)or die("Connect Error: ".mysql_error());
mysql_select_db($db, $con);
// set the variable for the query
$q = "SELECT * FROM 'users' WHERE username = $_POST['username'] AND email = $_POST['email']";
// execute the query
$result = mysql_query($q, $con);
// count rows
$rows = mysql_num_rows($result);
if ($rows=="0") {
header(Location: failedsign.html) }
else {
header(Location: signup.php) }
mysql_close($con);
}
?>
I used variables to connect to MySQL. It's not necessary but I'd recommend it, if you're doing more than one script. Then you can have a seperate file with the SQL variables and include it when you need to use it. So if there's any change, you can change it quickly and effectively.
-Nay
Posted: Sun Sep 21, 2003 10:26 am
by Ultimadark
Thanks really for the help man

Just one more thing. Is this some fault in the script or is it just that my host for mysql is bad (sometimes when i try to log in on phpadmin it says too many connections):
Warning: mysql_connect() [function.mysql-connect]: Too many connections in /web/www/frac/users/ultimadark/signup.php on line 2
Connect Error: Too many connections
Posted: Sun Sep 21, 2003 10:32 am
by Nay
http://www.mysql.com/doc/en/Too_many_connections.html
What's your website? Run a whois.sc/yourdomain.com and check how many sites are hosted on your server. This is probably since too many people are connecting to the SQL server at the same time.
Well, that's my thing. I think maybe someone has a better solution. mMm
-Nay
Posted: Sun Sep 21, 2003 10:36 am
by Ultimadark
Yeh i think your right. Now i just gotta get a better mysql host

Posted: Sun Sep 21, 2003 10:42 am
by Nay
If you don't mind me asking, who's your host anyway?
-Nay
Posted: Sun Sep 21, 2003 10:44 am
by Ultimadark
http://www.frac.dk
i tried mysql hosting at
http://www.freesql.org some days ago but i think theyre very slow
Posted: Sun Sep 21, 2003 10:48 am
by Nay
Oh, free hosting I see. Well, try:
http://www.webhosts4free.com/. I found some hosts with PHP and MySQL with no banners there. Anyhow, I'd say get better and better at PHP and advertise yourself. I got my two domains and two reseller hosting accounts by designing a few sites and PHP back-ends for some people.
-Nay
Posted: Sun Sep 21, 2003 11:19 am
by Ultimadark
Cool

I wish i were that good
Posted: Sun Sep 21, 2003 11:31 am
by Ultimadark
Oh and anyway i might get hosting next week at
http://www.namek.co.uk , i have applied for a competition for an intro to his site. The best intro wins free hosting there with no demands on already having a good website
I think my flash intro is pretty good u can wiew it
here
Posted: Sun Sep 21, 2003 5:48 pm
by Nay
Code: Select all
<?php
$host = "localhost";
$user = "ultimadark";
$pass = "********";
$db = "ultimadark";
$con = mysql_connect($host, $user, $pass)or die("Connect Error: ".mysql_error());
mysql_select_db($db, $con);
$q = "SELECT * FROM 'users' WHERE username = $_POST['username'] AND email = $_POST['email']";
$result = mysql_query($q, $con);
$rows = mysql_num_rows($result);
if ($rows=="0") {
header("Location: signup.php.html"); }
else {
header("Location: failedsign.html"); }
mysql_close($con);
?>
You forgot the ; after the header()'s. I would not put <html> tags IMHO, since this is a kind of process page, you're not displaying anything. And from what I know, put a space after location in headers. header("Location: signup.php") not header("Location:signup.php"). Yeah, one more thing. Why was it signup.php.html anyway? It's either .html, which I doubt, .php or .phtml

.
-Nay