Jump to content

Not passing variable


Recommended Posts

The below script for some reason isn't passing along the product_id variable.

$product_id=$_GET['product'];
session_start();
$error=$_SESSION['error'];
$content.='<div class="product_information_text review_form">
<div class="review_header">Write a Review for '.$product_name.'</div>
<form action="./review_process.php?product='.$product_id.'">
<p class="form_item"><label>Name:</label> <input type="text" name="review_name" size="30" /></p>';
if(isset($error[0])){$content.='<p class="red">This field is required.</p>';}
$content.='
<p class="form_item"><label>E-Mail:</label> <input type="text" name="review_email" size="30" /></p>
<p class="form_item"><label>Location:</label> <input type="text" name="review_location" size="30" /></p>
<p class="form_item"><label>Describe Yourself:</label> <input type="text" name="review_describe" size="30" /></p>
<p class="form_item"><label>Review Title:</label> <input type="text" name="review_title" size="30" /></p>
<p class="form_item"><label>Best Use of Product:</label> <input type="text" name="review_best_use" size="30" /></p>
<p class="form_item"><label>Product Pros:</label> <input type="text" name="review_pros" size="30" /></p>
<p class="form_item"><label>Product Cons:</label> <input type="text" name="review_cons" size="30" /></p>
<p class="form_item"><label>Product Rating:</label><br />
<div class="rating_radio"><input type="radio" name="review_product_rating" value="1" /> <br />1</div>
<div class="rating_radio"><input type="radio" name="review_product_rating" value="2" /> <br />2</div>
<div class="rating_radio"><input type="radio" name="review_product_rating" value="3" checked /> <br />3</div>
<div class="rating_radio"><input type="radio" name="review_product_rating" value="4" /> <br />4</div>
<div class="rating_radio"><input type="radio" name="review_product_rating" value="5" /> <br />5</div>
<div class="worst">(Worst)</div><div class="best">(Best)</div>
</p>
<p> </p>
<p class="form_item"><label>Comments on Product:</label><br />
<textarea name="review_text" rows="10" cols="60"></textarea>
</p>
<p><input type="submit" value="Submit" name="Submit" /></p>
</form>
</div>
';
session_unset();
session_destroy();

 

That code shows the proper product=$product_id value in the form action tag.

 

$product_id=$_GET['product_id'];

$review_name=$_POST['review_name'];
$review_name = stripslashes($review_name);
$review_name = mysql_real_escape_string($review_name);
if($review_name==""){
$error0=1;
}
else{
$error0=0;
}

$review_title=$_POST['review_title'];
$review_title = stripslashes($review_title);
$review_title = mysql_real_escape_string($review_title);
if($review_title==""){
$error1=1;
}
else{
$error1=0;
}

$review_email=$_POST['review_email'];
$review_email = stripslashes($review_email);
$review_email = mysql_real_escape_string($review_email);
if($review_email==""){
$error2=1;
}
else{
$error2=0;
}

$review_location=$_POST['review_location'];
$review_location = stripslashes($review_location);
$review_location = mysql_real_escape_string($review_location);
if($review_location==""){
$error3=1;
}
else{
$error3=0;
}

$review_describe=$_POST['review_describe'];
$review_describe = stripslashes($review_describe);
$review_describe = mysql_real_escape_string($review_describe);
if($review_describe==""){
$error4=1;
}
else{
$error4=0;
}

$review_best_use=$_POST['review_best_use'];
$review_best_use = stripslashes($review_best_use);
$review_best_use = mysql_real_escape_string($review_best_use);
if($review_best_use==""){
$error5=1;
}
else{
$error5=0;
}

$review_pros=$_POST['review_pros'];
$review_pros = stripslashes($review_pros);
$review_pros = mysql_real_escape_string($review_pros);
if($review_pros==""){
$error6=1;
}
else{
$error6=0;
}

$review_cons=$_POST['review_cons'];
$review_cons = stripslashes($review_cons);
$review_cons = mysql_real_escape_string($review_cons);
if($review_cons==""){
$error7=1;
}
else{
$error7=0;
}

$review_product_rating=$_POST['review_product_rating'];
$review_product_rating = stripslashes($review_product_rating);
$review_product_rating = mysql_real_escape_string($review_product_rating);

$review_text=$_POST['review_text'];
$review_text = stripslashes($review_text);
$review_text = mysql_real_escape_string($review_text);
if($review_text==""){
$error8=1;
}
else{
$error8=0;
}

$review_show="n";

date_default_timezone_set('US/Eastern');
$review_date = date("F j, Y, g:i a T");

$error="".$error0."".$error1."".$error2."".$error3."".$error4."".$error5."".$error6."".$error7."".$error8."";

if($error!=="000000000"){
session_start();
$_SESSION['error']=$error;
header("Location: ./store.php?product=".$product_id."#review");
}
else{
$sql="INSERT INTO $tbl_name3 (product_id, review_show, review_title, review_email, review_name, review_location, review_date, review_describe, review_best_use, review_pros, review_cons, review_product_rating, review_text) VALUES ('$product_id', '$review_show', '$review_title', '$review_email', '$review_name', '$review_location', '$review_date', '$review_describe', '$review_best_use', '$review_pros', '$review_cons', '$review_product_rating', '$review_text')";
mysql_query($sql);
echo "Thank You for submitting your review. It should appear on the site 
within 48 hours.";
}

 

The above redirects to store.php?product=#review with no product id. Ideas on why?

Link to comment
Share on other sites

Your form doesn't have a method property on it. It my be passing the data as POST values (although I thought the default was GET). Anyway, try setting the method to method="get"

 

Wouldn't that put all the form's values in the URL? I don't want that. I just want the product_id carried in the URL. I did notice I forgot the method attribute and added it as POST. Still the same issue.

Link to comment
Share on other sites

Your form doesn't have a method property on it. It my be passing the data as POST values (although I thought the default was GET). Anyway, try setting the method to method="get"

 

Wouldn't that put all the form's values in the URL? I don't want that. I just want the product_id carried in the URL. I did notice I forgot the method attribute and added it as POST. Still the same issue.

 

Yeah, my bad. I see you were appending it to the action value. Do a print_r($_GET) on the receiving page to validate if the value is there and there is a problem in the code.

Link to comment
Share on other sites

I'm not sure which page is the sending page and which is the receiving page. BUt, I see you are not consistent in the naming ("product" vs. "product_id").

 

If the first script is posting to the second page, then your problem is that the form action is specified as follows:

<form action="./review_process.php?product='.$product_id.'">

 

And the second script is trying to reference the value using

$product_id=$_GET['product_id'];
Link to comment
Share on other sites

If you use method='get' (or specify no method) in your <form> tag, you cannot put any get parameters on the end of the URL in the action="" attribute. Any get parameters on the end of the URL will be completely replaced by the form data.

 

You would need to use a hidden form field in this case.

Link to comment
Share on other sites

I'm not sure which page is the sending page and which is the receiving page. BUt, I see you are not consistent in the naming ("product" vs. "product_id").

 

If the first script is posting to the second page, then your problem is that the form action is specified as follows:

<form action="./review_process.php?product='.$product_id.'">

 

And the second script is trying to reference the value using

$product_id=$_GET['product_id'];

 

wow.... I forgot that the $_GET[] is supposed to be the text before the equal sign.

 

I'll fixing that as soon as my host comes back up... it managed to crash as soon as I start trying to get this working.

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.