Fatal error: Call to undefined function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Fatal error: Call to undefined function

Post by gaogier »

I edited a pre existing code that works fine.

Here is what i have, but i get the following error, no idea why, can you help?

Code: Select all

<?php
# Admin script -admin2.php
# Created on 20 July 2005
# Created by Joseph Jeffery
include ('diffhead.inc');
include ('admin.inc');
 
if ($_SESSION['user_sitemod'] < 1){
echo '<br /><br /><br /><center>Please Login to access this feature</center>';
include('difffooter.inc');
exit();
}else{
 
 
//------------------------Begin Random Event-------------------------------------------//
 
 
function racndom(){
$page = $_GET['page'];
    if(empty($page)){
        $page = 1;
   }    
    $limit          = 25;               
    $query_count    = "SELECT id FROM random";    
    $result_count   = mysql_query($query_count);    
    $totalrows      = mysql_num_rows($result_count);
    
    $limitvalue = $page * $limit - ($limit);
 
echo '<p><center><font class="adminheader">Random Event Admin</font></center></p>';
echo "<TABLE border=\"0\" width=\"89%\" class=monster>\n";
echo "<TR><TD class=title><center>Random Event Name</center></td><td class=title><center>Edit</center></TD</TR>\n";
   /* query for Random Events */
 
        $query = "SELECT id, name, sorter FROM random ORDER BY sorter ASC LIMIT $limitvalue, $limit";
    
    $result = mysql_query ($query);
 
    while ($row = mysql_fetch_assoc ($result)) {
        /* display Random Events in a table */
 
        $count = $count + 1; 
        /* place table row data in 
         * easier to use variables.
         */
        $id = $row['id'];   
        $title = $row['name'];  
  
 
        /* display the data */
        echo '<TR bgcolor="'.processRow($count).'"><TD class="calc"><b>'.$title.'</b></td><td class="calc"><a href="'.$_SERVER['PHP_SELF'] . '?flibble=update_random&id='.$row['id'].'"><img src="images/admin/view.gif" alt="Edit" border="0"></a>&nbsp;<a href="'.$_SERVER['PHP_SELF'] . '?flibble=delete_random&id='.$row['id'].'"><img src="images/admin/delete.gif" alt="Delete" border="0"></a></TD></TR>';
            if($count == 2){
                $count = 0;
            }   
     }
    
        /* finish up table*/
        echo "</TABLE><center>\n";
        
                if($page != 1){
        $pageprev = $page-1;        
        echo '<a href="admin3.php?flibble=random&page='.$pageprev.'">Previous</a>&nbsp;&nbsp;';
    }else{
        echo 'Previous&nbsp;&nbsp;';
    }
 
    $numofpages = $totalrows / $limit;
    
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo $i.' ';
        }else{
            echo '&nbsp;<a href="admin3.php?flibble=random&page='.$i.'">'.$i.'</a>&nbsp;';
        }
    }
    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo $i.' ';
        }else{
            echo '&nbsp;<a href="admin3.php?flibble=random&page='.$i.'">'.$i.'</a>&nbsp;';
        }
    }
    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page+1;
         
        echo '&nbsp;&nbsp;<a href="admin3.php?flibble=random&page='.$pagenext.'">Next</a>';
    }else{
        echo '&nbsp;&nbsp;Next';
    }
    mysql_free_result($result);
    echo '</center>';
        
        echo '<p><b><a href="http://runehints.com/admin3.php?flibble=add_random"><img src="images/plus.gif" alt="Add" border="0"> Add a Random Event guide</a></b></p>';
}
 
