Raised This Month: $ Target: $400
 0% 

[SQL / PHP] Query won't be executed


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 10-24-2013 , 05:22   [SQL / PHP] Query won't be executed
Reply With Quote #1

EDIT

Got it fixed.

PHP Code:
$query mysql_query("SELECT * FROM $sql_hat_table");

while(
$row mysql_fetch_assoc($query))
{        
    echo(
'<tr>');
    echo(
'    <td><img src="'$row['hat_picurl'] . '">');
    echo(
'    <td>'$row['hat_name'] .'</td>');
    echo(
'    <td>'$row['hat_desc'] .'</td>');
    echo(
'    <td>'$row['hat_price'].'</td>');
    echo(
'</tr>');


Hello everyone,

I'd try to make a table from some information I have in a SQL Table, but I always get this error :

Quote:
Warning: mysql_error() expects parameter 1 to be resource, string given in D:\Webserver\htdocs\battlefront\v1\shop_hats. php on line 165

Fatal error: Error in Query "Resource id #6". Message: in D:\Webserver\htdocs\battlefront\v1\shop_hats. php on line 165
I tried my Query on SQL Fiddle, there it's working :
http://puu.sh/4Y7rT.png

What is wrong with my code? It seems that "Resource id #6" is my query, but why?

PHP Code:
<?php

require_once("config.php");

$verbindung mysql_connect($sql_host$sql_user$sql_pass 
or die(
"Verbindung zur Datenbank konnte nicht hergestellt werden"); 

mysql_select_db($sql_database) or die ("Datenbank konnte nicht ausgewählt werden"); 

$q "SELECT * FROM sql_hat_table";

$r mysql_query($q) or trigger_error('Error in Query "'.$verbindung.'". Message: '.mysql_error($q),E_USER_ERROR);

for(
$i 1$a mysql_fetch_array($r); $i++) 
{
    echo(
'<tr>');
    echo(
'    <td><img src="'$a['hat_picurl'] . '">');
    echo(
'    <td>'$a['hat_name'] .'</td>');
    echo(
'    <td>'$a['hat_desc'] .'</td>');
    echo(
'    <td>'$a['hat_price'].'</td>');
    echo(
'</tr>');
}  

?>
__________________

Last edited by Kia; 10-24-2013 at 05:42.
Kia is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-24-2013 , 11:46   Re: [SQL / PHP] Query won't be executed
Reply With Quote #2

Not sure about the SQL, but the error you're seeing from PHP is being caused by this line:

PHP Code:
$r mysql_query($q) or trigger_error('Error in Query "'.$verbindung.'". Message: '.mysql_error($q),E_USER_ERROR); 
mysql_error wants $verbindung instead of $q

Edit: Whoops, missed the "Got it Fixed" thing in the first post.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-24-2013 at 11:46.
Powerlord is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 10-24-2013 , 12:04   Re: [SQL / PHP] Query won't be executed
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
Edit: Whoops, missed the "Got it Fixed" thing in the first post.
Thats why I put it at the top of my post.
__________________
Kia is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 10-24-2013 , 14:22   Re: [SQL / PHP] Query won't be executed
Reply With Quote #4

Quote:
Originally Posted by Powerlord View Post
mysql_error wants $verbindung instead of $q
Actually, it wants $r instead. $q is just a string
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 10-24-2013 , 20:20   Re: [SQL / PHP] Query won't be executed
Reply With Quote #5

Just a comment...
__________________

Last edited by Neeeeeeeeeel.-; 10-24-2013 at 20:21.
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-25-2013 , 11:54   Re: [SQL / PHP] Query won't be executed
Reply With Quote #6

Quote:
Originally Posted by YamiKaitou View Post
Actually, it wants $r instead. $q is just a string
mysql_error wants the database connection, which is $verbindung. The entire statement should have been

PHP Code:
$r mysql_query($q) or trigger_error('Error in Query "'.$q.'". Message: '.mysql_error($verbindung),E_USER_ERROR); 
Quote:
Originally Posted by Neeeeeeeeeel.- View Post
Just a comment...
It's only been deprecated since 5.5.0? PHP.net has been telling people to use PDO instead for years... since PHP 5.1.0 came out in 2005 at the very least.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-25-2013 at 11:57.
Powerlord is offline
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 10-25-2013 , 16:23   Re: [SQL / PHP] Query won't be executed
Reply With Quote #7

Quote:
Originally Posted by Powerlord View Post
mysql_error wants the database connection, which is $verbindung. The entire statement should have been

PHP Code:
$r mysql_query($q) or trigger_error('Error in Query "'.$q.'". Message: '.mysql_error($verbindung),E_USER_ERROR); 
It's only been deprecated since 5.5.0? PHP.net has been telling people to use PDO instead for years... since PHP 5.1.0 came out in 2005 at the very least.
idk I use php since 2011..
__________________
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 10-25-2013 , 16:26   AW: Re: [SQL / PHP] Query won't be executed
Reply With Quote #8

Quote:
Originally Posted by Neeeeeeeeeel.- View Post
idk I use php since 2011..
And I use it for a few days.
__________________
Kia is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:58.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode