Webmaster Key - Discussion Forums


Welcome, Guest. Please login or register.
Did you miss your activation email?
February 09, 2012, 09:17:23 PM

Login with username, password and session length
Welceome to Forums!

Important information for guests and new members:

In order to understand the full benefits of becoming an active member of this forum, please review the following information on guest and new member restrictions. These forum changes have been prompted by an overwhelming and unreasonable amount of bot postings and incoherent guest spam messages. We wish to prevent these events from happening in the future and make our community a more comfortable place for all of our members.

For guests:

Guests are not allowed to open new topics, polls, or posts attachments.
If you wish to open up new discussions on this forum, we encourage you to register.

For new members:

New members with less than five posts are not allowed to modify additional profile information such as avatars, contact information, biographies, and signatures. However, new members are encouraged to post their own topics or reply to topics initiated by other members. Become active on the forums and 5 posts should be an easy task!

We are a diverse community with members from all over the world. We encourage new ideas and interesting conversation. Do not be afraid to post webmaster/computer-related questions or problems, as our active members are always willing to help when they are able. Interested? Join us.

+ Webmaster Key Forums
|-+ Webmaster Corner
| |-+ Site Design and Web Authoring
| | |-+ Coding Talk
| | | |-+ php if statement
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Stumble Upon! Digg It! del.icio.us! Add to Technorati! ReddIt!  Send this topic Print
Author Topic: php if statement  (Read 3212 times)
stu
Key Keeper
Member
**
Posts: 83



WWW
« on: November 27, 2008, 02:47:28 AM »

Hi all

i have an if statement depending on results from the database. The if statments fine but its not reading the the imput right. The results is always out of stock although there is stock.

heres my code

<?php
$con = mysql_connect("localhost","user","pass123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("cart", $con);

$result = mysql_query("SELECT * FROM tbl_product
WHERE pd_id='22'");

if ($pd_qty > 0) {

// if we still have this product in stock
// show the 'Add to cart' button

?>
<form method="post" action="http://www.mydomain" target="_blank">
<select name="size ">
<option>Please select</option>
<option>small</option>
<option>large</option>
</select>

<input type="hidden" name="Title" value="Some cloathing item">
<input type="hidden" name="SerialNum" value="GAR006">
<input type="hidden" name="Price" value="27.99">

  <input name="cmd" type="hidden" id="cmd" value="1">
  <input type="submit" name="Submit" value="Add To Cart">
</form>
<?php
} else {
   echo 'Out Of Stock';
}
?>


if i delete everything above the if statement and add this $pd_qty = '22'; everything works fine

any body help with this please

thanks

stuart
Report to moderator   Logged

Andy
Administrator
Veteran
*****
Posts: 5 752



« Reply #1 on: November 27, 2008, 06:43:37 AM »

Hi

You need another line of code before the if statement to extract a value for $pd_qty

Check out http://uk.php.net/manual/en/function.msql-result.php See the recommended functions to use.
Report to moderator   Logged

stu
Key Keeper
Member
**
Posts: 83



WWW
« Reply #2 on: November 27, 2008, 10:32:56 AM »

hi

I have a mysql result line in my code tho

$result = mysql_query("SELECT * FROM tbl_product
WHERE pd_id='22'");

so i dont really understand if i add another line in i get an error message. Sorry i'm new to php

thanks

stuart
Report to moderator   Logged

stu
Key Keeper
Member
**
Posts: 83



WWW
« Reply #3 on: November 27, 2008, 12:41:51 PM »

Hi

I've really tried and feel like i'm running round in circuls now with things i've already tried.

I've tried adding a second result into the code like so

<?php
$con = mysql_connect("localhost","lush_lush","pass123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("lush_plaincart", $con);

$result = mysql_query("SELECT pd_qty * FROM tbl_product
WHERE pd_id='22'");

string mysql_result ( resource $result , int $row [ $pd_qty ] );


if ($result > 0) {


// if we still have this product in stock
// show the 'Add to cart' button

?>
<form method="post" action="http://www.lush-lingerie.com/run/FPHPSC/ShoppingCart.php" target="_blank">
<select name="size ">
<option>Please select</option>
<option>small</option>
<option>large</option>
</select>

<input type="hidden" name="Title" value="Some cloathing item">
<input type="hidden" name="SerialNum" value="GAR006">
<input type="hidden" name="Price" value="27.99">

  <input name="cmd" type="hidden" id="cmd" value="1">
  <input type="submit" name="Submit" value="Add To Cart">
</form>
<?php
} else {
   echo 'Out Of Stock';
}
?>

<?php


I really dont get this at all

please help

thanks

stuart
Report to moderator   Logged

Andy
Administrator
Veteran
*****
Posts: 5 752



« Reply #4 on: November 27, 2008, 05:06:11 PM »

OK, here is the way I normally extract the row data:

Code:
<?php
if ($row msql_fetch_object($result)) {
  
$pd_qty $row->pd_qty;


}
?>


or another way:

Code:
<?php
if ($row msql_fetch_row($result)) {
  
$pd_qty $row['pd_qty'];


}
?>


This assumes that you have a table called 'pd_qty'

 Smiley

Report to moderator   Logged

stu
Key Keeper
Member
**
Posts: 83



WWW
« Reply #5 on: November 28, 2008, 01:40:14 PM »

Hi

Thanks for your help. I dont know if I'm being thick but I really just can not do this. I can select itmes from the database arrange them how i want but i just can not get this what so ever.

What i need to do is

<?php
   
$con = mysql_connect("localhost","my user name","sum pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my database", $con);


// this is the select command
// select product quanty (pd_qty) from the table (tbl_product)
//where product quanty has a product id (pd_id) of 22


$result = mysql_query("SELECT pd_qty * FROM tbl_product
WHERE pd_id='22'");


//Now this is were i get lost

// if the pd_qty is grater than zero

if ($pd_qty > 0) {

// if we still have this product in stock
// show the 'Add to cart' button


?>

<form action ........>
</form>

<?php
} else {
   echo 'Out Of Stock';
}
?>



I really can not do this. i have tried so hard but no matter what i do it doesnt work. I'm new to php and I am struggling. I understand that the if statement is one of the basics. I can do the if statement on its own but not when its being incorparated like this.

Please help

thanks

stuart


Report to moderator   Logged

Pages: [1] Go Up Stumble Upon! Digg It! del.icio.us! Add to Technorati! ReddIt!  Send this topic Print 
+ Webmaster Key Forums
|-+ Webmaster Corner
| |-+ Site Design and Web Authoring
| | |-+ Coding Talk
| | | |-+ php if statement

Jump to:  
« previous next »


Our Partners
RelmaxTOP Ranking System Web Hosting RelmaxTOP Ranking System
Staff Sites
12Noon[12Noon Gallery] Andy[Urgentclick]
Tamuril[Tamuril's Digital Art Exhibit] Sensovision
Powered by MySQL Powered by PHP We are hosted by Relmax Inc. |Our Privacy Policy | Sitemap
Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC
Forum design by Tamuril © 2005.
Valid XHTML 1.0! Valid CSS!