Skip to main content
Known Participant
March 8, 2012
Answered

Link: works as an a href, but not in php

  • March 8, 2012
  • 1 reply
  • 712 views

Upon submitting a form I want it to redirect to where it came from.

Using this: <a href="form_update.php?beer_id=<?php echo $row_beer_update['beer_id']; ?>">

I can create a link that will take me to the page I want with the right information. Unfortunately into won't work on the submit button. So I'd have to click once to submit the info, and again on the link to go to the page I want.

Using this:

    

mysql_select_db($database_beer_diary, $beer_diary);

  $Result1 = mysql_query($updateSQL, $beer_diary) or die(mysql_error());

  $row_beer_update = mysql_fetch_assoc($Result1);

   $updateGoTo = "detail_sheet.php?recordID=";

    if (isset($_SERVER['QUERY_STRING'])) {

      $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

      $updateGoTo .= $_SERVER['QUERY_STRING'];

    }

 

  header(sprintf("Location: %s", $updateGoTo));

}

It will go to the page I want, but it doesn't have the information I want on it.

So trying to combine the  two:

mysql_select_db($database_beer_diary, $beer_diary);

  $Result1 = mysql_query($updateSQL, $beer_diary) or die(mysql_error());

  $row_beer_update = mysql_fetch_assoc($Result1);

    $updateGoTo = "detail_sheet.php?recordID=".echo $row_beer_update['beer_id'];

   

This is the closest I got (I've tried several variations, but none worked). On this attempt I keep on getting "parse eror" but I can't see what's missing.

Any ideas?

Thanks

This topic has been closed for replies.
Correct answer bregent

No, you don't want to append the entire SQL update statement to the querystring, you just want the ID.

  $updateGoTo = "detail_sheet.php?recordID=".$_POST['beer_id'];

Also, I assume you are not showing us the entire sprintf() statement, as what you have posted would be invalid.

1 reply

Participating Frequently
March 8, 2012

You are executing an update statement, so $Result1 contains only TRUE or FALSE; it is not a pointer to a recordset. Since you are updating a table, just use the primary key from your update's WHERE clause for the querystring value.

ggourdeAuthor
Known Participant
March 8, 2012

Ah, bregent.  I see what you are saying about the $Result1.  So I tried this instead:

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form")) {

  $updateSQL = sprintf("UPDATE beer SET beer_name=%s, brewer=%s, style_id=%s, substyle_id=%s, country_id=%s, location_id=%s, container_id=%s, aroma_id=%s, aroma_notes=%s, appearance_id=%s, appearance_notes=%s, mouthfeel_id=%s, mouthfeel_notes=%s, flavor_id=%s, flavor_notes=%s, overall_id=%s, overall_notes=%s, recommend=%s, abv=%s, date_tasted_01=%s, image_id=%s WHERE beer_id=%s",

                      

                       GetSQLValueString($_POST['beer_id'], "int"));

  mysql_select_db($database_beer_diary, $beer_diary);

  $Result1 = mysql_query($updateSQL, $beer_diary) or die(mysql_error());

  $updateGoTo = "detail_sheet.php?recordID=".echo $updateSQL['beer_id'];

    if (isset($_SERVER['QUERY_STRING'])) {

      $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

      $updateGoTo .= $_SERVER['QUERY_STRING'];

    }

 

  header(sprintf("Location: %s", $updateGoTo));

}

But I am still getting the same parsing error.

bregentCorrect answer
Participating Frequently
March 8, 2012

No, you don't want to append the entire SQL update statement to the querystring, you just want the ID.

  $updateGoTo = "detail_sheet.php?recordID=".$_POST['beer_id'];

Also, I assume you are not showing us the entire sprintf() statement, as what you have posted would be invalid.