darksniperx Posted October 22, 2007 Share Posted October 22, 2007 I havent done any changes to my php class files, I was working on tidying up my html form code, then when I test my website out, I get Fatal error: Cannot instantiate non-existent class:fusion ... line 15 <?php class forms { var $script; //temporary variables to use with forms var $js_script; var $css_script; var $body_onload_content; var $body_content; function forms() { $this->script = new fusion; ... the thing is that the code worked, did not do any changes to it "I think". What can I look for to find the cause of the problem. My php is 4.3.9. thx. Quote Link to comment https://forums.phpfreaks.com/topic/74358-solved-what-to-look-for-when-i-get-fatal-error-cannot-instantiate-non-existent-class/ Share on other sites More sharing options...
trq Posted October 22, 2007 Share Posted October 22, 2007 You need to make sure the class fusion is defined somewhere within scope. Quote Link to comment https://forums.phpfreaks.com/topic/74358-solved-what-to-look-for-when-i-get-fatal-error-cannot-instantiate-non-existent-class/#findComment-375793 Share on other sites More sharing options...
darksniperx Posted October 22, 2007 Author Share Posted October 22, 2007 I found the cause of the problem. now what to do to fix it. here is my index page <?php include ("forms.php"); $webForm = "Entry"; //specify which form you want to work with $form = new forms; // create an instance of selected class $form->setFormData($webForm); // populate class variables selected form ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Content-Script-Type" content="text/javascript; charset=UTF-8;" /> <title>Index Page!</title> <?php $form->outputHeaderData(); // echo any content in the head section ?> </head> <body <?php $form->ouputBodyAttributeData(); // echo any content that is suppose to be in body tag ?>> <?php $form->outputForm(); // echo any content in the body section ?> </body> </html> forms.php includes the requested form contained in a different php file and then echoes it with <?php class forms { var $script; //temporary variables to use with forms var $js_script; var $css_script; var $body_onload_content; var $body_content; function forms() { include 'fusion.php'; $this->script = new fusion; //when form is being submitted, the following verifyies which form then loads appropriate methods. if($_POST['form_feed_submit']) { $this->formFeed_submit(); } } //sets variable data that will be later used in the forms function setFormData($formName) { include $formName . '.php'; include '../scripts/' . $formName . '_js_script.php'; $this->js_script = 'show' . $formName . 'JS'; $this->body_onload_content = "onload='loader();'"; $this->body_content = 'show'.$formName; } //outputs data that is suppose to be in header tag function outputHeaderData() { echo "<script type='text/javascript'>"; echo "\n"; $x = $this->js_script; $x(); echo "</script>"; echo "\n"; } //output data inside body tag function ouputBodyAttributeData() { echo $this->body_onload_content; } //writes form data to html file for the requested form function outputForm() { $x = $this->body_content; $x(); } //prints the data from category table with check boxes function printCategoryBoxes() { $this->script->dbConnect(); $this->script->selectDb(); $category = mysql_query("SELECT * FROM category") OR die(mysql_error()); while($cat = mysql_fetch_array($category)) { echo "<label><input type='checkbox' name='cat_id[]' value='".$cat['cat_id']."'/>".$cat['c_label']."</label>"; } $this->script->closeDbConnection(); } the php file of the content that is being submitted. <?php function showEntry() { ?> <form method="post" action="<?php print $_SELF; ?>" onsubmit="validator()"> <h1>Welcome to Fusion Project!</h1> <h3>You are about to create a news entry.</h3> <h3>Remember that <font color='red'>*</font> means that the field is required and if you are an <u>advanced user</u><br/> you can press <u>advanced button</u> to add a variety of options and other usefull information.</h3> <hr /> <p><font color='red'>*</font><strong>Story Title <font size="-1">(Please enter a descriptive title for the story you're linking to.)</font></strong></p> <p> <input type='text' name='title_text' size="100" /> </p> <p><font color='red'>*</font><strong>Story Description <font size="-1">(Write your own description of the news story.)</font></strong></p> <p> <textarea cols="75" rows="5" name="content_text" ></textarea> </p> <font color='red'><strong>*</strong></font><strong>Story Link <font size="-1">(Link that points to the source of the story.)</font></strong> <p> <input type='text' name='l_href' size="100" /> </p> <strong><font color="#FF0000">*</font>Categories:</strong> <p> <?php $newForm = new forms; //*** this line creates problem $form->printCategoryBoxes();//print checkboxes ?> when I call $newForm = new forms; in php html file I get Fatal error: Cannot redeclare class fusion in /home/public_html/alex/test/fusion.php on line 3 fusion class <?php class fusion { VAR $CON,$SQL; VAR $database_location = 'localhost'; ... dont know what to do. Quote Link to comment https://forums.phpfreaks.com/topic/74358-solved-what-to-look-for-when-i-get-fatal-error-cannot-instantiate-non-existent-class/#findComment-375837 Share on other sites More sharing options...
btherl Posted October 23, 2007 Share Posted October 23, 2007 Try include_once instead of include Quote Link to comment https://forums.phpfreaks.com/topic/74358-solved-what-to-look-for-when-i-get-fatal-error-cannot-instantiate-non-existent-class/#findComment-375878 Share on other sites More sharing options...
darksniperx Posted October 23, 2007 Author Share Posted October 23, 2007 you change everywhere include to include_once Quote Link to comment https://forums.phpfreaks.com/topic/74358-solved-what-to-look-for-when-i-get-fatal-error-cannot-instantiate-non-existent-class/#findComment-375892 Share on other sites More sharing options...
darksniperx Posted October 23, 2007 Author Share Posted October 23, 2007 nice it works now. I should have studied more about include tag, only if I knew. include_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc. Quote Link to comment https://forums.phpfreaks.com/topic/74358-solved-what-to-look-for-when-i-get-fatal-error-cannot-instantiate-non-existent-class/#findComment-375912 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.