php form question (1 Viewer)

1987

Rookie
Joined
Feb 19, 2010
Messages
82
Reaction score
22
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
 

robsmith32

Super Forum Fanatic
Joined
Aug 7, 2006
Messages
9,194
Reaction score
1,533
Age
51
Offline
I don't know php, but looks like search isn't defined in post string would be my guess from what looks like.
 

jumpingoff

All-Pro
VIP Contributor
Joined
Mar 21, 2006
Messages
1,263
Reaction score
808
Offline
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.
 

jumpingoff

All-Pro
VIP Contributor
Joined
Mar 21, 2006
Messages
1,263
Reaction score
808
Offline
<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>
 

d3cyph3r

Hall-of-Famer
VIP Contributor
Platinum VIP Contributor
Joined
Sep 11, 2004
Messages
3,084
Reaction score
1,077
Location
Metairie
Offline
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.
 

taygolf

Hall-of-Famer
Joined
May 3, 2007
Messages
3,665
Reaction score
468
Offline
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
 

daybreaker

STH since 2006
Joined
Sep 1, 2003
Messages
12,027
Reaction score
12,985
Age
37
Location
Kenner
Offline
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 (Users: 0, Guests: 1)

Similar threads




Saints Headlines (The Advocate)

Headlines

Top Bottom