Jump to content

Notice: Undefined index:


happypete

Recommended Posts

I'm getting the following errors:

 

Notice: Undefined index: field

Notice: Undefined index:content

 

I'm getting a Status 200 and the content is passed:

 

content zbzbfff<br>

field text1

 

 

so I cant work out why it says there are undefined index???

 

------------------------------------------------------

error message:

<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: field in C:\wamp\www\archive\SmallProjects\cke-backup\save.php on line <i>9</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0007</td><td bgcolor='#eeeeec' align='right'>369704</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\archive\SmallProjects\cke-backup\save.php' bgcolor='#eeeeec'>..\save.php<b>:</b>0</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: content in C:\wamp\www\archive\SmallProjects\cke-backup\save.php on line <i>13</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0007</td><td bgcolor='#eeeeec' align='right'>369704</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\archive\SmallProjects\cke-backup\save.php' bgcolor='#eeeeec'>..\save.php<b>:</b>0</td></tr>
</table></font>
OK
<?php

ini_set('display_errors',1);
error_reporting(E_ALL);


include('inc/db.php');
// Extract details from database
$stmt = $db->prepare("SELECT * FROM data WHERE id=1");
$stmt->execute();
$e = $stmt->fetch();

$edit = "yes";
?>

<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta name="author" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
      <link rel="stylesheet" href="stylesheets/base.css">
    <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <!-- Favicons
    ================================================== -->
    <link rel="shortcut icon" href="images/favicon.ico">
    <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
    <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
    <link href='http://fonts.googleapis.com/css?family=Coming+Soon' rel='stylesheet' type='text/css'>
    <script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-#######-##']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script></head>
<body onLoad="initialize()">


    <!--[if lte IE 9]><script src="js/respond.js"></script><![endif]-->

    <!-- ================================================== -->


<div class="container">

    <div class="sixteen columns">
    
    <div id="message"></div>
                    
        <p><a id="vacationrentalbariloche"></a></p>
        <p> </p>
        <h1 <?php if ($edit == "yes") {  echo 'contenteditable="true" rel="text1"';} ?>>
        <?php echo html_entity_decode(stripslashes($e['text1'])) ?></h1>
        
        <h5 <?php if ($edit == "yes") {  echo 'contenteditable="true" rel="text2"';} ?>>
        <?php echo html_entity_decode(stripslashes($e['text2'])) ?></h5>

</div><!-- container -->
        
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
        <!--<script src="jquery 1.9.0.js"></script>-->
<script src="ckeditor/ckeditor.js"></script>
<script src="ckeditor/customize-toolbar.js"></script>
<script src="saving.js"></script>
        
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
        <script src="js/pikadate.js"></script>
        <script src="js/all.js"></script>

</body>
</html>

saving.js:

// JavaScript Document

			/* This bit of code saves the editable area every 60 seconds when it is being edited, but I also want it so be saved when the user deselects the text area & it need to save multiple editable areas - only save the editable area that is being edited or was selected, DON'T save all editbale areas at once just the one being edited at the time. */

			/* provide feedback to use that content saved when deselected 'content saved message' and every 60 seconds 'autosave message' */
			/* instance will be created for every element, and for every element we will set listeners for focus and blur events */
			/* when element is in focus, interval is set, to save data every 60 sec. Beside that, we will keep interval ID to destroy him once element is blured */
			CKEDITOR.on(
				"instanceReady", function(event) {
					var element=event.editor.element.$;
					$(element).on("focus", function(){
						var intervalID=setInterval(function(){
							saveData($(this), true);
						}, 30000);  // 30000 = 30 seconds autosave
						$(this).data("intervalID", intervalID);
					});

					$(element).on("blur", function(){
						var intervalID=parseInt($(this).data("intervalID"), 10);
						clearInterval(intervalID);
						saveData($(this), false);
					});
				}
			);
			
			//function saves data from CKEditor into the database, element is jQuery element that contain data that needs to be saved
			//auto is just a flag that tells us what message to display after save - "autosave" or "update"
			function saveData(element, auto)
			{
				$.ajax({
					method:"post",
					url:"save.php",
					data:{"field":element.attr("rel"), "content":element.html()},
					success: function(status){
						if(status==="OK")
						{
							var message;
							if(auto===true)
							{
								message="Autosave completed";
							}
							else
							{
								message="Saved";
							}
							
							$('#message').html(message).stop().hide().fadeIn(200).fadeOut(2500);
						}
						else
						{
							alert(status);
							//alert("Error: System cannot save your changes");
						}
					}
				});
			}

and the PHP - save.php

<?php

include('inc/db.php');

// Update data 
$sql = "UPDATE data SET ".$_POST['field']."=:content WHERE id=1"; 


$stmt = $db->prepare($sql);
$content=$_POST['content'];
$stmt->bindParam(":content", $content);
$stmt->execute();
$stmt->closeCursor();

echo "OK";
return;

?>
Link to comment
https://forums.phpfreaks.com/topic/286742-notice-undefined-index/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.