Jump to content

can I use a value="" in a form tag to select a DB table from $_POST?


spryce

Recommended Posts

I want to post some form identifyer when I hit submit, so that I can use this in an SQL query.

 

Previously I used the below code and would retrieve either page1.php or page2.php etc from $_POST['subject']);

 

<td>
<select name="subject" id="subject" onchange="gotourl(this.value)">
			<option value="" >Please Select</option>
			<option value="page1.php" >page1</option>
			<option value="page2.php">page2</option>
			<option value="page3.php">page3</option>
			</select>
		</td>

 

will this work?

 

<form id="form1" name="form1" value="tableName" method="post" action="">

 

$_POST['form1']) returns tableName......

 

Thanks

Link to comment
Share on other sites

I usually handle all my inputs on a one to one basis, as most of my inputs I require different things from..

in the form tag you don't need a value (actually I'm not even sure thats valid by W3C standards, I know Ive never seen it though).

 

Anyway.. if your looking just to have an array of data from any given form that you want to work with that array instead of a one to one, then all you need to do is go based on $_POST without the ['whatever'] as $_POST is an array by itself if you post your form and on the page its going to if you put

 

echo "<pre>";
print_r($_POST);
echo "</pre>";

 

you will see all the data in said array. All though I see you mention multiple forms? Do you mean on the same page? If so then a post is a post is a post. what ever lies between

<form> and </form>

is fair game to $_POST on a per form tag basis once the submit button is hit within those form tags.. Anything outside of that particluar form is not submitted. 

Link to comment
Share on other sites

hidden fields work, as long as they are within the <form> tags you are submitting. Although I wouldn't hard code my table names or anything that would make any connection to actual structure of my database into a place that's visible to those who know where to look in hopes of such information. Don't want to give any would be bad users anything pertinent to work with ya know.

 

Your concept however is alright, I would just use a different association.. say instead of TableName use some other identifier whatever you want to call it really. that you can put in your form handling script if($myHiddenValue == "thisSpecialValue"){$tableToUse = "TableName";} little extra work and processing per say. But in the end run Im a paranoid person. I don't trust anyone that comes to sites I work on cause ya never know when your gunna get that one that will just really $*(#$*RT& up your day..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.