function update_random($id) {
 
if (isset($_POST['preview'])){  //handle form 
    $name = $_POST['name'];
    $contributors = $_POST['contributors'];
    $guideby = $_POST['guideby'];
    $members = $_POST['members'];
    $guide = $_POST['guide'];
    
    
    if ($members = "Y") {
        $mem = "members only Random Event</b>, so it can only be done on a <b>members</b> server.";
    }else{
        $mem = "non-members Random Event</b>.";
    }
    if ($updated == 0){
    $up = 'No-one has updated this Random Event guide'; 
    }else{  
    $date2 = date("l jS of F Y @ H:i:s ", $updated);
    $up = 'It was last updated on '.$date2.'.';
    }
    if ($contributors != ""){
    $con = 'Thanks also to <b>'.$contributors.'</b> for changes.';  
    }else{
    $con = 'No-one else has contributed to this Random Event guide';
    }
    //$date = date("D M jS, Y g:i a", $added);
    $date = date("l jS of F Y @ H:i:s ", $added);
    
echo '
<p class="spheader">'.$name.'</p>
<p>This Random Event guide was written by <b>'.$guideby.'</b> for use on Runehints. '.$con.'  <br /></p>
<p class="small2"><br />This Random Event is <b>'.$mem.'</p>
<p>
<span class="titles">Random Event:</span></p>
<div id="Map">
<p>
   <?php echo $guide; ?>
</p></div>
<?php 
echo '
;
 
}
 
if (isset($_POST['submit'])){  //handle form 
    require_once ('../mysql_connect.php');//connect to db
    $name = $_POST['name'];
    $guideby = $_POST['guideby'];   
    $members = $_POST['members'];
    $guide = $_POST['guide'];
    $contributors = $_POST['contributors'];
    $updated = time();
    $sorter = $_POST['sorter'];
    
            if ($name){//if evrything is ok                         
                    
                
 
                    $query = "UPDATE random SET name='".$name."', updated='".$updated."', guideby='".$guideby."', contributors='".$contributors."', members='".$members."', mainbody='".$guide."', sorter='".$sorter."' WHERE id='".$id."'";
                    $result = mysql_query ($query); //Run the query.
                    
                    if ($result){ //if it entered correctly   
                        echo '<br /><table width=98% bgcolor=#C6F4DF class=pass align=center><tr>
                                        <td width=40><img src=images/tick.gif></td>
                                        <td align=left>
                                        <B>Success</B> <BR>
                                        The Random Event guide for '.$name.' was successfully updated<br />                         
                                        </table><br /><br />';
                        include ('difffooter.inc');//footer
                        exit();
                    }else{ // didn't work         
                        echo '<table width=98% bgcolor=#faf5f4 class=logfail align=center><tr>
                                    <td width=40><img src=images/exclamation.gif></td>
                                    <td align=left>
                                    <B>Update Failed!</B> <BR>
                                    The Random Event guide for '.$name.' could not be updated
                                    <BR>Please Try again later<br />
                                    </table><br /><br />';
                                    //Name: '.$name.' Updated: '.$updated.' Contributors: '.$contributors.'  By: '.$guideby.' Members: '.$members.' Guide: '.$guide.'
                    }       
 
            }
}
 
 
   /* query for item */
    $query = "SELECT * FROM random WHERE id=".$id;
    $result = mysql_query ($query);
    
    /* if we get no results back, error out */
    $numrtn = mysql_num_rows($result);
 
    if ($numrtn == 0) {
        echo "The guide requested cannot be found\n";
        return;
    }
    $row = mysql_fetch_assoc($result);
    /* easier to read variables and 
     * striping out tags */
        $nid = $id;  
        $title = $row['name'];
        $guideby = $row['guideby'];
        $members = ucwords($row['members']);
        $guide = $row['mainbody'];
        $sorter = $row['sorter'];
 
 
 
 
 
 
 
echo '<br /><font class="adminheader"><center>Update Random Event guide</center></font><br />
Here you can update an existing Random Event guides in the database.<br />
    <center><form action="admin3.php?flibble=update_random&id='.$nid.'" method="post">
    
    <table class=calc>
    <tr><td>
    <table>
 
    <tr><td align=right><font class="text2">Random Event Name:</font></td><td align=left><input type="text" class="text" name="name" size="15" maxlength="30" value="'.$title.'" /></td></tr>   
    
    <tr><td align=right><font class="text2">Guide Written by:</font></td><td align=left><input type="text" class="text" name="guideby" size="15" maxlength="30" value="'.$guideby.'" /></td></tr>   
    
    <tr><td align=right><font class="text2">Members?:</font></td><td align=left><input type="text" class="text" name="members" size="1" maxlength="1" value="'.$members.'<font class="small2">Use Y or N only</font></td></tr>  
 
    <tr><td align=right><font class="text2">Main Guide:</font></td><td align=left><textarea name="guide" cols="50" rows="18" wrap=physical>'.$guide.'</textarea></td></tr>  
 
    <tr><td align=right><font class="text2">Contributors:</font></td><td align=left><input type="text" class="text" name="contributors" size="30" maxlength="255" value="'.$contributors.'" /></td></tr>    
    
    <tr><td align=right><font class="text2">Sort name:</font></td><td align=left><input type="text" class="text" name="sorter" size="30" maxlength="255" value="'.$sorter.'" /><font class="small2">This is the name of the Random Event without spaces or the leading "The" if it has one.</font></td></tr>    
    </table>
    </td>
    </tr>
    <tr>
    <td>
    <div align="center"><input type="submit" name="submit" value="Update Random Event Guide" class="liteoption"/>&nbsp;<input type="submit" name="preview" value="Preview" class="liteoption"/>&nbsp;<input type="reset" name="reset" value="reset" class="liteoption" /></div>
    </td>
    </tr>
    </table>
</CENTER>
    </form>';
    
}
 
 
function add_random() {
 
if (isset($_POST['preview'])){  //handle form 
    $name = $_POST['name'];
    $contributors = $_POST['contributors'];
    $guideby = $_POST['guideby'];
    $members = $_POST['members'];
    $guide = $_POST['guide'];
    
    
    if ($members = "Y") {
        $mem = "members only Random Event</b>, so it can only be done on a <b>members</b> server.";
    }else{
        $mem = "non-members Random Event</b>.";
    }
    if ($updated == 0){
    $up = 'No-one has updated this Random Event guide'; 
    }else{  
    $date2 = date("l jS of F Y @ H:i:s ", $updated);
    $up = 'It was last updated on '.$date2.'.';
    }
    if ($contributors != ""){
    $con = 'Thanks also to <b>'.$contributors.'</b> for changes.';  
    }else{
    $con = 'No-one else has contributed to this Random Event guide';
    }
    //$date = date("D M jS, Y g:i a", $added);
    $date = date("l jS of F Y @ H:i:s ", $added);
    
echo '
<p class="spheader">'.$name.'</p>
<p>This Random Event guide was written by <b>'.$guideby.'</b> for use on Runehints. '.$con.'  <br /></p>
<p class="small2"><br />This Random Event is <b>'.$mem.'</p>
  <p class="small2">'.$guide.'</p>'
 
;
 
}
 
if (isset($_POST['submit'])){  //handle form; 
    require_once ('../mysql_connect.php');//connect to db
    $name = $_POST['name'];
    $guideby = $_POST['guideby'];   
    $members = $_POST['members'];
    $guide = $_POST['guide'];
    $added = time();
    $sorter = $_POST['sorter'];
    
            if ($name){//if evrything is ok                         
                    
                
 
                    $query = "INSERT INTO random (name, added, guideby, members, mainbody, sorter) VALUES ('$name', '$added', '$guideby', '$members', '$guide', '$sorter')";
                    $result = mysql_query ($query); //Run the query.
                    
                    if ($result){ //if it entered correctly   
                        echo '<br /><table width=98% bgcolor=#C6F4DF class=pass align=center><tr>
                                        <td width=40><img src=images/tick.gif></td>
                                        <td align=left>
                                        <B>Success</B> <BR>
                                        The Random Event guide for '.$name.' was successfully added<br />                           
                                        </table><br /><br />';
                        include ('difffooter.inc');//footer
                        exit();
                    }else{ // didn't work         
                        echo '<table width=98% bgcolor=#faf5f4 class=logfail align=center><tr>
                                    <td width=40><img src=images/exclamation.gif></td>
                                    <td align=left>
                                    <B>Update Failed!</B> <BR>
                                    The Random Event guide for '.$name.' could not be added
                                    <BR>Please Try again later<br />                                    
                                    </table><br /><br />';
                                    
                    }       
 
            }
}
 
?>
 
<br /><font class="adminheader"><center>Add Random Event guides</center></font><br />
Here you can add Random Event guides to the database.<br />
    <form action="admin3.php?flibble=add_random" method="post"><center>
    <table class=calc>
    <tr><td>
    <table>
 
    <tr><td align=right><font class="text2">Random Event Name:</font></td><td align=left><input type="text" class="text" name="name" size="15" maxlength="50" value="<?php if (isset($_POST['name'])) echo stripslashes($_POST['name']); ?>" /></td></tr>   
    
    <tr><td align=right><font class="text2">Guide Written by:</font></td><td align=left><input type="text" class="text" name="guideby" size="15" maxlength="30" value="<?php if (isset($_POST['guideby'])) echo stripslashes($_POST['guideby']); ?>" /></td></tr>   
    
    <tr><td align=right><font class="text2">Members?:</font></td><td align=left><input type="text" class="text" name="members" size="1" maxlength="1" value="<?php if (isset($_POST['members'])) echo stripslashes($_POST['members']); ?>" /><font class="small2">Use Y or N only</font></td></tr>  
 
    <tr><td align=right><font class="text2">Main Guide:</font></td><td align=left><textarea name="guide" cols='50' rows='18' wrap=physical><?php if (isset($_POST['guide'])) echo stripslashes($_POST['guide']); ?></textarea>&nbsp;<font class="small2"> When including, bold, italics, images etc. Please use <a href="html.php" target="_blank">HTML</a></font></td></tr>    
    
    <tr><td align=right><font class="text2">Sort Name:</font></td><td align=left><input type="text" class="text" name="sorter" size="30" maxlength="255" value="<?php if (isset($_POST['sorter'])) echo stripslashes($_POST['sorter']); ?>" /><font class="small2">This is the name of the Random Event without spaces or the leading "The" if it has one.</font></td></tr>     
    </table>
    </td>
    </tr>
    <tr>
    <td>
    <div align="center"><input type="submit" name="submit" value="Add Random Event Guide" class="liteoption" />&nbsp;<input type="submit" name="preview" value="Preview" class="liteoption" />&nbsp;<input type="reset" name="reset" value="reset" class="liteoption" /></div>
    </td>
    </tr>
    </table>
</CENTER>
    </form>
        <?php
}
 
