• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Undefined index: submit_form in C:\wamp\www\cms\private\youreditor.php on line 23

#1
[eluser]adamsonit[/eluser]
Code:
<?php
//This section should deal with the MagicQuotes and slashes
function nukeMagicQuotes() {
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value) {
$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
}
?>
<?php nukeMagicQuotes(); ?>
<?php  
  // Connect to the database
  $cnx = mysql_connect("localhost", "root", "")
         OR die("Unable to connect to database!");
  mysql_select_db("fckdata", $cnx);
  
  
  if ($_POST['submit_form'] == 1) {
    // Save to the database.
    $data = mysql_real_escape_string(trim($_POST['fcktext']));
    $res = mysql_query("UPDATE fck_data SET data = '".$data."' WHERE id = 1");
    
    if (!$res)
      die("Error saving the record!  Mysql said: ".mysql_error());
    
    // Redirect to self to get rid of the POST
    header("Location: youreditor.php");
  }

  include_once("../FCKeditor/fckeditor.php");
?&gt;<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;title&gt;Test FCKeditor&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<h1>Test FCKeditor</h1>

&lt;form action="youreditor.php" method="post"&gt;
&lt;?php
  // Get data from the database
  $query = mysql_query("SELECT data FROM fck_data WHERE id = 1");
  $data = mysql_fetch_array($query);

  // Configure and output editor
  $oFCKeditor = new FCKeditor('fcktext');
  $oFCKeditor->BasePath = "../FCKeditor/";
  $oFCKeditor->Value    = $data["data"];
  $oFCKeditor->Width    = 540;
  $oFCKeditor->Height   = 400;
  echo $oFCKeditor->CreateHtml();
?&gt;
<br />
&lt;input type="hidden" name="submit_form" value="1" /&gt;
&lt;input type="submit" value="Save Form" /&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;


&lt;?php
  // Close the database connection
  mysql_close($cnx);
?&gt;

#2
[eluser]TheFuzzy0ne[/eluser]
You're being very naughty and not checking that the post variable is set (isset()).
Code:
if (isset($_POST['submit_form']) && $_POST['submit_form'] == 1) {

The input class fixes this for you, but your code doesn't look like it's compatible with CodeIgniter...

If you need to use isset() lots of times throughout your code, you can export it to a function like this:
Code:
function get_post($index)
{
    return isset($_POST[$index]) ? $_POST[$index] : FALSE;
}
The above code is untested

And then you can use it like this:
Code:
if (get_post('submit_form') == 1) {


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.