0

I wanna make option edit product when user login. Here is the link when user click edit on the web.

 <a href="edit.php?id=<?php $id=$data['gameId'];echo $id;?>" ><input type="button" value="Edit"/></a>

Then in edit page, there's submit button, that I fill with some validation in doUpdate.php I tried to get id from URL in doUpdate.php to make an update in database (Id is the primary key, I use my sql as database) so I use this code

  $id= $_GET['id'];

The problem is, why $id couldn't take the id value from the url? How should I fixed that? (It is not hosting yet, I use localhost cause I'm still learning)

greenthunder
  • 697
  • 8
  • 19
  • 34

4 Answers4

1

If I'm understanding you correctly the problem isn't getting the id in edit.php, but getting the id in doUpdate.php. Presumably your edit page is POSTing date to the doUpdate page, in which case you need to do two things.

firstly inside your form on the edit page you'll need to add a hidden element inside you formcontaining the id you want to pass to doUpdate.php

<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>"/>

and then in doUpdate.php fetch it from the $_POST global

$id = $_POST['id'];
Crisp
  • 11,417
  • 3
  • 38
  • 41
  • Yes, I couldn't get the id in doUpdate.php. I added input type hidden as your advice but it still not working. Why can't I get the id although I used $_GET['id'] and it's located in URL? – greenthunder May 05 '12 at 14:01
1

You have to either edit the form action in your edit.php like <form name="edit" action="doUpdate.php?id=<?= $_GET['id'] ?> or you just create an input field, within the form, which has the value from your GET Parameter. .

Ahatius
  • 4,777
  • 11
  • 49
  • 79
0

The code inside your <a> tag is incorrect. Also, you can't have a <button> inside an <a>. Try this:

<a href="edit.php?id=<?php echo $data['gameId'];?>">Edit</a>
Nadh
  • 6,987
  • 2
  • 21
  • 21
0

It is possible for PHP to automatically set variables in this way using a feature called register_globals, but using this feature can open up security holes in your application which is why it is currently deprecated, and will eventually be removed from PHP.

The PHP manual has a detailed explanation of the feature and why it should not be used: http://php.net/manual/en/security.globals.php

Tim Fountain
  • 33,093
  • 5
  • 41
  • 69