function delete_random($id){
 
$query = "SELECT `name` FROM random WHERE id=$id";
    $result = mysql_query ($query);
   
    /* if we get no results back, error out */
$numrtn = mysql_num_rows($result);
 
    if ($numrtn == 0) {
        echo "The quest guide requested cannot be found\n";
        return;
    }
    $row = mysql_fetch_assoc($result);
    /* easier to read variables and
     * striping out tags */
        $name = $row['name'];
if (isset($_POST['yes'])){  //handle form           
$query = "DELETE FROM `random` WHERE `id` = ".$id." LIMIT 1";
$result = mysql_query($query);
 
    if ($result) {
        ob_end_clean();
                header("http://runehints.com/admin3.php?flibble=random");   
                exit();     
    }
}
 
if (isset($_POST['no'])) {
        ob_end_clean();
        header("http://runehints.com/admin3.php?flibble=random");     
        exit();       
}
       
echo '<table width=98% bgcolor=#faf5f4 class=logfail align=center><tr>
 
                                                                        <td width=40><img src=images/exclamation.gif></td>
                                                                        <td align=left>
                                                                        <B>Delete?</B> <BR>
                                                                        Are you sure you want to delete '.$name.' from the database?
                                                                        <BR><br /><form action="admin3.php?flibble=delete_random&id='.$id.'" method="post"><input type="submit" name="yes" value="Yes" class="delete" />&nbsp;<input name="no" type="submit" value="No" class="delete" /></form>
                                                                        </table><br /><br />';
 
 
}
 
