Jump to content

Recommended Posts

Posted

Hi everyone,

 

I'm Deno, and I'm new to this forum. I just purchased web hosting from totalchoicehosting last week, and I like it so far.

 

Anywho, I'm having some trouble with my php scripting, and I'm wondering if anybody can help me out, I'd really appreciate it:

 

I have a MySQL DB setup already, and when I want to do a simple data retrieval, say a user clicks on a link and retrieves that specific data on that specific link. However, when I uploaded my page to the webserver, I get an error that MySQL functions such as mysql_fetch_array and mysql_num_rows are INVALID functions. Why is this? Could someone explain to me how to get it running and what I'm doing wrong here. Again, any help would be totally appreciated. :wacko:

 

 

Here's my code:

 

$Host = "localhost";

$User = "USERNAME

$Password = "PASSWORD";

$DBName = "DBNAME";

$TableName = "$select";

 

$Link = mysql_connect($Host,$User,$Password); //connect to the database

 

$Query = "select * from $TableName";

$Result = mysql_db_query($DBName,$Query,$Link);

 

if(mysql_num_rows($Result) == 0) {

print("No results to display.");

print("$select");

} //checks to see if there's any data to display

 

while ($Row = mysql_fetch_array($Result)) {

//print("<b><a href='newsdetail.php?detailno=$Row[newsID]'>$Row[headline]</a></b><p>");

print("$Row[name]<p><br></p>");

//}

 

mysql_close($Link); //close the connection

Posted

Hi Deno.

 

First of all, welcome to the family! :(

 

I was about to say that the admin who set up the server forgot to compile PHP with MySQL support but from what you said, all other MySQL functions are working, right?

If it said that you had invalid parameters or something like that, we could narrow the problem to some error on the script itself but if PHP says those are invalid functions...

That's really strange... :wacko:

 

Could you please submit a help desk ticket so one of the admins can take a look at the situation?

 

Let us know how it goes, OK? I'm curious about this one.

Posted

I sent a ticket to help desk, but they tell me to go to the forum cause the tech support don't deal with scripting code.

 

They did however give me this code:

 

$dbh=mysql_connect ("localhost", "starryc_Deno", "PASSWORD") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("starryc_db1starryc");

 

They were telling me that I didn't create the user in the DB. When I now run the script, I STILL get the same error, it's saying that functions such as mysql_db_query, mysql_num_rows, mysql_fetch_array and mysql_close are not valid functions.

 

Could someone please help me out? what am I doing wrong? Any help would be appreciated. Thanks.

Posted

Deno, check your PMs.

 

I don't think the code they gave you has anything to do with the problem (the problem is not with the connection to the database) but before telling you to reopen the help desk ticket, I'll take a look at the problem myself. :(

Posted

Hi Deno,

 

I can see a couple of errors in your code which may be affecting things, or it may be just the copy you have posted.

 

>$User = "USERNAME

should be;

>$User = "USERNAME";

 

and

>//}

is commenting out the close bracket, when you need it

 

Andy

Posted (edited)

I noticed those, too, Andy. But I don't think that's the source of the problem because if it was, then PHP wouldn't say that mysql_*() is an undefined function. It would say the script contained a parse error on line X.

 

I'd say the " after the USERNAME is there in the original script but Deno inadvertently deleted it when changing the info to post the code.

 

Not sure about the } being commented out but that wouldn't result in mysql_*() being reported as invalid functions either.

 

Deno is reading these posts right now, so let's wait and see what he has to say :(

Edited by TCH-Raul
Posted

Can you provide a link so that we can see the exact error message and determine where the problem might lie. I spent some time looking at your Help Desk ticket but there was no information about where the code is located so I could not do much. There was no user connected to the database and I corrected that.

Posted

Thanks for replying and for your help everybody, I appreciate it a lot.

 

I did notice the } error as mentioned and changed it, but I'm still getting the error.

 

The link to my client's site is http://www.starryconstellation.com. Click on the "Interviews" button, and you'll find my error there. What I actually want it to do, is when you click on that button, it'll go and retrieve a list of interviews from the MySQL DB, but now you'll find those errors I've mentioned.

 

Please let me know what you think of this situation. Thanks again.

 

Deno

Posted (edited)

Oh! So the problem is not quite with the functions but with their arguments! :)

 

