php form question (1 Viewer)

Joined
Feb 19, 2010
Messages
158
Reaction score
174
Offline
I am getting the error "Undefined index: search". I know it has to do with search being the wrong variable being passed from the form but I'm not sure what is suppose to be passed and I've tried everything. Could some help me out?

I've placed stars where some vowels would go to prevent it from posting a text box.

Code posted below:

<!--<form action='custSearch.php' method='post'>
<input type='text' name='search' />
<input type='submit' value='search' />
<input type='hidden' name='do' value ='value' />
</form>";--> <f*rm acti*n='custSearch.php' meth*d='p*st'>
<inp*t type='t*xt' name='se*rch' />
<inp*t type='subm*t' val*e='search' />
<inp*t type='hidd*n' n*me='d*' val*e ='val*e' />
</f*rm>";

$value = $_POST['search'];

if (isset($_POST['do']) && $_POST['do'] == 'value')
{
//checking to see if field is empty then proceeding with search query
if (empty($value))
{
echo "You left search field blank.";
}
else
 
I don't know php, but looks like search isn't defined in post string would be my guess from what looks like.
 
I don't know php, but looks like search isn't defined in post string would be my guess from what looks like.

My php is rusty....btw, Rob the value of post is set via user input, enter your age, name etc.

I think you may want to define if statement as if post = = "" then echo "you left the search field blank" else (run rest of script).

sorry for bad syntax but hope you understand.
 
<code>go here to see what I mean....

http://stackoverflow.com/questions/16211612/php-post-if-statement<!--?php //$status = $_POST['status']; //if($status == ""){ //echo "Please enter a status."; //} //else { //echo "Thanks"; //} //?--></code>
 
why don't you do
PHP:
<pre>
<?php  print_r($_POST); ?>
</pre>
this will tell you exactly what is being posted, maybe your variable has something weird going on.
 
I believe you need a $ in front of value in your if statement even if you have it wrapped in single quotes

Edit
Sorry I see you have a variable $value and a value that equals 'value'. Can't see the form piece of your code until I quote your post for a reply

Can you call $_Post['do'] twice like that? Just curious what would happen if you set that to $do and used it instead
 
The error means that $_POST['search'] isnt set.

$_POST is only set through an HTTP POST action, usually a form submission. Are you submitting a form to get to that page? Are you submitting your form to the same page you are initially loading with the form? (ie: is the main page index.php, and the form submits to index.php) Because if so, youll get that error on the initial load, since there would have been no POST action yet. wrap it in something like $value = isset($_POST["search"]) ? $_POST['search'] : false;

Then later when you want to use $value, you can do if($value) first
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Users who are viewing this thread

    Back
    Top Bottom