| | |
undefined variable error
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2007
Posts: 10
Reputation:
Solved Threads: 0
Hey, I've just uploaded some stuff to server and it works fine but theres a big error message through the screen saying "undefined variable seacrh at line 15"
Code:
[php]if(isset($_GET['search']))
if(!isset($cmd))
{
$search = $_GET['search'];
}
$keywords = explode(" ", $search); <--- line 15
[/php]
Also is there any way to write to an outfile (SQL) on my server. It worked offline but my absolute path isn't working. I assume the directory can't be written to.
Thanks for any help
Code:
[php]if(isset($_GET['search']))
if(!isset($cmd))
{
$search = $_GET['search'];
}
$keywords = explode(" ", $search); <--- line 15
[/php]
Also is there any way to write to an outfile (SQL) on my server. It worked offline but my absolute path isn't working. I assume the directory can't be written to.
Thanks for any help
•
•
Join Date: Oct 2006
Posts: 14
Reputation:
Solved Threads: 0
Well..maybe you need something between " and " in line 15?
Like that maybe?
PHP Syntax (Toggle Plain Text)
$keywords = explode("$string", $search);
Like that maybe?
•
•
Join Date: Oct 2006
Posts: 42
Reputation:
Solved Threads: 4
You get the error message because you have your error level set to E_ALL or simalar. The message that you are getting is a warning and doesn't affect how the script runs.
When you put it on a production server you shoud have the lower level warning messages turned off anyway. If you really want to get ride of it just intialise the variable at the start of the script.
When you put it on a production server you shoud have the lower level warning messages turned off anyway. If you really want to get ride of it just intialise the variable at the start of the script.
•
•
•
•
You get the error message because you have your error level set to E_ALL or simalar. The message that you are getting is a warning and doesn't affect how the script runs.
When you put it on a production server you shoud have the lower level warning messages turned off anyway. If you really want to get ride of it just intialise the variable at the start of the script.
[PHP]$search = '';
if(isset($_GET['search']))
if(!isset($cmd))
{
$search = $_GET['search'];
}
[/PHP]
•
•
Join Date: Feb 2007
Posts: 10
Reputation:
Solved Threads: 0
Thanks, that fixed the undefined variables but how do i fix the undefined indexes I'm getting on other pages? Code;
[php]$name = stripslashes($_POST['txtName']);
$message = stripslashes($_POST['txtMessage']);[/php] is giving undefined indexes txtmessage and txtname.
While[php]if($_GET["cmd"]=="delete")[/php] is giving cmd
and finally[php]if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")[/php] is also giving cmd and I don't know how to define an index.
Thanks very much for any help.
[php]$name = stripslashes($_POST['txtName']);
$message = stripslashes($_POST['txtMessage']);[/php] is giving undefined indexes txtmessage and txtname.
While[php]if($_GET["cmd"]=="delete")[/php] is giving cmd
and finally[php]if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")[/php] is also giving cmd and I don't know how to define an index.
Thanks very much for any help.
•
•
Join Date: Oct 2006
Posts: 42
Reputation:
Solved Threads: 4
You are getting these because you are referancing array keys that do not exist.
Without seeing your whole script it is difficult to give you definate answer but I would assume that you are using the $_POST and $_GET variables each time the script is run wheater a form has been submited or not (which I guess means that you form submits to the page that it is on).
The easiest way to stop this is check to see if the form has ben submitted with something like
Or you are referencing form fields that do not exist.
Without seeing your whole script it is difficult to give you definate answer but I would assume that you are using the $_POST and $_GET variables each time the script is run wheater a form has been submited or not (which I guess means that you form submits to the page that it is on).
The easiest way to stop this is check to see if the form has ben submitted with something like
PHP Syntax (Toggle Plain Text)
if(isset($_POST['submit']))
Or you are referencing form fields that do not exist.
You could use the shorthand notation with isset, it keeps things on one line..
[php]
$name = isset($_POST['txtName']) ? stripslashes($_POST['txtName']) : '';
[/php]
[php]
$name = isset($_POST['txtName']) ? stripslashes($_POST['txtName']) : '';
[/php]
Last edited by digital-ether; Mar 24th, 2007 at 6:47 am.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: find the parse error
- Next Thread: PHP - subscribers' email
| Thread Tools | Search this Thread |
ajax apache api array arrays beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external file files folder form forms forum function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert integration ip java javascript joomla limit link login loop mail malfunction menu method mlm multiple mysql neutrality oop paypal pdf php phpmysql play problem query question radio random recursion regex remote root script search select server sessions sms soap source space sql syntax system table tutorial update upload url validator variable video web xml youtube






