Jump to content

[SOLVED] Arghh... switched on errors, now I have loads :/


dmccabe

Recommended Posts

I was having an issue where any errors such as missing ;'s and things were not being displayed on my web server.

 

So I switched on display_errors in php.ini - all good.

 

Well kinda!

 

Now I am getting errors on my forms which look like this when click the "submit" button:

 

Not Found

 

The requested URL /phonebook/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>C:\wamp\www\wordpress\phonebook\index.php</b> on line <b>42</b><br /> was not found on this server.

 

Anyone know why?

 

p.s. this isnt a word press thing it is just in the wordpress folder.

Link to comment
Share on other sites

dont use PHP_SELF..try $_SERVER['REQUEST_URI']

 

thatll fix some issues

 

 

The equivalent for $PHP_SELF is $_SERVER['PHP_SELF']. The difference between PHP_SELF and REQUEST_URI is that REQUEST_URI includes the query string whereas PHP_SELF doesn't.

Link to comment
Share on other sites

Thanks guys, that has fixed the PHP_SELF errors, however now I have new issue's.

 

 

Notice: Undefined index: name in C:\wamp\www\wordpress\phonebook\index.php on line 71

 

Notice: Undefined index: name in C:\wamp\www\wordpress\phonebook\index.php on line 187

 

Notice: Undefined variable: sort_by in C:\wamp\www\wordpress\phonebook\index.php on line 194

 

Line 71 is:

 

if ($_GET['name']) {

which is checking if the button on the form has been pressed and therefore passing the variable 'name'

 

now what?

 

 

Link to comment
Share on other sites

Undefined index errors are caused, in this case, when referencing an invalid array key.

 

Is your form method POST or GET?

If its POST you should use $_POST['name'] and if you also have GET data you need to be passed into the next page use $_SERVER['REQUEST_URI'] for your action. As I just learned is different to PHP_SELF  :P

Link to comment
Share on other sites

Right we are getting there, the isset thing worked fine.

 

However I have a lot of lines like this:

 

echo "<td bgcolor=\"$color\" width=\"12.5%\">".$info[$a]["telephonenumber"][0]." </td>";

 

Which is getting the phone number pulled from our Active Directory setup.

 

However not all users have a phone number specified, so if they dont I get this error:

 

Notice: Undefined index: telephonenumber in C:\wamp\www\wordpress\phonebook\index.php on line 300

 

Which I am guessing again is down to the isset thing as telephonenumber isn't set for that person, but what is the correct way to use the isset in-line on this?

Link to comment
Share on other sites

<?php
echo (isset($info[$a]["telephonenumber"]) ? "<td bgcolor=\"$color\" width=\"12.5%\">".$info[$a]["telephonenumber"][0]." </td>" : '';
?>

 

Will create the table cell if it exists, and nothing if it doesn't, if you would like a blank table cell to be created alter to this

 

<?php
echo (isset($info[$a]["telephonenumber"]) ? "<td bgcolor=\"$color\" width=\"12.5%\">".$info[$a]["telephonenumber"][0]." </td>" : "<td bgcolor=\"$color\" width=\"12.5%\"> </td>";
?>

Link to comment
Share on other sites

For the last option, this would probably be better:

 

echo "<td bgcolor=\"$color\" width=\"12.5%\">" . (isset($info[$a]['telephonenumber']) ? $info[$a]["telephonenumber"][0] : ' ') . "</td>";

 

Thanks guys, so is that kind of like an in-line if, but without the if?

 

so if this :

(isset($info[$a]['telephonenumber']) 

do this

$info[$a]["telephonenumber"][0]

else this 

 

? I have not seen it done like this before is all.

Link to comment
Share on other sites

Thanks Dan, one last question on this, would this work ok?

 

echo "<td bgcolor=\"$color\" width=\"12.5%\">" . (isset($email && $info[$a]["givenname"][0] && $info[$a]["sn"][0]) ? <a href=\"mailto:$email\" title=\"Email ".$info[$a]["givenname"][0]." ".$info[$a]["sn"][0]."\"><b>".$info[$a]["sn"][0] : ' ') . "</b></a> </td>";

 

with the multiple operators?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.