Page 1 of 1

[SOLVED] PHP/database error

Posted: Mon Jun 21, 2004 1:25 pm
by marker5a
Ok
I am trying to develop a script that allows a user to sign up for email. After signing up, they get a comfirmation email, with a link, to activate the account. The activation process involves transfering the user data they entered into the initial form from the temporary table, to a permanant table. Than, it deletes the row in the temporary table. For debugging purposes, I have setup a dummy account on the temp table, marker5a. The activation link is http://www.marker5a.com/database/hostin ... d=marker5a.

The code is here.

Code: Select all

<?php
$username = $HTTP_GET_VARS['id'];
$db = mysql_connect("localhost", "*", "*");
mysql_select_db("$db_name",$db);
$sql="SELECT * FROM `temp_confirm` where username=$username";$result=mysql_query($sql,$db);
$row = mysql_fetch_array($result);
$username=$row["username"];echo $username;if(empty($username)){$db = mysql_connect("localhost", "root", "window12");mysql_select_db('hosting_db',$db);$sql="SELECT * FROM `temp_confirm`where username="$username"";$result=mysql_query($sql,$db);
$row2==mysql_fetch_array($result);
$username=$row2['username'];$password=$row2['password'];$email=$row2['email'];$name=$row2['name'];$gender=$row2['gender'];$dob=$row2['dob'];
mysql_query("insert into `data` (username,password,email,name,gender,dob) values ('$username','$password','$email','$name','$gender','$dob')");
mysql_query("DELETE FROM `temp_confirm` WHERE username="$username"");}

if(isset($username)){print " <p align="center" style="word-spacing: 0; line-height: 100%; margin-top: 0; margin-bottom: 0"><b><u><font size="4">The
username $username has either already been activated or has not yet been
created.&nbsp; </font></u></b></p>
<p align="center" style="word-spacing: 0; line-height: 100%; margin-top: 6; margin-bottom: 0"><b><u><font size="4">Please
return to the signup page to create another account.</font></u></b></p>
<p align="center" style="word-spacing: 0; line-height: 100%; margin-top: 6; margin-bottom: 0">&nbsp;</p>
<p align="center" style="word-spacing: 0; line-height: 100%; margin-top: 6; margin-bottom: 0"><b><u><font size="4">Thank
you</font></u></b></p>
<p align="center" style="word-spacing: 0; line-height: 100%; margin-top: 6; margin-bottom: 0"><b><u><font size="4">Chris
Hamilton</font></u></b></p>\n ";}
?>
I am getting the following error message, that I do not know how to resolve.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\htdocs\database\hosting_database\confirmed.php on line 6

PLease help me. Thanks

Chris


feyd|use

Code: Select all

tags when posting code.[/color]

Posted: Mon Jun 21, 2004 1:37 pm
by feyd
change

Code: Select all

$result=mysql_query($sql,$db);
to

Code: Select all

$result=mysql_query($sql,$db) or die(mysql_error());

Posted: Mon Jun 21, 2004 1:42 pm
by marker5a

Posted: Tue Jun 22, 2004 2:53 pm
by marker5a
Wow,
Im a fool. Ok, on line 4, the mysql_select_db command was trying to connect to a database saved in a variable that didnt exist. It works great now. Thanks for helping me out guys.

Chris