jaboc Posted April 6, 2007 Share Posted April 6, 2007 I keep getting this error PHP Notice: Undefined index: search in simpleformdata2.php on line 12 line 12 is the line where the search variable is declared. I am still learning php and this is code from a text book. coppied line for line. <?php $search = $_GET["search"]; $self=$_SERVER['PHP_SELF']; if ($search != NULL ) { (' <form action="'.$_SERVER["PHP_SELF"].'" method="GET"> <label>Search: <input type="text" name="search" /> </label> <input type="submit" value="Go!" /> </form> '); } ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 6, 2007 Share Posted April 6, 2007 What is this chunk of code? <?php (' <form action="'.$_SERVER["PHP_SELF"].'" method="GET"> <label>Search: <input type="text" name="search" /> </label> <input type="submit" value="Go!" /> </form> '); ?> It looks like you're missing an "echo" <?php echo '<form action="'.$_SERVER["PHP_SELF"].'" method="GET"> <label>Search: <input type="text" name="search" /> </label> <input type="submit" value="Go!" /> </form>'; ?> Ken Quote Link to comment Share on other sites More sharing options...
jaboc Posted April 6, 2007 Author Share Posted April 6, 2007 hmm, text book doesn't have the echo...I will try it. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 6, 2007 Share Posted April 6, 2007 Textbooks aren't always accurate, unfortunately. Ken Quote Link to comment Share on other sites More sharing options...
jaboc Posted April 6, 2007 Author Share Posted April 6, 2007 hmm I don't think this is gonna work. the moddified code you gave me didnt include the if statement which is used to check if there is data in the text field. I tried this <?php echo '$search = $_GET["search"]'; $self=$_SERVER['PHP_SELF']; if ($search != NULL ) { (' <form action="'.$_SERVER["PHP_SELF"].'" method="GET"> <label>Search: <input type="text" name="search" /> </label> <input type="submit" value="Go!" /> </form> '); } ?> got this error $search = $_GET["search"] PHP Notice: Undefined variable: search in simpleformdata2.php on line 14 when I tried this <?php echo '$search = $_GET["search"]; $self=$_SERVER['PHP_SELF']; if ($search != NULL ) { (' <form action="'.$_SERVER["PHP_SELF"].'" method="GET"> <label>Search: <input type="text" name="search" /> </label> <input type="submit" value="Go!" /> </form> '); }' ?> this error came up PHP Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in simpleformdata2.php on line 13 Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 6, 2007 Share Posted April 6, 2007 you should be very familiar with these tutorials before posting in any php forum: tizag and w3schools. Quote Link to comment Share on other sites More sharing options...
jaboc Posted April 6, 2007 Author Share Posted April 6, 2007 I am confused because I read the guidelines for posting and it said that this is a forum for people learning php yet I ask for help and I am told that I should go read tutorials before I post. also in the guidlines it says people who are new to php should post in the php newbie forum which I couldnt find. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 6, 2007 Share Posted April 6, 2007 The php newbie forum hasn't existed on this site in over a year. The guidelines need to be changed. I just posted one piece of your code that I felt was in error. Now I will post your entire code with the fixes that should make it work (maybe) <?php <?php $search = $_GET["search"]; // you don't want an "echo" here since this line needs to be executed $self=$_SERVER['PHP_SELF']; if ($search != NULL ) { echo '<form action="'.$_SERVER["PHP_SELF"].'" method="GET"> <label>Search: <input type="text" name="search" /> </label> <input type="submit" value="Go!" /> </form>'; } ?> Please remember to surround all of your code with tags. Ken Quote Link to comment Share on other sites More sharing options...
jaboc Posted April 6, 2007 Author Share Posted April 6, 2007 *sigh* got this error PHP Notice: Undefined index: search in simpleformdata3.php on line 12 $search = $_GET["search"]; // this is line 12 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 6, 2007 Share Posted April 6, 2007 That is just a "Notice", not an error. Looking at the code, the logic is incorrect. Try this: <?php if (!isset($_GET['search'])) { echo '<form action="'.$_SERVER["PHP_SELF"].'" method="GET"> <label>Search: <input type="text" name="search" /> </label> <input type="submit" value="Go!" /> </form>'; } else echo 'You want to search for <span style="color:red;font-weight:bold">' . stripslashes($_GET['search']) . '</span>'; ?> I put the "else" clause in so you will see what you entered into the form. Ken Quote Link to comment Share on other sites More sharing options...
jaboc Posted April 6, 2007 Author Share Posted April 6, 2007 cool, thanks...This text book I am using might be useless then huh? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 6, 2007 Share Posted April 6, 2007 Yes. What is the name of the book and when was it published? If there is a web site associated with the book, check it out to see if any errata have been posted. Ken Quote Link to comment Share on other sites More sharing options...
jaboc Posted April 6, 2007 Author Share Posted April 6, 2007 learning PHP & MySQL printed 2006 0'Reilly Media wow user reviews on the site say there are many errors in this book! good thing I didnt buy it! I borrowed it from a friend. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 6, 2007 Share Posted April 6, 2007 I am confused because I read the guidelines for posting and it said that this is a forum for people learning php yet I ask for help and I am told that I should go read tutorials before I post. also in the guidlines it says people who are new to php should post in the php newbie forum which I couldnt find. allow me to clarify. we are not here to re-invent the wheel. there are plenty of tutorials on the internet explaining just about everything you could want to know. 'just about' are the operative words in that sentence. after doing research online and the manual, you should post your questions here. you were looking for a how-to 'if/else' condition... this is a very elementary procedure that can be found in a thousand other places. please, don't waste the space on simple posts. come here to acquire conceptual and procedural understanding of things you do not yet know, but only after you have attempted on your own. unfortunately, that book of yours isn't a very good reference. replace that text book with those two tutorial sites i posted, and you'll be good to go. welcome to the forums! Quote Link to comment Share on other sites More sharing options...
jaboc Posted April 6, 2007 Author Share Posted April 6, 2007 cool, thanks for the clarification. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.