Jump to content

Archived

This topic is now archived and is closed to further replies.

kikilahooch

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

Recommended Posts

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

[code]<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>
[/code]

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

[code]<?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>
[/code]

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

Share this post


Link to post
Share on other sites
Hi,
I updated ur code ....

[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>
[/code]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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:

[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 (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>
  [/code]

But now it is not actually updating the products.

Share this post


Link to post
Share on other sites
The query isnt being executed
REPLACE THIS :
[code]
$query2 = "UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'";
[/code]

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

Share this post


Link to post
Share on other sites

×

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.