October 16, 201214 yr iv built a cms and my edit_blog page isnt liking when i hit my save button. im getting the following message Notice: Undefined index: blogID in C:\xampp\htdocs\nurd\admin\edit_blog.php on line 27 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 <?php session_start(); include "connection.php"; if(!isset($_POST['submit'])) { $q = "SELECT * FROM cmsblog WHERE blogID = $_GET[blogID]"; $result = mysql_query($q); $row = mysql_fetch_array($result); } ?> <h1>Edit Page</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Page Name: <input type="text" name="inputTitle" value="<?php echo $row['blogTitle']; ?>" /><br /> <br /> Content:<br /> <textarea name="inputContents" cols="100" rows="25"><?php echo $row['blogContents']; ?></textarea> <br /> <input type="hidden" name="id" value="<?php echo $_GET['blogID']; ?>" /> <input type="submit" name="submit" value="Save" /> </form> <?php if (isset($_POST['submit'])) { $u = "UPDATE pages SET `blogTitle`='$_POST[inputTitle]', `blogContents`='$_POST[inputContents]' WHERE blogID = $_POST[blogID]"; mysql_query($u) or die (mysql_error()); echo "Successful! Blog has been updated"; header("Location: controlpanel.php"); } ?> Edited October 16, 201214 yr by dpuk44
October 16, 201214 yr Pal you need to read into sql injection protection and before you put that code online Hackers will be able to run there own sql commands with out protection Edited October 16, 201214 yr by motters
October 16, 201214 yr iv built a cms and my edit_blog page isnt liking when i hit my save button. im getting the following message Notice: Undefined index: blogID in C:\xampp\htdocs\nurd\admin\edit_blog.php on line 27 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 <?php session_start(); include "connection.php"; if(!isset($_POST['submit'])) { $q = "SELECT * FROM cmsblog WHERE blogID = $_GET[blogID]"; $result = mysql_query($q); $row = mysql_fetch_array($result); } ?> <h1>Edit Page</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Page Name: <input type="text" name="inputTitle" value="<?php echo $row['blogTitle']; ?>" /><br /> <br /> Content:<br /> <textarea name="inputContents" cols="100" rows="25"><?php echo $row['blogContents']; ?></textarea> <br /> <input type="hidden" name="id" value="<?php echo $_GET['blogID']; ?>" /> <input type="submit" name="submit" value="Save" /> </form> <?php if (isset($_POST['submit'])) { $u = "UPDATE pages SET `blogTitle`='$_POST[inputTitle]', `blogContents`='$_POST[inputContents]' WHERE blogID = $_POST[blogID]"; mysql_query($u) or die (mysql_error()); echo "Successful! Blog has been updated"; header("Location: controlpanel.php"); } ?> If you have a simple question like this ex-specially saying how to fix it. thats probably an indication you need to study php more before trying to build something like a CMS your code is not secure at all like mentioned above.
Create an account or sign in to comment