Need Help with Simple Registration Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Need Help with Simple Registration Form

Post by Citizen »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I get this error:

Code: Select all

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource on line 50

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource  on line 51
Thank you! Information entered.

The connect.php file has my connection script, which looks like this:

Code: Select all

<?php
$dbh=mysql_connect ("localhost", "*****", "****") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("****");
?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Last edited by Citizen on Tue Mar 07, 2006 1:37 pm, edited 1 time in total.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Check db user name and password... Likely as not, that's your problem! Good luck...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ahem, $db vs $dbh
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

I tried the advice you just gave me, but nothing that I try seems to work. What exactly do I need to change?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

like feyd said

Code: Select all

$result=mysql_query($sql,$db);
:arrow:

Code: Select all

$result=mysql_query($sql,$dbh);
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

Ok, I made the changes and I'm getting this error now:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource on line 50

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 51

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource on line 62
Thank you! Information entered.

Contents of the connect.php file:

Code: Select all

<?php
$dbh=mysql_connect ("localhost", "db_name", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("db_name");
echo 'Connected successfully';
?>
On the pages, it does echo "connected sucessfully"
Last edited by Citizen on Tue Mar 07, 2006 1:37 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your php doesn't like $dbh being passed to mysql_query(), try removing them. They often aren't needed anyways.
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

Thanks!


Line 51 is:
$samenick = mysql_num_rows($result);

BTW, do you take donations? I dont have a lot, but I could toss a buck or two your way.
Last edited by Citizen on Tue Mar 07, 2006 1:36 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your SQL has an error in it..
'accounts'
vs
`accounts`

notice: ' and `
Citizen wrote:BTW, do you take donations? I dont have a lot, but I could toss a buck or two your way.
The forum does not take donations at this time. However individual users may be open to it. :)
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

feyd wrote:your SQL has an error in it..
'accounts'
vs
`accounts`

notice: ' and `

Also,
feyd wrote:
Citizen wrote:BTW, do you take donations? I dont have a lot, but I could toss a buck or two your way.
The forum does not take donations at this time. However individual users may be open to it. :)
I meant you, not the forum itself :)
Last edited by Citizen on Tue Mar 07, 2006 1:35 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

check what mysql_error() outputs, you likely need to backtick "name" and should probably escape $name (mysql_real_escape_string())

regarding donations, check your private messages.
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

feyd wrote:check what mysql_error() outputs, you likely need to backtick "name" and should probably escape $name (mysql_real_escape_string())
I'm not exactly sure what I need to do. I'm pretty new to php and mysql. What do I need to change?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

basics:

Code: Select all

<?php

//........

$result=mysql_query($sql);

//........

?>
to

Code: Select all

<?php

//........

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

//........

?>
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

Thanks. I got this error back....

"No Database Selected" but I didnt see any other errors.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Make sure the database you're requesting exists and that the function is being called.
Post Reply