Closed
Moderator: General Moderators
-
Ultimadark
- Forum Newbie
- Posts: 9
- Joined: Sun Sep 21, 2003 5:57 am
You connect to the MySQL database. Then first check for the username:
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
Code: Select all
SELECT * FROM "users" WHERE username = '$_POSTї'username'] AND email = '$_POSTї'email']-Nay
-
Ultimadark
- Forum Newbie
- Posts: 9
- Joined: Sun Sep 21, 2003 5:57 am
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
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
-
Ultimadark
- Forum Newbie
- Posts: 9
- Joined: Sun Sep 21, 2003 5:57 am
<?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);
}
?>
This shows on the top of the page, and the script isnt working.'0' ) { (header(Location: failedsign.html)) } else { (header(Location: signup.php)) } mysql_close($con); } ?>
Yes ive started on the code, but i did it last week im still very very much a newbie in php.
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.
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
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);
}
?>-Nay
-
Ultimadark
- Forum Newbie
- Posts: 9
- Joined: Sun Sep 21, 2003 5:57 am
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
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
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
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
-
Ultimadark
- Forum Newbie
- Posts: 9
- Joined: Sun Sep 21, 2003 5:57 am
-
Ultimadark
- Forum Newbie
- Posts: 9
- Joined: Sun Sep 21, 2003 5:57 am
http://www.frac.dk
i tried mysql hosting at http://www.freesql.org some days ago but i think theyre very slow
i tried mysql hosting at http://www.freesql.org some days ago but i think theyre very slow
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
-Nay
-
Ultimadark
- Forum Newbie
- Posts: 9
- Joined: Sun Sep 21, 2003 5:57 am
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
I think my flash intro is pretty good u can wiew it here
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);
?>-Nay