Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-08-2004, 03:01 PM mysql help.
Chris_krasnichu's Avatar
Ultra Talker

Posts: 331
Location: Ontario, Canada
Trades: 0
Hey,
I'm having a bit of trouble with this script.
Can anybody help me out?
PHP Code:
<?php
/////////////////
// Connection strings
/////////////////
$host "localhost";
$user "fake";
$password "fake";
$database "fake";


 
mysql_connect($host$user$password);
  
mysql_select_db($database);


function 
checkstock($card$string2)
{
 
$query "SELECT cardstock FROM cards WHERE cardid = $card";
 
$result mysql_query($query);
  if (
$result 0) {
  echo 
"$result";
  
$string2 true;
  } elseif (
$result == 0) {
  echo 
"<font color=\"red\"><b>Out of Stock</b></font>";
  
$string2 false;
  } 
}
$get $_GET['x'];
if (
$get "test") {
$fake "";
checkstock("testcard"$fake);
echo 
"$fake";
} else {}

?>
Thanks in advance

Chris
__________________
Name: Chris Krasnichuk
Email Address:
Please login or register to view this content. Registration is FREE
Chris_krasnichu is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-08-2004, 03:10 PM
WaHoOoO!'s Avatar
Mentally Unstable Tugboat Captain

Posts: 797
Name: Chad
Location: /usr/bin/perl
Trades: 0
What kind of errors are you getting?
__________________
He's baaaaaaaack....
WaHoOoO! is offline
Reply With Quote
View Public Profile Visit WaHoOoO!'s homepage!
 
Old 04-08-2004, 03:55 PM
Chris_krasnichu's Avatar
Ultra Talker

Posts: 331
Location: Ontario, Canada
Trades: 0
Well. it's just showing out of stock (witch is what it does when theres a value of 0 in the database)
It's ether in the database or the script.
Heres a demo: www.dragongames.ca/dbconnect.php?x=test
it should show 1 but it doesn't

Chris
__________________
Name: Chris Krasnichuk
Email Address:
Please login or register to view this content. Registration is FREE
Chris_krasnichu is offline
Reply With Quote
View Public Profile
 
Old 04-08-2004, 03:55 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Your using $result as if it is an actual number. mysql_query is just returing a result set, you have to use other functions to get that data. To get just the number, you can try:

PHP Code:
$query "SELECT cardstock FROM cards WHERE cardid = $card";
$result mysql_query($query); 
$result mysql_fetch_row($result); // fetch the row
$result $result[0]; // which will retrun a 1 element array, so just grab it 
I think that should work. I've got a DB class that does most of my work for me so I'm a little rusty

// edit, you might have to use more the one variable for query and result Try this if the first doesn't work:
PHP Code:
$query "SELECT cardstock FROM cards WHERE cardid = $card";
$result mysql_query($query); 
$cardstock mysql_fetch_row($result); // fetch the row
$cardstock $cardstock[0]; // which will retrun a 1 element array, so just grab it 
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE


Last edited by Christopher; 04-08-2004 at 04:02 PM..
Christopher is offline
Reply With Quote
View Public Profile
 
Old 04-08-2004, 04:07 PM
Chris_krasnichu's Avatar
Ultra Talker

Posts: 331
Location: Ontario, Canada
Trades: 0
Quote:
Originally Posted by Chroder
Your using $result as if it is an actual number. mysql_query is just returing a result set, you have to use other functions to get that data. To get just the number, you can try:

PHP Code:
$query "SELECT cardstock FROM cards WHERE cardid = $card";
$result mysql_query($query); 
$result mysql_fetch_row($result); // fetch the row
$result $result[0]; // which will retrun a 1 element array, so just grab it 
I think that should work. I've got a DB class that does most of my work for me so I'm a little rusty

// edit, you might have to use more the one variable for query and result Try this if the first doesn't work:
PHP Code:
$query "SELECT cardstock FROM cards WHERE cardid = $card";
$result mysql_query($query); 
$cardstock mysql_fetch_row($result); // fetch the row
$cardstock $cardstock[0]; // which will retrun a 1 element array, so just grab it 

It still doesn't work.
the error I'm getting is this: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/draconum/public_html/dbconnect.php on line 19


Chris
__________________
Name: Chris Krasnichuk
Email Address:
Please login or register to view this content. Registration is FREE
Chris_krasnichu is offline
Reply With Quote
View Public Profile
 
Old 04-08-2004, 04:22 PM
david's Avatar
King Spam Talker

Posts: 1,314
Location: Glasgow, UK
Trades: 0
It may make no difference, but try this:
PHP Code:
$query "SELECT cardstock FROM cards WHERE cardid = '".$card"'"
__________________

Please login or register to view this content. Registration is FREE
- Everything a webmaster needs - for free

Please login or register to view this content. Registration is FREE
- Free web hosts reviewed and rated

Please login or register to view this content. Registration is FREE
- Impartial hosting directory - Add your host today for FREE
david is offline
Reply With Quote
View Public Profile
 
Old 04-08-2004, 04:25 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
See if there's an error:
PHP Code:
$result mysql_query($query) or die('Error: ' mysql_error()); 
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 04-08-2004, 04:29 PM
Chris_krasnichu's Avatar
Ultra Talker

Posts: 331
Location: Ontario, Canada
Trades: 0
Quote:
Originally Posted by david
It may make no difference, but try this:
PHP Code:
$query "SELECT cardstock FROM cards WHERE cardid = '".$card"'"
I think that did it.
Thanks alot both of you.

Chris
__________________
Name: Chris Krasnichuk
Email Address:
Please login or register to view this content. Registration is FREE
Chris_krasnichu is offline
Reply With Quote
View Public Profile
 
Old 04-08-2004, 04:32 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
So cardid was a string all along?
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 04-08-2004, 04:36 PM
Chris_krasnichu's Avatar
Ultra Talker

Posts: 331
Location: Ontario, Canada
Trades: 0
yep and the script works like a charm.

Chris
__________________
Name: Chris Krasnichuk
Email Address:
Please login or register to view this content. Registration is FREE
Chris_krasnichu is offline
Reply With Quote
View Public Profile
 
Old 06-14-2007, 01:13 PM Re: mysql help.
Skilled Talker

Latest Blog Post:
My book update
Posts: 97
Name: Eric
Location: Las Vegas
Trades: 0
If you get used to doing this
$query
= "SELECT cardstock FROM cards WHERE cardid = '{$card}'";
it is good practice because then you can use arrays in your query!
__________________

Please login or register to view this content. Registration is FREE

Eric - M
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
peanutpad is offline
Reply With Quote
View Public Profile Visit peanutpad's homepage!
 
Reply     « Reply to mysql help.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.69994 seconds with 12 queries