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:

if(isset($_GET['search']))
if(!isset($cmd))
{
$search = $_GET['search'];
}
$keywords = explode(" ", $search); <--- line 15

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

Well..maybe you need something between " and " in line 15?

$keywords = explode("$string", $search);

Like that maybe?

I don't thinks so. I think it has something to do with isset, if is set the variable before the code uses it, the error message goes away but new ones appear for different variable (same message though). Does anyone think it may be differences between php4 and 5?

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.

Ok, the problem is my hosting does not let me change the php.ini file. Can I change the error level in the script say with set_error_handler(). Would I just put at the top of the script.
Cheers for your help.

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.

Do it as UrbanSky said. It would look something like this:

$search = '';
if(isset($_GET['search']))
if(!isset($cmd))
{
$search = $_GET['search'];
}

Thanks, that fixed the undefined variables but how do i fix the undefined indexes I'm getting on other pages? Code;

$name = stripslashes($_POST['txtName']);
$message = stripslashes($_POST['txtMessage']);

is giving undefined indexes txtmessage and txtname.

While

if($_GET["cmd"]=="delete")

is giving cmd

and finally

if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")

is also giving cmd and I don't know how to define an index.

Thanks very much for any help.

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

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..

$name = isset($_POST['txtName']) ? stripslashes($_POST['txtName']) : '';
This article has been dead for over six months. Start a new discussion instead.