PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$id = $_GET['trans'];
/* code to use this $id in order to retrieve that exact row of data from mysql */
if (!isset($_POST['submit']))
{
/* code to create a form and insert data from mysql into each text box */
}
else
{
/*
code to update the database with any/all adjustments made to the form after submit has been clicked
*/
/*
Problem: $id no longer has a value so I cannot use it to update the mysql database
*/
}
I have no idea what the scope of _GET is but every other variable I have is accessible except $id. What am I missing here? Thanks in advance.
Last edited by dbdsol on Tue Jun 16, 2009 10:21 am, edited 2 times in total.
On its own that code looks okay, then - you'll have to show us more specific code. It's difficult to debug your code if you don't show us what you're using...
In scope terms, $_GET is accessible on any page (included, or directly accessed) which is reached with the relevant URL parameter added, I believe. Maybe your variable name is being overwritten somewhere?
mattpointblank wrote:Sorry, which bit doesn't work, specifically?
On line #91 when I submit the sql $query I get this error from mysql: Error in query: UPDATE transaction SET t_date='2009/06/08',amount= '925',deposit='1',comment='Temp Power K&A' WHERE id=. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2
$id no longer has a value. I confirmed that $id does have a valid value everywhere before line #68.
Ah, it could be because you're using it inside your form submission code - I could be wrong, but I think that once a form is submitted, the page it submits to can't reach the $_GET attributes (can anyone confirm this?). Either way, the way I normally handle this is to embed the ID value in a hidden form field, which you can then access by $_POST when the form is submitted.
I figured the problem was something to that effect, but I was just trying to find ways to make a copy of the data in $_GET so that I could preserve it.
Is there a way to make a copy of a variables value so that when it dies you dont lose the value?
You can use PHP's session functions, which persist across a session (eg, as long as the browser window is open), from page to page. They're pretty simple: Run this function to open a session:
session_start();
(has to run BEFORE any browser output, eg HTML code etc)
Then assign data to it like this:
$_SESSION['yourVariable'] = $_GET['id'];
Now on any subsequent page, you can access $_SESSION['yourVariable'] (as long as you call session_start() again on that page too). Pretty useful.