Well, the first function reporting an invalid argument (mysql_db_query()) says the "supplied argument is not a valid MySQL-Link resource", which means in fact that the problem is on the database connection - my apologies to whoever mentioned this on the help desk, seems you were right.

 

I have never used the mysql_db_query() function, I always use mysql_query(), which doesn't need a MySQL-Link resource at all. Actually, now that I went to php.net looking for the documentation for mysql_db_query(), here's what they have to say about it:

    Note:  This function has been deprecated since PHP 4.0.6. Do not use this function. Use mysql_select_db()  and mysql_query() instead.
So just use it like I do (new code in green):
$Host = "localhost";

$User = "USERNAME";

$Password = "PASSWORD";

$DBName = "DBNAME";

$TableName = "$select";

 

$Link = mysql_connect($Host,$User,$Password) or die("Error connectiong to the database: ".mysql_error()); //connect to the database

mysql_select_db($DBName'], $Link) or die ("Unable to select database: ".mysql_error()); // Select the desired database

 

$Query = "select * from $TableName";

$Result = mysql_query($Query,$Link) or die("Error when querying the database: ".mysql_error());

 

if(mysql_num_rows($Result) == 0) {

  print("No results to display.");

  print("$select");

} //checks to see if there's any data to display

 

while ($Row = mysql_fetch_array($Result)) {

  //print("<b><a href='newsdetail.php?detailno=$Row[newsID]'>$Row[headline]</a></b><p>");

  print("$Row[name]<p><br></p>");

}

 

mysql_close($Link); //close the connection

Try it like this and let us know if it works :)

PS - Notice the use of the mysql_error() function. It's really usefull when debugging PHP scripts that work with MySQL ;)

Edited by TCH-Raul
Posted

Andy and I played around with the code a bit and it is closer. The errors are gone and it lists the names of the interviews. There were several key parts of the code commented out causing some errors as well as not having the table you wanted to use in the code. Everything on the server is functioning correctly and php/MySQL are compiled correctly.

Posted

Hey everyone,

 

Deno again. Apologies for the late reply, I've been uber-busy lately. I just copied and pasted the code you sent me Raul, and now I get a parse error on line 38. Any ideas? :)

Posted

Hello again, Deno :)

 

Could you please copy and paste the code up to (and including) line 38 so I can see where the problem is? Oh, and please indicate which one is 38.

 

Thanks :dance:

Posted

Hi Raul,

 

Here's the code for my page interviews.php. The red highlight indicates that that is line 38. By the way, this page is part of include of page.php?select=. You see page.php is like the template of the site, when the user selects a link, it takes a link then it includes whatever page they clicked on, so in this case it's page.php?select=interviews.php. So on page.php?select=interviews.php, there's the one piece of code there that says include("$select");, where in this case, it's include("interviews.php"). Just to let you all know that. See what you can make of it. Uber-Thanks. :-)

 

 

 

<?php

$Host = "localhost";

$User = "starryc_Deno";

$Password = "****";

$DBName = "starryc_db1starryc";

$TableName = "$select";

 

$Link = mysql_connect($Host,$User,$Password) or die("Error connectiong to the database: ".mysql_error()); //connect to the database

mysql_select_db($DBName], $Link) or die ("Unable to select database: ".mysql_error()); // Select the desired database

 

$Query = "select * from $TableName";

$Result = mysql_query($Query,$Link) or die("Error when querying the database: ".mysql_error());

 

if(mysql_num_rows($Result) == 0) {

print("No results to display.");

print("$select");

}

 

while ($Row = mysql_fetch_array($Result)) {

/*//print("<b><a href="newsdetail.php?detailno=$Row[newsID]'">$Row[headline]</a></b><p>");*/

print("$Row[name]<p><br></p>");

}

 

mysql_close($Link); //close the connection

?>

Posted

I don't know if that's the problem but the only thing wront I see in the code is the ']' at the end of $DBName. I tried it on my computer and that's the only error I got.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...