//------------------------End Random Event-------------------------------------------//
 
switch($_GET['flibble']) {
 
        //---random---//
    case 'random':
        random();
        break;
    case 'add_random':
        add_random();
        break;
    case 'update_random':
        update_random($_GET['id']);
        break;
    case 'delete_random':
        delete_random($_GET['id']);
        break;
 
 
}
 include('difffooter.inc');
 }
 
 ?>
Fatal error: Call to undefined function random() in /home/gaogier/public_html/admin4.php on line 404
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Fatal error: Call to undefined function

Post by andym01480 »

Would that be because of line 18 - a typo?

Code: Select all

function racndom(){
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Re: Fatal error: Call to undefined function

Post by gaogier »

Yeah, thanks

It now wont let me get to the form where i add the guide/artical... not sure why, any ideas?
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Fatal error: Call to undefined function

Post by andym01480 »

Don't know - I commented out the includes and login section and the admin3.php?flibble=add_random showed the form.

What's not working?


BTW -
Line 99

Code: Select all

if (isset($_POST['preview'])){
would be better as

Code: Select all

if($_POST['preview']=='Preview"){
because IE might miss it if enter is pressed rather than a mouse click.
Similarly Line 282 for the submit
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Re: Fatal error: Call to undefined function

Post by gaogier »

I found out the problem

i feel stupid again...

it was using a page that didnt have the coding, admin3.php should of been admin4.php there are a few in that line of code, works great now...

i have to go, but could someone reply, so i can carry on fixing errors in my php coding in the morning?
Post Reply