April 3, 200917 yr 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
April 3, 200917 yr 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(); } } ?>
April 3, 200917 yr 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