Jump to content

[SOLVED] Posting a form value through URL query HELP!


Sarajs

Recommended Posts

hey people! can't get hold of the "Guru" I would usually ask and I just can't figure this one out, maybe I have been looking at it for too long! I'm trying to post the 'productID' through the url to the next page, but it won't! it goes to the page but no value for 'productID', please please help it's driving me insane!!

 

<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/Templates/maintemp.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<?php $title = "Sounds Good - Edit Product"; //Set title
if(!isset($_SESSION['username'])){ //Check logged in
Header("Location: index.php");  } 

?>
<!-- InstanceEndEditable --> 
<?php include('includes/head.inc'); ?>
<!-- InstanceBeginEditable name="head" -->

<!-- InstanceEndEditable -->
</head>
<body>
<div class="container">
<?php include('includes/header.inc'); ?>
<!-- InstanceBeginEditable name="content" -->
<div class="left530"><h1>Edit Product</h1></div>
<div class="clearboth"></div>
<div class="formcontainter">


<form enctype="multipart/form-data" action="editProduct.php?productID=<?php echo $_POST['productID']; ?>" method="post">
<table>
<tr>
<td class="coltype1">
Product ID
</td>
<td class="coltype2" colspan="4">
<input name="productID"  id="productID" type="text" />
</td>
</tr><tr>
<td></td>
<td colspan="4">
<input class="submit" id="edit" type="submit" value="Edit" />
</td>
</tr>

</table></form>


</div>


<!-- InstanceEndEditable -->

<?php include('includes/footer.inc'); ?>

</body>
<!-- InstanceEnd --></html>

 

Thank you  ;D x

Link to comment
Share on other sites

If you're adding the productId in the form;

 

<input name="productID"  id="productID" type="text" />

 

then I'm guessing the form has not been sent yet, so there will be no POST data to allow you to do this;

 

<form enctype="multipart/form-data" action="editProduct.php?productID=<?php echo $_POST['productID']; ?>" method="post">

 

Are you trying to send the entered productId via GET?

Link to comment
Share on other sites

That's what I thought but I tried GET and that didn't work either, basically it's such a simple input form, where the user inputs the productID, clicks the edit button and it takes them to the edit page for that product, strangely it picks up the correct product and all the edit fields on the next page are filled with the correct product data, but I need it to be passed in the URL as when I click the modify button on the next page it needs the ProductID from the url, it should be so simple I jsut can't get it :S.

Link to comment
Share on other sites

here's the code to the following page:

 

<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/Templates/maintemp.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<?php 
if(!isset($_SESSION['username'])){
Header("Location: index.php");  }


$cd_productID = $_REQUEST['productID'];
global $cd_productID;

echo product
require('includes/DBConnection.inc');

$sql = mysql_query("SELECT tProducts . * , tProductTypes.productType FROM tProducts INNER JOIN tProductTypes ON tProducts.productTypeID = tProductTypes.productTypeID WHERE productID = '$cd_productID'") ;

$row = mysql_fetch_array($sql);


$cd_artist = $row['artist'];
$cd_title = $row['title'];
$cd_genre = $row['genre'];
$cd_year = $row['year'];
$cd_type = $row['productType'];
$cd_price = $row['price'];
$cd_description = $row['description'];
$cd_stock = $row['stockCount'];
$cd_img = $row['imgUrl'];
$cd_typeID = $row['productTypeID'];
$image_width = "100%";


$class2 = "hidden";
$employeeID = $_SESSION['employeeID'];


if($row['imgUrl'] == ""){

	$img_query = "SELECT tIcons.iconURL, tProductTypes.productTypeID FROM tProductTypes INNER JOIN
                      tIcons ON tProductTypes.iconID = tIcons.iconID WHERE tProductTypes.productTypeID = '$cd_typeID'";
	$img_result = mysql_query($img_query) or die($img_query."<br />".mysql_error());
	$image_width = "60px";
	$cd_img = mysql_result($img_result, 0, 'iconURL');
}

$title = "Product Details - ". $cd_title;
$action = "";
$deleteProduct = "productDetails.php?productID=" . strip_tags($_GET['productID']) ."";
$modifyProduct = "editProduct.php?productID=" . strip_tags($_GET['productID']) ."";

function DeleteProduct()
{
Global $cd_title, $cd_productID, $action, $deleteProduct, $employeeID;

$action = $deleteProduct;
require('includes/DBConnection.inc');

$query = "DELETE FROM `tProducts` WHERE `productID` = '".mysql_escape_string($cd_productID)."'";

$sql = mysql_query($query) or die($query."<br />".mysql_error());
$class = "hidden";
echo "The product has been deleted";


$date = date("d/m/y H:i");


$actionTypeID = 3;
$logAction = "INSERT INTO tLogs (employeeID, date, eventID) VALUES ($employeeID, '$date', $actionTypeID)";

		  
	$outcome = mysql_query($logAction) or die($query."<br />".mysql_error());
}

function ModifyProduct(){ 
Header("Location: ./editProduct.php?productID=".htmlentities($_GET['productID']));
exit();
}

?>
<!-- InstanceEndEditable --> 
<?php include('includes/head.inc'); ?>
<!-- InstanceBeginEditable name="head" -->

