Alright guys, bear with me, im a noob when it come to PHP.


When a user clicks I am currently redirecting users the following way:

echo '<li class="edit"><a href=updateInfoForm.html?id='.$siteInfoId.'><img src ="images/edit.png" class="editImg" height="23" width="23"/></a></li>';

The problem is I would rather not have this data in the URL, I know how to use POST and GET in relation to HTML forms and I more often than not use POST, but I was wondering how I would go about passing the "id" parameter without putting it directly in the URL in this case.


Any help is much appreciated!

if you make it a small form then just include a "<input type=hidden ... for the id.

i actually never thought of that. that's a pretty good idea for a work around and I may end up using that, but are there any other ways that are a little more conventional?

Member Avatar for rajarajan2017

Create a form with a submit button, Inside form tag define attributes method="post" action="filename.php".

Then within the form whatever tag you define with name attribute will passed to filename.php while on submit.

In filename.php use:

$id=$_POST;
echo $id;

You can do it by using cookies and javascript

<?php
setcookie('id','125');
echo "<a href=updateInfoForm.html>a1</a>";
?>

updateInfoForm.html:

<script type="text/javascript">

alert(getCookie("id"));


function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}

</script>

thanks guys for all of your responses. I have another (related) question. I am attempting to post a form to itself. Let me back up. Right now I am displaying 6 columns using PHP and MySQL. and I want to give the user the ability to sort these results however they want. I am using a select list in a little form to post what the user wants to sort by. It works 100% fine when I use "get", but when I try to use "post" it only works sometimes. Is there something I am doing wrong?

Here are some snippets of the code where I am having trouble (FYI the name of the page is "siteInfo.html").

This is the form used to post the user selection:

<form action="siteInfo.html" id="inputForm" method="post">
					<select  class="select" name="sort" onchange="this.form.submit()">
						<option value="entryDate">Entry Date</option>";
						<option value="pageName">Page Name</option>";
						<option value="title">Title</option>";
						<option value="information">Information</option>";
						<option value="display">Display</option>";
					</select>
				</form>

Then later on down the page this is where the previous post from the form is read in:

<?php
                                        $sort = $_POST['sort'];
					include 'php/loginInfo.php'; 

					$link = mysql_connect($host, $user, $pass) or die(mysql_error());
					mysql_select_db($dbName) or die(mysql_error());	
					
					if(isset($sort)){
						$result = mysql_query('SELECT siteInfoId, entryDate, title, information, pageName, display FROM siteInfo, page WHERE page.pageId = siteInfo.pageId ORDER BY '.$sort.' desc');
					}else{
						$result = mysql_query('SELECT siteInfoId, entryDate, title, information, pageName, display FROM siteInfo, page WHERE page.pageId = siteInfo.pageId ORDER BY entryDate desc');
					}
					
					unset($sort);
                                  ?>

And then farther down the page I have this for debugging, it seems that the form is not posting everytime based on the results from this debug, but who knows:

<?php
					//FOR DEBUGGING, DELETE!!!!!!!
					if(isset($sort)){
						echo 'SELECT siteInfoId, entryDate, title, information, pageName, display FROM siteInfo, page WHERE page.pageId = siteInfo.pageId ORDER BY '.$sort.' desc';
					}else{
						echo 'Not Read!!! <br />';
						echo 'SELECT siteInfoId, entryDate, title, information, pageName, display FROM siteInfo, page WHERE page.pageId = siteInfo.pageId ORDER BY entryDate desc';
					}
					
					unset($sort);
					
					
					mysql_close($link);
				?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.