el-sid Posted May 31, 2010 Share Posted May 31, 2010 hi, i am unable to retrieve the id from the $_GET variable. I am trying to update a table in a database with a specific id. The thing is, i can see the id on the address bar, but cannot retrieve it via $_GET http://portal:8080/events/admin/editEvent.php?id=14 this is the code <?php require('../config.php'); //require('../NewsScript.php'); include ('../../lib/class.form.php'); include ('../../lib/Events.class.php'); include ('../../lib/class.upload.php'); session_start(); /** * Here we have clicked the button to update our edited article * We need to update it in the database */ if(!empty($_POST['caption'])) { $event = new Events(); $uploadDir = dirname(__FILE__) . "/images/"; $tmpName = $_FILES['event_image']['tmp_name']; $ext = substr(strrchr($tmpName, "."), 1); // make the random file name $randName = md5(rand() * time()); // and now we have the unique file name for the upload file $filePath = $uploadDir . $randName . '.' . $ext; $name = $randName . '.' . $ext; $file = new upload($_FILES['event_image']); $file->file_new_name_body = $name; $file->image_resize = true; $file->image_convert = gif; $file->image_x = 100; $file->image_y = 100; $file->process($uploadDir); $event->updateEvent($_GET['id'], $_POST['caption'], $_POST['content'], $filePath ); if($event->updateEvent($_GET['id'], $_POST['caption'], $_POST['content'], $filePath )) { echo "Update complete!"; echo "<br>"; echo $_GET['id'] . "<br>"; echo $_POST['caption'] . "<br>"; echo $_POST['content'] ."<br>"; echo $filePath; } else { echo "Update Error!"; } exit(); } else // page loads but form not submitted { if(is_numeric($_GET['id'])) { $connection = mysql_connect($db_host, $db_user, $db_password) or die("Unable to connect to MySQL"); mysql_select_db($db_name, $connection) or die("Unable to select DB!"); $id = $_GET['id']; $result = mysql_query("SELECT * FROM event WHERE id = '$id'"); $row = mysql_fetch_assoc($result); $caption = $row['caption']; $content = $row['content']; mysql_close($connection); } else { echo "None numeric Value!"; } } /** * output our content * */ function showContent() { global $content; echo $content; } /** * output the author * */ function showCaption() { global $caption; echo 'value="'. $caption . '"'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Edit News</title> </head> <body> <h1>Edit News</h1> <?php $form = new genForm(); $form->startForm(basename($_SERVER['PHP_SELF'])); $form->startFieldset(''); $form->textareaInput('caption','Caption',false,false,false,$caption, 15,10); $form->closeFieldset(); $form->insertBR(); $form->startFieldset(''); $form->textareaInput('content','Content',false,false,false,$caption, 25,10); $form->closeFieldset(); $form->insertBR(); $form->startFieldset(''); $form->fileInput('event_image','Upload Your Event Picture'); $form->closeFieldset(); $form->insertBR(); $form->newline = false; $form->submitButton(); $form->newline = true; $form->resetButton(); $form->closeForm(); if(!$output = $form->getForm()) { die("error: " . $form->error); } else { echo $output; } ?> </body> </html> any ideas? thanks Link to comment https://forums.phpfreaks.com/topic/203416-unable-to-retrieve-_getid-value/ Share on other sites More sharing options...
riwan Posted May 31, 2010 Share Posted May 31, 2010 try storing the $_GET["id"] to for instance $id at the beginning of the page. Link to comment https://forums.phpfreaks.com/topic/203416-unable-to-retrieve-_getid-value/#findComment-1065647 Share on other sites More sharing options...
el-sid Posted May 31, 2010 Author Share Posted May 31, 2010 thanks for the reply riwan, but it didnt work. could it be that all the other $_POST varables are available because they come from a $_POST request while the id is a $_GET in a $_POST form. though i was under the impression that requests in the url are accessible no matter the method in the form Link to comment https://forums.phpfreaks.com/topic/203416-unable-to-retrieve-_getid-value/#findComment-1065654 Share on other sites More sharing options...
riwan Posted May 31, 2010 Share Posted May 31, 2010 well, when you access this from other page it should work http://portal:8080/events/admin/editEvent.php?id=14 but if you're submitting a form with method post, you shouldn't put ?id= in the action but instead store the id value in the hidden field so you can retrieve the id value using $_POST["id"] Link to comment https://forums.phpfreaks.com/topic/203416-unable-to-retrieve-_getid-value/#findComment-1065660 Share on other sites More sharing options...
el-sid Posted May 31, 2010 Author Share Posted May 31, 2010 well, when you access this from other page it should work http://portal:8080/events/admin/editEvent.php?id=14 but if you're submitting a form with method post, you shouldn't put ?id= in the action but instead store the id value in the hidden field so you can retrieve the id value using $_POST["id"] i am redirecting from a link in another page. it redirects from this code in a seperate php file while($row = mysql_fetch_assoc($result)) { // Display the row $id = $row['id']; $caption = $row['caption']; $content = $row['content']; $event_image = $row['event_image']; /** * show each article with edit/delete links */ echo "<div>ID: $id</div>"; echo "<div>Caption: $caption</div>"; echo "<div>Content: $content</div>"; echo "<div>Event Picture: $event_image</div>"; echo "<div><a href=\"editEvent.php?id=$id\">Edit</a> | <a href=\"deleteEvent.php?id=$id\">Delete</a></div>"; echo"<br /><hr />"; } Link to comment https://forums.phpfreaks.com/topic/203416-unable-to-retrieve-_getid-value/#findComment-1065663 Share on other sites More sharing options...
riwan Posted May 31, 2010 Share Posted May 31, 2010 what I mean is change the way you create your form $form->startForm("editEvent.php"); // this would make your form action doesn't contain the id I'm not sure how you create hidden input using class.form.php as I didn't have it. it should be output sth like this <input type="hidden" name="id" value="<?php echo $_GET["id"];?>"> Link to comment https://forums.phpfreaks.com/topic/203416-unable-to-retrieve-_getid-value/#findComment-1065668 Share on other sites More sharing options...
el-sid Posted May 31, 2010 Author Share Posted May 31, 2010 what I mean is change the way you create your form $form->startForm("editEvent.php"); // this would make your form action doesn't contain the id I'm not sure how you create hidden input using class.form.php as I didn't have it. it should be output sth like this <input type="hidden" name="id" value="<?php echo $_GET["id"];?>"> thanks..it woked Link to comment https://forums.phpfreaks.com/topic/203416-unable-to-retrieve-_getid-value/#findComment-1065672 Share on other sites More sharing options...
shino Posted May 31, 2010 Share Posted May 31, 2010 Try this in another php file on it's own and send it a ?id=1000 or something in the url: <?php echo $_GET['id'].'<br />'; echo $id.'<br />'; ?> It should only echo once, if you see it twice then register globals is on and you need to disable it with your host. Link to comment https://forums.phpfreaks.com/topic/203416-unable-to-retrieve-_getid-value/#findComment-1065673 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.