<!-- InstanceEndEditable -->
</head>
<body>
<div class="container">
<?php include('includes/header.inc'); ?>
<!-- InstanceBeginEditable name="content" -->
<div>
<div class="marginbottom">
<div class="left530"><h1>Product Details</h1></div>

</div>
<div class="clearboth"></div>
<div class="formcontainter">
<?php if(mysql_num_rows($sql) <= 0){
  echo("Product not found"); 
}
else{
if(isset($_POST['form_submit']) && strtolower($_POST['form_submit']) == "delete"){
	// print_r($_POST); 
	DeleteProduct(); 

}elseif(isset($_POST['form_submit']) && strtolower($_POST['form_submit']) == "modify"){ // you must not change the text on that submit button. or this will break.
	ModifyProduct(); // did it updfate the files? yeah I think so let me try again  thats at now!!  no I'll do i
}else{
?><form action="" method="post">
<div>
<div class="<?php $class ?>">

<table> 
<tr>
<td class="coltype1 headings">
Artist:
</td>
<td class="coltype2"><div class="<?php echo $class ?>">
<label id="artist" type="text"><?php echo $cd_artist; ?> </label></div>
<div class="<?php echo $class2 ?>"><input id="artist" name="artist" value=<?php echo "'$cd_artist'"; ?> type="text" /></div>
</td>
<td class="coltype3"> 

</td>
<td class="coltype1 headings">
Title:
</td>
<td class="coltype2">
<div class="<?php echo $class ?>">
<label id="title" type="text"><?php echo $cd_title; ?></label></div>
</td>

</tr>
<tr>
<td class="coltype1 headings">
Genre:
</td>
<td class="coltype2">
<div class="<?php echo $class ?>">
<label id="genre" type="text"><?php echo $cd_genre; ?> </label></div>
</td>
<td class="coltype3"> 

</td>
<td class="coltype1 headings">
Year:
</td>
<td class="coltype2">
<div class="<?php echo $class ?>">
<label id="year" type="text"><?php echo $cd_year; ?> </label></div>
</td>

</tr>
<tr>
<td class="coltype1 headings">
Type:
</td>
<td class="coltype2">
<div class="<?php echo $class ?>">
    <label id="type" type="text" ><?php echo $cd_type; ?> </label></div>
        
</td>
<td class="coltype3"> 

</td>
<td class="coltype1 headings">
Price:
</td>
<td class="coltype2">
<div class="<?php echo $class ?>">
<label id="price" type="text">£<?php echo $cd_price; ?> </label></div>
</td>

</tr>
<tr>
<td class="coltype1 headings">
Description:
</td>
<td class="coltype2" colspan="4">
<div class="<?php echo $class ?>">
    <label id="description" type="text"><?php echo $cd_description; ?></label></div>
</td>


</tr>
<tr>
<td class="coltype1 headings">
Image:
</td>
<td class="coltype2">
<div class="<?php echo $class ?>">
    <img src="images/productImages/<?php echo $cd_img; ?>" width="<?php echo $image_width; ?>" /> <p> </p></div>
</td>
<td class="coltype3"> 

</td>
<td colspan="2">
<table class="mini">
<tr>
<td class="coltype1 headings">
Stock:<br /> 
</td>
<td class="coltype2">
<div class="<?php echo $class ?>">
<label id="stock" type="text"><?php echo $cd_stock; ?> </label></div>    
</td>
</tr>
<tr>
<td class="coltype1 headings">
PID:<br /> 
</td>
<td class="coltype2">
<div class="<?php echo $class ?>">
<label id="stock" type="text"><?php echo $cd_productID; ?> </label></div>    
</td>
</tr>

</table>
</td>

</tr>
<tr>
<td>

</td>
<td colspan="4">
    <input id="modify" type="submit" name="form_submit" value="Modify"  /> <input id="delete" name="form_submit" type="submit" value="Delete" />
</td>
</tr>
</table>
<?php
} 
}
?></div></div>
</form>
</div>
</div>

<!-- InstanceEndEditable -->

<?php include('includes/footer.inc'); ?>

</body>
<!-- InstanceEnd --></html>

Link to comment
Share on other sites

Line 14: echo product

 

Not sure what that is suppose to be, the syntax is wrong. If it's meant to be a string there'd no quote. If it's meant to be a variable there's no dollar sign. And there's no closing semi-colon.

 

Apart from that what's wrong?

Link to comment
Share on other sites

Ok, how about where you have your hidden fields you put another one

 

<input type="hidden" name="productID" value="<?php echo $cd_productID ?>" />

 

 

Then hit View Source to make sure it's saved itself. If you're sending forms via POST there's no need to add anything to the URL (usually)

Link to comment
Share on other sites

I'm not sure you're completely understanding, I dont want it to show in this bit;

 

<form enctype="multipart/form-data" action="editProduct.php?productID=" method="post">

 

You should change the action so that it looks like this;

 

<form enctype="multipart/form-data" action="editProduct.php" method="post">

 

and use a hidden field as a way of passing the ID via POST.

 

Also, the code given above didn't perfectly replicate the live version of editProduct.php.

 

Can you post the current version, and I can do the change for you, or see where you're going wrong

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.