latino.ad7 Posted February 14, 2010 Share Posted February 14, 2010 I wrote some PHP/MySQL code and it works fine on my hard-drive throu WebServ. Yet when I place it on the internet, on the website, it generates an error. Here is PHP code (after successfully connecting to the database): 165 $q = ("Select id, filename, name, author, bin from objects where category = 'category1'"); 166 $r = mysql_query ($q, $link); 167 168 while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) { 169 $arrid[$row['id']] = $row['id']; 170 $arrfilename[$row['id']] = $row['filename']; 171 $arrname[$row['id']] = $row['name']; 172 $arrauthor[$row['id']] = $row['author']; 173 $arrbin[$row['id']] = $row['bin']; 174} 175 $num = mysql_num_rows($r); The error messages are: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in .../public_html/category.php on line 168 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in .../public_html/category.php on line 175 Link to comment https://forums.phpfreaks.com/topic/192032-website-vs-webserv-php-code-issue/ Share on other sites More sharing options...
jl5501 Posted February 14, 2010 Share Posted February 14, 2010 see what this tells you $q = "Select id, filename, name, author, bin from objects where category = 'category1'"; $r = mysql_query ($q, $link) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/192032-website-vs-webserv-php-code-issue/#findComment-1012097 Share on other sites More sharing options...
latino.ad7 Posted February 14, 2010 Author Share Posted February 14, 2010 Ehem, no... I don't get it. What I tried is I put: echo "$r -- $q"; to check. On the internet it seems empty("--"), while throu WebServ it seems fine: "Select id, filename, name, author, bin from objects where category = 'category1' -- Resource id #58 " Link to comment https://forums.phpfreaks.com/topic/192032-website-vs-webserv-php-code-issue/#findComment-1012098 Share on other sites More sharing options...
latino.ad7 Posted February 14, 2010 Author Share Posted February 14, 2010 Hm, I'm actually using a link to get a variable: Link: whatever/page.php?val=whatever&cat=Category if ($cat == "Category") { $q = ("Select id, filename, name, author, bin from objects where category = '".$val."'"); } elseif ($cat == "Author") { $q = ("Select id, filename, name, author, bin from objects where author2 = '".$val."'"); } Link to comment https://forums.phpfreaks.com/topic/192032-website-vs-webserv-php-code-issue/#findComment-1012099 Share on other sites More sharing options...
jl5501 Posted February 14, 2010 Share Posted February 14, 2010 in that case you will need this $cat = $_GET['cat']; if ($cat == "Category") { .... Link to comment https://forums.phpfreaks.com/topic/192032-website-vs-webserv-php-code-issue/#findComment-1012103 Share on other sites More sharing options...
latino.ad7 Posted February 14, 2010 Author Share Posted February 14, 2010 Yes, this is the problem. When I just plugged: $cat = "Category"; $val = "whatever"; it works fine. Why doesn't it work? Can't I use a link to send variables using GET method? Link to comment https://forums.phpfreaks.com/topic/192032-website-vs-webserv-php-code-issue/#findComment-1012104 Share on other sites More sharing options...
latino.ad7 Posted February 14, 2010 Author Share Posted February 14, 2010 in that case you will need this $cat = $_GET['cat']; if ($cat == "Category") { .... Yay! Works like a charm! Many thanks. Solved. Link to comment https://forums.phpfreaks.com/topic/192032-website-vs-webserv-php-code-issue/#findComment-1012105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.