Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
fariquzeli
Forum Contributor
Posts: 144 Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:
Post
by fariquzeli » Mon Jun 24, 2002 10:51 am
I've tried several different things with this, and the code I currently have does not report an error message if the user enters an already in-use password, it just refreshes the form page. Here is the code I have:
Code: Select all
<? //initilize PHP
include("webvars.inc");
mysql_connect("$hostname","$user","$pass") or die(); //connect
mysql_select_db("pancorp"); //select db
if($submit) {
$usertest = $_POSTї'username'];
$sql = "SELECT username FROM technicians WHERE username = '$usertest'";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) != 0) {
echo 'Username taken, please choose another username.';
}
else {
$sql2 = "INSERT INTO technicians (id,username,password,firstname,lastname,email,location,phonenumber)".
"VALUES ('NULL', '$username', '$password', '$firstname', '$lastname', '$email', '$location', '$phonenumber')";
$result=mysql_query($sql2) or die(); //Insert into db
header ("location: http://www.pancorp.com/techs/thanks.php");
}
}
mysql_close();
?>
The form is on the same page and just echoes itself.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Tue Jun 25, 2002 2:06 am
Does it work if you use a not-already-used password?
Have you read
this ?
Mac
fariquzeli
Forum Contributor
Posts: 144 Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:
Post
by fariquzeli » Tue Jun 25, 2002 9:20 am
it works great if I have use an unused username. Form goes through fine.
ssand
Forum Commoner
Posts: 72 Joined: Sat Jun 22, 2002 9:25 pm
Location: Iowa
Post
by ssand » Tue Jun 25, 2002 10:11 am
First I should warn I am a newbie.
Does it matter that your echo statement is not in double quotes instead of single quote marks?
Or you could try:
Code: Select all
if($submit)
{
$usertest = $_POSTї'username'];
$sql = "SELECT count(*) FROM technicians WHERE
username = '$usertest';
$result = mysql_query($sql) or die(mysql_error());
$count = mysql_result($result);
if ($count = 0)
{
echo "Username taken, please choose another username.";
}
... etc.
Note: Untested and like I said I'm new to this.
fariquzeli
Forum Contributor
Posts: 144 Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:
Post
by fariquzeli » Tue Jun 25, 2002 10:13 am
single quotes doesn't matter it only has one argument.
That basically will do the same thing.
ssand
Forum Commoner
Posts: 72 Joined: Sat Jun 22, 2002 9:25 pm
Location: Iowa
Post
by ssand » Tue Jun 25, 2002 10:18 am
Does your submit button tag have a name=submit ?
mikeq
Forum Regular
Posts: 512 Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland
Post
by mikeq » Tue Jun 25, 2002 12:46 pm
$result = mysql_query($sql) or die(mysql_error());
try printing the value of mysql_num_rows to see what it is
$HowMany = mysql_num_rows($result);
print "Total number of records is $HowMany";
if ($HowMany > 0) {
echo 'Username taken, please choose another username.';
}
else {[/b]
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Wed Jun 26, 2002 2:24 am
I agree with mikeq, you really need to echo everything to find out where the problem is, that is you need to know what information you're giving and getting in order to effectively debug code so try:
Code: Select all
$usertest = $_POSTї'username'];
$sql = "SELECT username FROM technicians WHERE username = '$usertest'";
echo '$sql: '.$sql; // DEBUGGING
$result = mysql_query($sql) or die(mysql_error());
echo '<br />num_rows: '.mysql_num_rows($result); // DEBUGGING
if (mysql_num_rows($result) != 0) {
echo 'Username taken, please choose another username.';
}
Obviously you remove all of these echo's once the problem is sorted.
Mac
fariquzeli
Forum Contributor
Posts: 144 Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:
Post
by fariquzeli » Wed Jun 26, 2002 9:14 am
thanks.