Jump to content

change enum status 'Y' or 'N' to show/hide product


vinpkl

Recommended Posts

hi all

 

i have a input type button name="status" which on click change the enum status of the field in database to "Y" or "N".

If the status is "Y" the product is showed to public but if the status is "N" then the product gets hide for public.

But the problem i m facing is that i m not able to write the value "hide" or "show" on input type button because the value i have taken is the product_id. If i change the value to "show" or hide then it doesnt work.

 

The code i m using is

if(isset($_REQUEST['status']))
{
$pid=$_REQUEST['status'];
echo $pid;
$qry="select * from product_table where product_id=$pid";
$result=mysql_query($qry);
$row=mysql_fetch_array($result);
if($row['status']=='Y')
{
$updtqry="update product_table set status='N' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}
else
{
$updtqry="update product_table set status='Y' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}

}	

echo "<form name='status_update' action='manage_products.php' method='post'>";
		echo "<td valign=top>". "<input type ='submit' name='status'". "value=" . $row['product_id'];?> <?php if($row['status']=='Y') echo 'checked';?> <?php echo "</td>";
		echo "</form>";

 

I want to know how can i do exactly the same with two image as buttons.

one image button name=hide and other image button name=show.

When hide image button is click then the product will hide and when the show image button is click the product will

show.

 

I tried this but this doesnt worked. please help

echo "<td valign=top>";
		if ($row['status']==Y) 
		{ 	
		echo "<a href='manage_products.php?=" . $row['product_id'] . "'>" . "<img src='../images/hide_icon.gif' name='status' id='status'>" . "</a>";
		 } 

		 else 
		 {
		echo "<a href='manage_products.php?status" . $row['product_id'] . "&" .$row['status']=Y. "'>" . "<img src='../images/show_icon.gif' name='status' id=status'>" . "</a>";
		 }	

		echo "</td>";

Link to comment
Share on other sites

try using a hidden field to hold the value of the product and set a variable to display the value for the submit button, like this:

 


if(isset($_REQUEST['status']))
{
$pid=$_REQUEST['status'];
echo $pid;
$qry="select * from product_table where product_id=$pid";
$result=mysql_query($qry);
$row=mysql_fetch_array($result);
if($row['status']=='Y')
{
$updtqry="update product_table set status='N' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}
else
{
$updtqry="update product_table set status='Y' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}

             if($row['status']=='Y') {
                 $status = "Hide";
             } else {
                 $status = "Show";
             }
}	

echo '<form name="status_update" action="manage_products.php" method="post">';
echo '<td valign="top"><input type="submit" value="'.$status.'" />';
echo '<input type="hidden" name="status" value="'.$row['product_id'].'" />;
echo '</td>';
echo '</form>';

Link to comment
Share on other sites

try using a hidden field to hold the value of the product and set a variable to display the value for the submit button, like this:

 


if(isset($_REQUEST['status']))
{
$pid=$_REQUEST['status'];
echo $pid;
$qry="select * from product_table where product_id=$pid";
$result=mysql_query($qry);
$row=mysql_fetch_array($result);
if($row['status']=='Y')
{
$updtqry="update product_table set status='N' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}
else
{
$updtqry="update product_table set status='Y' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}

             if($row['status']=='Y') {
                 $status = "Hide";
             } else {
                 $status = "Show";
             }
}	

echo '<form name="status_update" action="manage_products.php" method="post">';
echo '<td valign="top"><input type="submit" value="'.$status.'" />';
echo '<input type="hidden" name="status" value="'.$row['product_id'].'" />;
echo '</td>';
echo '</form>';

 

hi

 

i tried your code but still it doesnt show the value "show" or "hide" on it. it shows blank button. neither any error is coming.

 

vineet

Link to comment
Share on other sites

ahh yes sorry, my fault forgot to initialise the variable:

 

try this:

 

$status="Hide";

if(isset($_REQUEST['status']))
{

 

and also are you only displaying the submit button when there is a product?

 

cause what you have at the moment is wont work because the form is outside of the IF statement - ie there will be no product id in the status field

Link to comment
Share on other sites

ahh yes sorry, my fault forgot to initialise the variable:

 

try this:

 

$status="Hide";

if(isset($_REQUEST['status']))
{

 

hi

 

Now its showing everytime "Hide". Its not toggling with "Hide" and "Show".

Its functioning properly means on first click its hiding the product and on second click its showing the product.

But its not changing its status from "hide" to "show". everytime its showing on it "Hide".

 

vineet

Link to comment
Share on other sites

read my edit above

 

hi

 

this is what i have added that u said

 

$status="Hide";

if(isset($_REQUEST['status']))
{
$pid=$_REQUEST['status'];
echo $pid;
$qry="select * from product_table where product_id=$pid";
$result=mysql_query($qry);
$row=mysql_fetch_array($result);
if($row['status']=='Y')
{
$updtqry="update product_table set status='N' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}
else
{
$updtqry="update product_table set status='Y' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}

             if($row['status']=='Y') {
                 $status = "Hide";
             } else {
                 $status = "Show";
             }

}	

echo '<form name="status_update" action="manage_products.php" method="post">';
		echo '<td valign="top"><input type="submit" value="'.$status.'" />';
		echo '<input type="hidden" name="status" value="'.$row['product_id'].'" />';
		echo '</td>';
		echo '</form>';

 

 

 

Link to comment
Share on other sites

Yeah, sorry i meant the second part:

 

and also are you only displaying the submit button when there is a product?

 

cause what you have at the moment is wont work because the form is outside of the IF statement - ie there will be no product id in the status field

 

does this page receive $_REQUEST['status'] when it first loads?

 

or only once the user clicks the hide/show button?

Link to comment
Share on other sites

Yeah, sorry i meant the second part:

 

and also are you only displaying the submit button when there is a product?

 

cause what you have at the moment is wont work because the form is outside of the IF statement - ie there will be no product id in the status field

 

does this page receive $_REQUEST['status'] when it first loads?

 

or only once the user clicks the hide/show button?

 

Hi

 

i tell you everything in detail what is happening.

 

In the database i have status field with enum datatype value "Y" and "N" and default set to "Y".

 

So when the page in which "this submit button" is inserted will display button value as "Hide".

 

When i click the "Hide button" then on top of the page it echos "7" that is the product_id.

 

but it doesnt change to "show".

 

vineet

Link to comment
Share on other sites

change this:

 

if($row['status']=='Y') {

                $status = "Hide";

            } else {

                $status = "Show";

            }

 

 

to this:

 

if($row['status']=='Y') {

                $status = "Show";

            } else {

                $status = "Hide";

            }

 

and see if that helps

Link to comment
Share on other sites

change this:

 

if($row['status']=='Y') {

                 $status = "Hide";

             } else {

                 $status = "Show";

             }

 

 

to this:

 

if($row['status']=='Y') {

                 $status = "Show";

             } else {

                 $status = "Hide";

             }

 

and see if that helps

 

hi

 

which this change if i have to hide the product then i will have to press the hide button 2 times.

It will change the Enum status to "N" and hide on second time.

 

But still it doesnt change button status value to "show".

 

vineet

Link to comment
Share on other sites

so thats not the problem then - which brings me back to the below:

 

 

does this page receive $_REQUEST['status'] when it first loads?

 

or only once the user clicks the hide/show button?

 

 

i think that you will find that the problem is that when the page loads it does not get a product from the database and therefore when you click the hide button the database is trying to update the row with product_id="" and as this doesn't exist the value of status will never equal 'Y' and the button will always say "hide"

 

 

Link to comment
Share on other sites

so thats not the problem then - which brings me back to the below:

 

 

does this page receive $_REQUEST['status'] when it first loads?

 

or only once the user clicks the hide/show button?

 

 

i think that you will find that the problem is that when the page loads it does not get a product from the database and therefore when you click the hide button the database is trying to update the row with product_id="" and as this doesn't exist the value of status will never equal 'Y' and the button will always say "hide"

 

 

 

HI

 

To make myself more clear.

I have a dropdown of dealer list on my page from where i select the dealer and This is all i receive on selecting the dealer and not clicking the hide/show button.

product image, product id, description, price etc everything is coming from database and showed on the page.

 


if(isset($_REQUEST['dealer_id']))
{
$dealer_id=$_REQUEST['dealer_id'];
$qry="select * from product_table where dealer_id=$dealer_id";
//echo $qry;
$result = mysql_query($qry);

if(mysql_num_rows($result)>0)
{
	while($row=mysql_fetch_array($result))
	{
		echo "<tr>";
		echo "<td valign=top>". $row['product_id'] . "</td>";
		echo "<td valign=top>". $row['product_name'] . "</td>";
		echo "<td valign=top>". $row['description'] . "</td>";
		echo "<td valign=top>". $row['cutout_price'] . "</td>";
		echo "<td valign=top>". $row['price'] . "</td>";
		echo "<td valign=top>". "<img border=1 height=115 width=92 src='uploads/" . $row['image'] . "'/>" . "</td>";
		echo "<td valign=top>". $row['shipping_cost'] . "</td>";
		echo "<td valign=top>". $row['shipping_detail'] . "</td>";
		echo "<td valign=top>". $row['warranty'] . "</td>";


		echo '<form name="status_update" action="manage_products.php" method="post">';
		echo '<td valign="top"><input type="submit" value="'.$status.'" />';
		echo '<input type="hidden" name="status" value="'.$row['product_id'].'" />';
		echo '</td>';
		echo '</form>';


		echo "<td valign=top>"."<a href='modify_products.php?id=" . $row['product_id'] . "'/>  Modify </a>" . "</td>";
		echo "</tr>";	
	}
}
}	

Link to comment
Share on other sites

OK sorry that has just confused me!

 

Is that all of the code on your page?

 

If not can you post all of the code so i can see where the below part fits in.

 

$status="Hide";

if(isset($_REQUEST['status']))
{
$pid=$_REQUEST['status'];
echo $pid;
$qry="select * from product_table where product_id=$pid";
$result=mysql_query($qry);
$row=mysql_fetch_array($result);
if($row['status']=='Y')
{
$updtqry="update product_table set status='N' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}
else
{
$updtqry="update product_table set status='Y' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}

             if($row['status']=='Y') {
                 $status = "Hide";
             } else {
                 $status = "Show";
             }

}	

Link to comment
Share on other sites

OK sorry that has just confused me!

 

Is that all of the code on your page?

 

If not can you post all of the code so i can see where the below part fits in.

 

$status="Hide";

if(isset($_REQUEST['status']))
{
$pid=$_REQUEST['status'];
echo $pid;
$qry="select * from product_table where product_id=$pid";
$result=mysql_query($qry);
$row=mysql_fetch_array($result);
if($row['status']=='Y')
{
$updtqry="update product_table set status='N' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}
else
{
$updtqry="update product_table set status='Y' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}

             if($row['status']=='Y') {
                 $status = "Hide";
             } else {
                 $status = "Show";
             }

}	

 

hi

 

this is the code that is inserted before the <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  starts

$status="Hide";

if(isset($_REQUEST['status']))
{
$pid=$_REQUEST['status'];
echo $pid;
$qry="select * from product_table where product_id=$pid";
$result=mysql_query($qry);
$row=mysql_fetch_array($result);
if($row['status']=='Y')
{
$updtqry="update product_table set status='N' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}
else
{
$updtqry="update product_table set status='Y' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}

             if($row['status']=='Y') {
                 $status = "Hide";
             } else {
                 $status = "Show";
             }


}	

 

and the other code is in my <table> tag

<table width="901" cellpadding="6" cellspacing="0" class="bordr">
      <tr style="background-color:#CCCCCC; height:25px">
        <td>Product ID </td>
        <td>Product Name </td>
        <td>Description </td>
	<td>Cutout Price</td>
	<td>Price</td>
	<td>Product Image</td>
	<td>Shipping cost</td>
	<td>Shipping detail</td>
	<td>warranty</td>
                          <td>Show/hide</td>
	<td>Action</td>
      </tr>
<?php

if(isset($_REQUEST['dealer_id']))
{
$dealer_id=$_REQUEST['dealer_id'];
$qry="select * from product_table where dealer_id=$dealer_id";
//echo $qry;
$result = mysql_query($qry);

if(mysql_num_rows($result)>0)
{
	while($row=mysql_fetch_array($result))
	{
		echo "<tr>";
		echo "<td valign=top>". $row['product_id'] . "</td>";
		echo "<td valign=top>". $row['product_name'] . "</td>";
		echo "<td valign=top>". $row['description'] . "</td>";
		echo "<td valign=top>". $row['cutout_price'] . "</td>";
		echo "<td valign=top>". $row['price'] . "</td>";
		echo "<td valign=top>". "<img border=1 height=115 width=92 src='uploads/" . $row['image'] . "'/>" . "</td>";
		echo "<td valign=top>". $row['shipping_cost'] . "</td>";
		echo "<td valign=top>". $row['shipping_detail'] . "</td>";
		echo "<td valign=top>". $row['warranty'] . "</td>";


		echo '<form name="status_update" action="manage_products.php" method="post">';
		echo '<td valign="top"><input type="submit" value="'.$status.'" />';
		echo '<input type="hidden" name="status" value="'.$row['product_id'].'" />';
		echo '</td>';
		echo '</form>';

		echo "<td valign=top>"."<a href='modify_products.php?id=" . $row['product_id'] . "'/>  Modify </a>" . "</td>";
		echo "</tr>";	
	}
}
}	

Link to comment
Share on other sites

OK that makes more sense  :)

 

try the below

 


if(isset($_REQUEST['status']))
{
$pid=$_REQUEST['status'];
echo $pid;
$qry="select * from product_table where product_id=$pid";
$result=mysql_query($qry);
$row=mysql_fetch_array($result);
if($row['status']=='Y')
{
$updtqry="update product_table set status='N' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}
else
{
$updtqry="update product_table set status='Y' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}
}	

 

<table width="901" cellpadding="6" cellspacing="0" class="bordr">
      <tr style="background-color:#CCCCCC; height:25px">
        <td>Product ID </td>
        <td>Product Name </td>
        <td>Description </td>
	<td>Cutout Price</td>
	<td>Price</td>
	<td>Product Image</td>
	<td>Shipping cost</td>
	<td>Shipping detail</td>
	<td>warranty</td>
                          <td>Show/hide</td>
	<td>Action</td>
      </tr>
<?php

if(isset($_REQUEST['dealer_id']))
{
$dealer_id=$_REQUEST['dealer_id'];
$qry="select * from product_table where dealer_id=$dealer_id";
//echo $qry;
$result = mysql_query($qry);

if(mysql_num_rows($result)>0)
{
	while($row=mysql_fetch_array($result))
	{
		echo "<tr>";
		echo "<td valign=top>". $row['product_id'] . "</td>";
		echo "<td valign=top>". $row['product_name'] . "</td>";
		echo "<td valign=top>". $row['description'] . "</td>";
		echo "<td valign=top>". $row['cutout_price'] . "</td>";
		echo "<td valign=top>". $row['price'] . "</td>";
		echo "<td valign=top>". "<img border=1 height=115 width=92 src='uploads/" . $row['image'] . "'/>" . "</td>";
		echo "<td valign=top>". $row['shipping_cost'] . "</td>";
		echo "<td valign=top>". $row['shipping_detail'] . "</td>";
		echo "<td valign=top>". $row['warranty'] . "</td>";


if($row['status']=='Y') {
$status = "Hide";
} else {
$status = "Show";
}			

		echo '<form name="status_update" action="manage_products.php" method="post">';
		echo '<td valign="top"><input type="submit" value="'.$status.'" />';
		echo '<input type="hidden" name="status" value="'.$row['product_id'].'" />';
		echo '</td>';
		echo '</form>';

		echo "<td valign=top>"."<a href='modify_products.php?id=" . $row['product_id'] . "'/>  Modify </a>" . "</td>";
		echo "</tr>";	
	}
}
}	

Link to comment
Share on other sites

hi

 

thanks thanks a lot. works perfect as needed.

 

vineet

 

 

OK that makes more sense  :)

 

try the below

 


if(isset($_REQUEST['status']))
{
$pid=$_REQUEST['status'];
echo $pid;
$qry="select * from product_table where product_id=$pid";
$result=mysql_query($qry);
$row=mysql_fetch_array($result);
if($row['status']=='Y')
{
$updtqry="update product_table set status='N' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}
else
{
$updtqry="update product_table set status='Y' where product_id=$pid";
mysql_query($updtqry,$conn) or die("Not updated");
}
}	

 

<table width="901" cellpadding="6" cellspacing="0" class="bordr">
      <tr style="background-color:#CCCCCC; height:25px">
        <td>Product ID </td>
        <td>Product Name </td>
        <td>Description </td>
	<td>Cutout Price</td>
	<td>Price</td>
	<td>Product Image</td>
	<td>Shipping cost</td>
	<td>Shipping detail</td>
	<td>warranty</td>
                          <td>Show/hide</td>
	<td>Action</td>
      </tr>
<?php

if(isset($_REQUEST['dealer_id']))
{
$dealer_id=$_REQUEST['dealer_id'];
$qry="select * from product_table where dealer_id=$dealer_id";
//echo $qry;
$result = mysql_query($qry);

if(mysql_num_rows($result)>0)
{
	while($row=mysql_fetch_array($result))
	{
		echo "<tr>";
		echo "<td valign=top>". $row['product_id'] . "</td>";
		echo "<td valign=top>". $row['product_name'] . "</td>";
		echo "<td valign=top>". $row['description'] . "</td>";
		echo "<td valign=top>". $row['cutout_price'] . "</td>";
		echo "<td valign=top>". $row['price'] . "</td>";
		echo "<td valign=top>". "<img border=1 height=115 width=92 src='uploads/" . $row['image'] . "'/>" . "</td>";
		echo "<td valign=top>". $row['shipping_cost'] . "</td>";
		echo "<td valign=top>". $row['shipping_detail'] . "</td>";
		echo "<td valign=top>". $row['warranty'] . "</td>";


if($row['status']=='Y') {
$status = "Hide";
} else {
$status = "Show";
}			

		echo '<form name="status_update" action="manage_products.php" method="post">';
		echo '<td valign="top"><input type="submit" value="'.$status.'" />';
		echo '<input type="hidden" name="status" value="'.$row['product_id'].'" />';
		echo '</td>';
		echo '</form>';

		echo "<td valign=top>"."<a href='modify_products.php?id=" . $row['product_id'] . "'/>  Modify </a>" . "</td>";
		echo "</tr>";	
	}
}
}	

 

hi

 

thanks thanks a lot. works perfect as needed.

 

vineet

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.