Jump to content


Photo

passing values directly to a new page and using them to update values


  • Please log in to reply
4 replies to this topic

#1 kikilahooch

kikilahooch
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 30 August 2006 - 12:15 PM

I'm trying to pass values through from one page to the next by clicking on an image. When I click an image it passes through the values for prodId and shopName

<td align="center"><a href="admin_update2.php?login=true&shopName='.$row['shopName'].'&prodId='.$row['prodId'].'"><img src="http://snet.wit.ie/~ciaracousins/clothes/' . $row['image'] . '"></a>

This is passed through to my admin_update.php where I want to populate a table with all of the details stored on the product that was clicked on. The values are being passed through ok but the table is not being displayed. I have another update page but with this page i am using a submit button which is passing through the details. I tried using this method again but because there is no submit button used (I am just clicking on a link/image) it is not working for me. Below is the code I am trying to use

<?php 

include("db.php"); 

$prodId = $_GET['prodId']; 

$sql = "select * from product where prodId = '$prodId'";

//db 
//$result = mysql_query($sql,$conn) or die(mysql_error()); 


if (isset($_POST['submittedUpdate'])) 
{ 
    $prodId         = mysql_real_escape_string(trim($_POST['prodId'])); 
    $sName          = mysql_real_escape_string(trim($_POST['shopName'])); 
    $dept           = mysql_real_escape_string(trim($_POST['dept'])); 
    $brand          = mysql_real_escape_string(trim($_POST['brand']));
    $type           = mysql_real_escape_string(trim($_POST['type'])); 
    $image          = mysql_real_escape_string(trim($_POST['image'])); 
    $price          = mysql_real_escape_string(trim($_POST['price'])); 

		$query2 = "UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'";

$query = "SELECT * FROM product WHERE prodId = '$prodId'";


if ($result = mysql_query($query)) 
{ 
 
    $row = mysql_fetch_array($result, MYSQL_ASSOC) 
    ?> 
    <form action="admin_update2.php" method="post"> 
    <input type="hidden" name="prodId" value="<?php echo $prodId; ?>">

    <center> 
    <table align="center" cellspacing="0" cellpadding="5" bgcolor="#ffffff" border=1 bordercolor="#2696b8">

        <TR><TD align="left" bgcolor="#2696b8" width="30%"><FONT color="white"><B>Product Id: </B></FONT></TD> 
        <TD width="70%"><?php echo $row['prodId'] ?></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Shop Name:</B></FONT></TD> 
        <TD width="70%"><?php echo $row['shopName'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Product Name:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name=name value="<?php echo $row['prodName'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Department:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="surname" value="<?php echo $row['dept'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Brand:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="address" value="<?php echo $row['brand'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Type:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="address2" value="<?php echo $row['type'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Image:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="county" value="<?php echo $row['image'] ?>"></TD></TR>

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Price:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="county" value="<?php echo $row['price'] ?>"></TD></TR>

 	 <TR><TD></td> 
        <TD><CENTER><input name=submit type=submit value="UPDATE"> 
        <FONT color=navy></FONT></P></TD></TR> 
        </TBODY> 


	<input type="hidden" name="prodId" value='.$prodId.'>
	<input type="hidden" name="submittedUpdate" value="TRUE"/></td></tr>
			
    </TABLE> 
    </FORM> 
    <?php 
} 
}

?> 	

</body>
</html>

would be really grateful if somebody could point out what modifications need to be made

#2 joking

joking
  • Members
  • PipPip
  • Member
  • 29 posts
  • LocationLebanon

Posted 30 August 2006 - 12:28 PM

Hi,
I updated ur code ....

<?php 

include("db.php"); 
$prodId = 0;   // UPDATED
$prodId = $_GET['prodId']; 

$sql = "select * from product where prodId = '$prodId'";

//db 
//$result = mysql_query($sql,$conn) or die(mysql_error()); 


if ( (isset($_POST['submittedUpdate'])) || ($prodId != 0) ) 
{ 
    $prodId         = mysql_real_escape_string(trim($_POST['prodId'])); 
    $sName          = mysql_real_escape_string(trim($_POST['shopName'])); 
    $dept           = mysql_real_escape_string(trim($_POST['dept'])); 
    $brand          = mysql_real_escape_string(trim($_POST['brand']));
    $type           = mysql_real_escape_string(trim($_POST['type'])); 
    $image          = mysql_real_escape_string(trim($_POST['image'])); 
    $price          = mysql_real_escape_string(trim($_POST['price'])); 

		$query2 = "UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'";

$query = "SELECT * FROM product WHERE prodId = '$prodId'";


if ($result = mysql_query($query)) 
{ 
 
    $row = mysql_fetch_array($result, MYSQL_ASSOC) 
    ?> 
    <form action="admin_update2.php" method="post"> 
    <input type="hidden" name="prodId" value="<?php echo $prodId; ?>">

    <center> 
    <table align="center" cellspacing="0" cellpadding="5" bgcolor="#ffffff" border=1 bordercolor="#2696b8">

        <TR><TD align="left" bgcolor="#2696b8" width="30%"><FONT color="white"><B>Product Id: </B></FONT></TD> 
        <TD width="70%"><?php echo $row['prodId'] ?></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Shop Name:</B></FONT></TD> 
        <TD width="70%"><?php echo $row['shopName'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Product Name:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name=name value="<?php echo $row['prodName'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Department:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="surname" value="<?php echo $row['dept'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Brand:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="address" value="<?php echo $row['brand'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Type:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="address2" value="<?php echo $row['type'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Image:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="county" value="<?php echo $row['image'] ?>"></TD></TR>

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Price:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="county" value="<?php echo $row['price'] ?>"></TD></TR>

 	 <TR><TD></td> 
        <TD><CENTER><input name=submit type=submit value="UPDATE"> 
        <FONT color=navy></FONT></P></TD></TR> 
        </TBODY> 


	<input type="hidden" name="prodId" value='.$prodId.'>
	<input type="hidden" name="submittedUpdate" value="TRUE"/></td></tr>
			
    </TABLE> 
    </FORM> 
    <?php 
} 
}

?> 	

</body>
</html>

Just JoKinG

#3 kikilahooch

kikilahooch
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 30 August 2006 - 12:51 PM

Thank you, that is now displaying the table which is wasnt doing before but it is not being filled with the values for product. any ideas why? I have asked about this on here before and was told it was something to do with the fact that I am using isset($_POST['submittedUpdate'] when I am not using a submit button on my previous page. I am just using the url to pass the values through, but dont know how to get around this...

#4 kikilahooch

kikilahooch
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 30 August 2006 - 02:11 PM

I have after managed to get the values now displaying into the table by changing getting rid of the submitted update part at the beginning. The code now looks like this:

<?php 

include("db.php"); 
$prodId = 0;   // UPDATED
$prodId = $_GET['prodId']; 

$sql = "select * from product where prodId = '$prodId'";

//db 
$result = mysql_query($sql,$conn) or die(mysql_error());

if (mysql_num_rows($result) == 1) {

	//if authorized, get the values of prodId, shopName...

	$prodId 	  = mysql_result($result, 0, 'prodId');
	$shopName= mysql_result($result, 0, 'shopName');
	$dept 	  = mysql_result($result, 0, 'dept');
	$brand 	  = mysql_result($result, 0, 'brand');
	$type	  = mysql_result($result, 0, 'type');
	$image 	  = mysql_result($result, 0, 'image');
	$price 	  = mysql_result($result, 0, 'price');

	

		$query2 = "UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'";

$query = "SELECT * FROM product WHERE prodId = '$prodId'";


if ($result = mysql_query($query)) 
{ 
 
    $row = mysql_fetch_array($result, MYSQL_ASSOC) 
    ?> 
    <form action="admin_update2.php" method="post"> 
    <input type="hidden" name="prodId" value="<?php echo $prodId; ?>">

    <center> 
    <table align="center" cellspacing="0" cellpadding="5" bgcolor="#ffffff" border=1 bordercolor="#2696b8">

        <TR><TD align="right" bgcolor="#2696b8" width="30%"><FONT color="white"><B>Product Id: </B></FONT></TD> 
        <TD width="70%"><?php echo $row['prodId'] ?></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Shop Name:</B></FONT></TD> 
        <TD width="70%"><?php echo $row['shopName'] ?> </TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Product Name:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name=name value="<?php echo $row['prodName'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Department:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="surname" value="<?php echo $row['dept'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Brand:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="address" value="<?php echo $row['brand'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Type:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="address2" value="<?php echo $row['type'] ?>"></TD></TR> 

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Image:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="county" value="<?php echo $row['image'] ?>"></TD></TR>

        <TR><TD align="right" bgcolor="#2696b8"><FONT color="white"><B>Price:</B></FONT></TD> 
        <TD><INPUT type="text" maxLength=45 size=45 name="county" value="<?php echo $row['price'] ?>"></TD></TR>

 	<TR><TD></td> 
        <TD><CENTER><input name=submit type=submit value="UPDATE"> 
        <FONT color=navy></FONT></P></TD></TR> 
        </TBODY> 


	<input type="hidden" name="prodId" value='.$prodId.'>
	<input type="hidden" name="submittedUpdate" value="TRUE"/></td></tr>
			
    </TABLE> 
    </FORM> 
    <?php 
} 
}

?> 	

</body>
</html>
 

But now it is not actually updating the products.

#5 joking

joking
  • Members
  • PipPip
  • Member
  • 29 posts
  • LocationLebanon

Posted 30 August 2006 - 05:07 PM

The query isnt being executed
REPLACE THIS :
$query2 = "UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'";


with this :
$query2 = mysql_query("UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'");



Just JoKinG




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users