Hey guys; keep having trouble with these blasted index errors!! :evilgrin:
Anyway heres the code im having problems with....


<?php
	if($_POST)
	{
		include('../scripts/session_a.php');
		include('connection.php');


	$categoryname = $_POST['categoryname'];


	if(empty($categoryname))
	{
		echo 'Category name is required';
	}		
	else
	{

		$categoryname = strip_tags($categoryname);
		$categoryname = mysql_real_escape_string($categoryname);

		$sql = mysql_query("INSERT INTO categories (category_name,created_by,created_on))
		VALUES ('$categoryname','$session_name',now())") or die(mysql_error());

		if($sql)
		{
			$fetch = mysql_query("SELECT * FROM categories ORDER BY id DESC") or die (mysql_error());
			while($row = mysql_fetch_array($fetch))
			{
				extract($row);
				echo '<div class="form-elements>
				<input type=checkbox" name="categorycreate[]" value="'.$category_name.'" id="categorycreate"/> Category 1'.$category_name.'</div>';
			}
		}
	}



}

?>

The index error that gets presented to me is as follows; Undefined index: categoryname in C:\wamp\www\AbsoluteBeginners\PHPLogin\admin\scripts\create-cat.php on line 9

If anyone has a solution or need me to supply the "include" files then let me know
Thanks
Alex 😃

    Your $_POST['categoryname'] variable does not exist. I assume some kind of form is being submitted before this code is executed. Check your form for 'categoryname'. Make sure form elements have a name attribute; PHP requires this. Also make sure the form's method is post.

      And just because $POST is set (and you should be using [man]isset[/man] to check that), don't just assume that $POST['categoryname'] is set as well.

        Hiya; heres the other code that is linked to the script above:

        create-posts.php (contains all the divs etc)

        <!--////////////////////////////////////////////////////////
        // Project : Absolute Beginners log in system ///////////
        // Purpose : A2 Level Coursework for ICT ////////////////
        // Teacher : Mr L Hawkins ///////////////////////////////
        // Student : Alex Sims //////////////////////////////////
        // Candidate No. : 4173 /////////////////////////////////
        // Centre No : 27168 ////////////////////////////////////
        /////////////////////////////////////////////////////////-->
        
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"/></script>
        <script type="text/javascript" src="javascript/create-cat.js"/></script>
        <script type="text/javascript" src="javascript/custom.js"/></script>
        
        <?php include_once('includes/header.php') ; ?>
        <?php include_once('scripts/session_a.php') ; ?>
        <?php include_once ('includes/posts-header.php')?>
        
        <script type="text/javascript" >
           $(document).ready(function() {
        	  $("#markItUp").markItUp(mySettings);
           });
        </script>
        
        
        
        
        		<div class="col-full">
        			<ul id="submenu">
        
        			</ul>
        			</ul>
        
        			</ul>
        		</div> <!-- end subheader -->
        		<!-- Start Main Div section -->
        		<div class="col-full">
        		<div id="leftsection">
        			<h2>Create Posts</h2>
        			<div class="form-elements">
        				<input type"text" name"title" placeholder="Add Title Here" id="title"/>
        
        		</div><!-- End of Left Section -->
        
        
        			<div class="form-elements">
        				<textarea id="markItUp" name"content"></textarea>
        			</div> <!-- Installed Text Editor -->
        
        			<div class="form-elements">
        				<input type"text" name"metatitle" placeholder="Meta Title" id="metatitle"/>
        		</div>
        
        		<div class="form-elements">
        				<input type"text" name"metadescription" placeholder="Meta Description" id="metadescription"/>
        		</div>
        
        		<div class="form-elements">
        				<input type"text" name"metarobots" placeholder="Meta Robots" id="metarobots"/>
        		</div>
        
        		<div class="form-elements">
        				<input type"text" name"metatags" placeholder="Meta Tags" id="metatags"/>
        		</div>
        
        		<div id="rightsection">
        			<h2>Categories</h2>
        
        			<div id="listcategores">
        				<div class="form-elements2">
        					<input type="checkbox" name="categoryname" value="" id="categoryname"/> Category 1
        		</div>
        				<div class="form-elements2">
        					<input type="checkbox" name="categoryname" value="" id="categoryname"/> Category 2
        		</div> <!-- end category list -->
        
        		<div id="createcat">
        <div class="form-elements">
        	   <input type="text" name="categorycreate" id="categorycreate" placeholder="Add New Category"/>
        		</div><!-- end createcat-->
        
        
        		<div class="clear"></div>
        
        
        </div><!--end mainWrapper-->
        
        </body>
        </html>
        

        create-cat.php (the script i had problems with above)

        <?php
        
        if(isset($_POST))
        {
        	include('../scripts/session_a.php');
        	include('connection.php');
        
        
        	$categoryname = $_POST['categoryname'];
        
        
        	if(empty($categoryname))
        	{
        		echo 'Category name is required';
        	}		
        	else
        	{
        
        		$categoryname = strip_tags($categoryname);
        		$categoryname = mysql_real_escape_string($categoryname);
        
        		$sql = mysql_query("INSERT INTO categories (category_name,created_by,created_on))
        		VALUES ('$categoryname','$session_name',now())") or die(mysql_error());
        
        		if($sql)
        		{
        			$fetch = mysql_query("SELECT * FROM categories ORDER BY id DESC") or die (mysql_error());
        			while($row = mysql_fetch_array($fetch))
        			{
        				extract($row);
        				echo '<div class="form-elements>
        				<input type=checkbox" name="categorycreate[]" value="'.$category_name.'" id="categorycreate"/> Category 1'.$category_name.'</div>';
        			}
        		}
        	}
        
        
        
        }
        
        ?>
        

        post-header

        <?php include ('javascript/posthead.js'); ?>		
        		<div id="subheader">
        			&nbsp;
        		<div class="col-full">
        
        
        			<ul id="submenu">
        
        			<li><a href="create-posts.php">Add New</a></li>
        			<li><a href="posts.php">View Posts</a></li>
        			<li><a href="categories.php">Manage</a></li>
        
        			<?php if(isset($_SESSION)); ?>
        
        			</ul>
        			</ul>
        
        			</ul>
        
        		</div> <!-- and col-full -->
        
        	</div>  <!-- enf sub header -->
        

        create-cat.js (the javascript file which I am having problem with)

        // Defines that we are calling a function//
        $(function(){
        			// 13 = the return key, when return is pressed inside the div "createcat" then trigger the function
        			$('#categorycreate').live("keypress",function(e){
        			if(e.which == 13) 
        
        		{
        		//Variable, inputbox is echoed through following post script when
        		//the value is equal to what is contained in the box.	
        			var categorycreate = $(this).val();
        
        		//Execute script once Return is pressed on keyboard
        		//Send a XMLHttpRequest to process the rest of procedure.	
        				if(window.XMLHttpRequest)
        			{
        				xmlhttp = new window.XMLHttpRequest //Variable
        			}
        			else
        			{
        				xmlhttp = new ActiveXObject ('Microsoft',XMLHTTP);
        			}
        
        			xmlhttp.onreadystatechange = function(){
        				if(xmlhttp.readyState == '4' && xmlhttp.status == '200')
        				{
        					response = xmlhttp.responseText;
        					$('#listcategores').html(response);
        					$('categorycreate').val('');
        				}
        
        			}
        		//Defines the parameters in use, Variable line 10.
        				parameters = 'categorycreate=' + categorycreate;
        
        		//Posts the information to the PHP script, create-cat.php
        				xmlhttp.open('POST','scripts/create-cat.php',true);
        				xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        				xmlhttp.send(parameters);
        		}
        
        
        	});
        
        });
        

        Hopefully with this information youll be able to see the links, I have already defined the class name 'categoryname' in my form elements table as you can see

        No idea where im going rong, same error still present!

        	</div>  <!-- enf sub header -->
          Write a Reply...