dmccabe Posted June 6, 2008 Share Posted June 6, 2008 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. Quote Link to comment Share on other sites More sharing options...
Buddski Posted June 6, 2008 Share Posted June 6, 2008 dont use PHP_SELF..try $_SERVER['REQUEST_URI'] thatll fix some issues Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 6, 2008 Share Posted June 6, 2008 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. Quote Link to comment Share on other sites More sharing options...
Buddski Posted June 6, 2008 Share Posted June 6, 2008 You learn something new every day Either way should get the desired effect..Unless you dont want the query string.. Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 6, 2008 Author Share Posted June 6, 2008 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? Quote Link to comment Share on other sites More sharing options...
Buddski Posted June 6, 2008 Share Posted June 6, 2008 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 Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 6, 2008 Share Posted June 6, 2008 Try if (isset($_GET['name']) { instead. Same goes for the sort_by index if it's similar to the one with name. Quote Link to comment Share on other sites More sharing options...
Buddski Posted June 6, 2008 Share Posted June 6, 2008 Oh and yeah as Daniel0 said always check if its set before referencing it Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 6, 2008 Author Share Posted June 6, 2008 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? Quote Link to comment Share on other sites More sharing options...
RMcLeod Posted June 6, 2008 Share Posted June 6, 2008 <?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>"; ?> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 6, 2008 Share Posted June 6, 2008 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>"; Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 6, 2008 Author Share Posted June 6, 2008 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. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 6, 2008 Share Posted June 6, 2008 Yes, it resembles an if-else statement. It's called the ternary operator. See: http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 6, 2008 Author Share Posted June 6, 2008 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? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 6, 2008 Share Posted June 6, 2008 Sure Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 6, 2008 Author Share Posted June 6, 2008 Excellent, now I have some major reworking to do, thank you all for you help 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.