/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] quick problem

hey, ive got a simple registration script that doesnt seem to want to look, just some if else statements a few database connections thats, i cant seem to get this thing to work, its probally something simple, any help would be appreciated.

[code=php]
<?php
include(“database.inc”);
$username = $_POST[‘username’];
$password = $_POST[‘password’];
$v_password = $_POST[‘vpassword’];
$email = $_POST[’email’];
$v_email = $_POST[‘vemail’];
if ($username == “” || $password == “” || $v_password == “” || $email == “” || $v_email == “”){
header(“Location: register.php?error=4”);
} else {
$connection = mysql_connect($host,$user,$password)
or die (‘Couldnt connect: ‘.$connection.’ – Error: ‘.mysql_error());
$db = mysql_select_db($database, $connection)
or die (‘Couldnt select database: ‘.$db.’ – Error: ‘.mysql_error());
$sql = “SELECT loginName FROM members
WHERE loginName=’$username”;
$result = mysql_query($sql)
or die (‘Couldnt execute query 1: ‘.$sql.’ – Error: ‘.mysql_error());
$num = mysql_num_rows($result);
if ($num != 0){
header(“Location: register.php?error=1”);
} else {
if ($password != $v_password){
header(“Location: register.php?error=2”);
} else {
if ($email != $v_email){
header(“Location: register.php?error=3”);
} else {
$today = date(“Y-m-d”);
$sql = “INSERT INTO members (loginName,createDate,password,email,access)
VALUES(‘$username’,’$today’,md5(‘$password’),’$email’,’0′)”;
mysql_query($sql);
header(“Location: register.compelte.php”);
}
}
}
}
?>
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 02.2006 — You might want to validate that the final insert query is working:
[code=php]
else {
$today = date("Y-m-d");
$sql = "INSERT INTO members (loginName,createDate,password,email,access)
VALUES('$username','$today',md5('$password'),'$email','0')";
$result = mysql_query($sql) or die("Query failed: $sql - " . mysql_error());
header("Location: register.compelte.php");
}
[/code]
Copy linkTweet thisAlerts:
@chazzyMar 02.2006 — Also, when you use die syntax, like in here:

[code=php]
$connection = mysql_connect($host,$user,$password)
or die ('Couldnt connect: '.$connection.' - Error: '.mysql_error());
$db = mysql_select_db($database, $connection)
or die ('Couldnt select database: '.$db.' - Error: '.mysql_error());
[/code]

$connection and $db will have no values and this could cause problems. Basically when you say "set $db to mysql_select_db or kill the application [because i couldn't set that value]" you could have some problems. Though tha'ts not related to this issue, figured I'd throw that out there.
Copy linkTweet thisAlerts:
@welshauthorMar 02.2006 — its redirecting me to my first error: register.php?error=1 which on register php it picks up and displays one or more fields is empty. my guess its got to be something with:
[code=php]if ($username == "" || $password == "" || $v_password == "" || $email == "" || $v_email == ""){
header("Location: register.php?error=4");
} else { [/code]
Copy linkTweet thisAlerts:
@SpectreReturnsMar 02.2006 — That piece of code isn't the part that redirects you to register.php?error=1. Since you're getting register.php?error=1, it means there's something wrong with your sql query:
[code=php] $sql = "SELECT loginName FROM members
WHERE loginName='$username";
$result = mysql_query($sql)
or die ('Couldnt execute query 1: '.$sql.' - Error: '.mysql_error());
$num = mysql_num_rows($result);
if ($num != 0){
header("Location: register.php?error=1"); [/code]
Copy linkTweet thisAlerts:
@welshauthorMar 02.2006 — ok, it was something really really stupid, i spelled one of the input fields in wrong, time for the rest of debuggin,srry to waste ur time, and it works after i found out i used the same variable twice *jumps of a bridge*
×

Success!

Help @welsh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...