Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Notice: Undefined variable:

Featured Replies

Morning,

 

I am getting the following error message:

 

Notice: Undefined variable: result in /Applications/MAMP/htdocs/website.com/admin/index.php on line 71

 

Here is my PHP code:

 

<?php

include("config.php");

if (isset($_POST["submit"])) {
	$txt = $_POST['txt'];
	$txt = mysql_real_escape_string($_POST['txt']);

	$result = mysql_query("UPDATE content SET txt='$txt' WHERE id='1'", $db);
}

if ($result) {
echo "<meta http-equiv=Refresh content=0;url=index.php>";
} 

else {

$result = mysql_query("SELECT * from content WHERE id='1'", $db);	
while ($row=mysql_fetch_assoc($result)){

require('fckeditor/fckeditor.php');

				$oFCKeditor = new FCKeditor('txt');
				$oFCKeditor->BasePath	= 'fckeditor/';
				$oFCKeditor->Value		= $row['txt'];
				$oFCKeditor->Height	 = '300';
				$oFCKeditor->Create();

}

}

?>

 

Line 71 is the following:

 

if ($result) {

 

any ideas, what I've done wrong?

 

Cheers

DFT

Hi again DFT,

The problem stems from the location of the first $result variable.

It is inside the first if() clause and so will only exist IF the form has been submitted. You then call the variable outside of the if() before the form has been submitted and so the variable hasnt been created yet - giving you the error.

 

I would guess that moving the { on line 10 down to where the else is on line 16 would do the trick.

 

<?php

include("config.php");

if (isset($_POST["submit"])) {
	$txt = $_POST['txt'];
	$txt = mysql_real_escape_string($_POST['txt']);

	$result = mysql_query("UPDATE content SET txt='$txt' WHERE id='1'", $db);


if ($result) {
echo "<meta http-equiv=Refresh content=0;url=index.php>";
}

} else {

$result = mysql_query("SELECT * from content WHERE id='1'", $db);	
while ($row=mysql_fetch_assoc($result)){

require('fckeditor/fckeditor.php');

				$oFCKeditor = new FCKeditor('txt');
				$oFCKeditor->BasePath	= 'fckeditor/';
				$oFCKeditor->Value		= $row['txt'];
				$oFCKeditor->Height	 = '300';
				$oFCKeditor->Create();

}

}
?>

Hi again DFT,

The problem stems from the location of the first $result variable.

It is inside the first if() clause and so will only exist IF the form has been submitted. You then call the variable outside of the if() before the form has been submitted and so the variable hasnt been created yet - giving you the error.

 

I would guess that moving the { on line 10 down to where the else is on line 16 would do the trick.

 

<?php

include("config.php");

if (isset($_POST["submit"])) {
	$txt = $_POST['txt'];
	$txt = mysql_real_escape_string($_POST['txt']);

	$result = mysql_query("UPDATE content SET txt='$txt' WHERE id='1'", $db);


if ($result) {
echo "<meta http-equiv=Refresh content=0;url=index.php>";
}

} else {

$result = mysql_query("SELECT * from content WHERE id='1'", $db);	
while ($row=mysql_fetch_assoc($result)){

require('fckeditor/fckeditor.php');

				$oFCKeditor = new FCKeditor('txt');
				$oFCKeditor->BasePath	= 'fckeditor/';
				$oFCKeditor->Value		= $row['txt'];
				$oFCKeditor->Height	 = '300';
				$oFCKeditor->Create();

}

}
?>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.