Deno Posted November 25, 2003 Posted November 25, 2003 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. 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 Quote
borfast Posted November 25, 2003 Posted November 25, 2003 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... 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. Quote
Deno Posted November 26, 2003 Author Posted November 26, 2003 Hey thanks for replying Raul! And yes, I have sent you a ticket already. Quote
Deno Posted November 27, 2003 Author Posted November 27, 2003 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. Quote
borfast Posted November 27, 2003 Posted November 27, 2003 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. Quote
TCH-Andy Posted November 27, 2003 Posted November 27, 2003 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 Quote
borfast Posted November 27, 2003 Posted November 27, 2003 (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 November 27, 2003 by TCH-Raul Quote
TCH-Andy Posted November 27, 2003 Posted November 27, 2003 Raul, All good, and valid points Andy Quote
TCH-Rick Posted November 27, 2003 Posted November 27, 2003 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. Quote
Deno Posted November 27, 2003 Author Posted November 27, 2003 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 Quote
borfast Posted November 27, 2003 Posted November 27, 2003 (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 November 27, 2003 by TCH-Raul Quote
TCH-Rick Posted November 27, 2003 Posted November 27, 2003 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. Quote
Deno Posted December 3, 2003 Author Posted December 3, 2003 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? Quote
borfast Posted December 3, 2003 Posted December 3, 2003 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 Quote
Deno Posted December 3, 2003 Author Posted December 3, 2003 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 ?> Quote
TCH-Dick Posted December 3, 2003 Posted December 3, 2003 mysql_select_db($DBName], $Link) Remove the bracket ] Quote
borfast Posted December 4, 2003 Posted December 4, 2003 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. Quote
Deno Posted December 4, 2003 Author Posted December 4, 2003 Hey guys, I found my error and I got the script working! Thanks guys, appreciate it a lot! ;-) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.