Sarajs Posted January 29, 2009 Share Posted January 29, 2009 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 x Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/ Share on other sites More sharing options...
gevans Posted January 29, 2009 Share Posted January 29, 2009 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 https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750189 Share on other sites More sharing options...
Sarajs Posted January 29, 2009 Author Share Posted January 29, 2009 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 https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750202 Share on other sites More sharing options...
gevans Posted January 29, 2009 Share Posted January 29, 2009 Can you show me the enxt page, I'm not really getting the problem. If the Product ID has been passed via POST you'll have access to it on the next page. Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750205 Share on other sites More sharing options...
Sarajs Posted January 30, 2009 Author Share Posted January 30, 2009 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 https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750213 Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 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 https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750219 Share on other sites More sharing options...
Sarajs Posted January 30, 2009 Author Share Posted January 30, 2009 that was just left from testing I've taken it out now. I sent you a message with the url for the site. Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750221 Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 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 https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750222 Share on other sites More sharing options...
Sarajs Posted January 30, 2009 Author Share Posted January 30, 2009 i thought of doing this, I'll give it a try Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750224 Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 If you still have a problem just shout Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750229 Share on other sites More sharing options...
Sarajs Posted January 30, 2009 Author Share Posted January 30, 2009 It's not picking it up in the hidden field <form enctype="multipart/form-data" action="editProduct.php?productID=" method="post"> Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750230 Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 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 https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750235 Share on other sites More sharing options...
Sarajs Posted January 30, 2009 Author Share Posted January 30, 2009 cool sorry I posted the wrong line! Latest version live Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750239 Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 I think we're getting pages mixed up. I wanted you to add the code to editProduct.php not selectEditProduct.php Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750242 Share on other sites More sharing options...
Sarajs Posted January 30, 2009 Author Share Posted January 30, 2009 ahh sorry put it on completely wrong page! done Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750248 Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 Did you change the previous page as I just get 'Product not found' Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750253 Share on other sites More sharing options...
Sarajs Posted January 30, 2009 Author Share Posted January 30, 2009 ah sorry, i was fixing something else and accidentally deleted it, use product 70 Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750265 Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 It works.... the product number is stored in the hidden field. You can change the form tag to this; <form enctype="multipart/form-data" action="editProduct.php" method="post"> Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750272 Share on other sites More sharing options...
Sarajs Posted January 30, 2009 Author Share Posted January 30, 2009 Brilliant, thank you so much!! Uni project for tomorrow!! x Link to comment https://forums.phpfreaks.com/topic/143050-solved-posting-a-form-value-through-url-query-help/#findComment-750283 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.