<?php session_start(); require("db.php"); require("functions.php"); if(isset($_SESSION['USERNAME']) == TRUE) { if($_POST['submit']) { $sql = "INSERT INTO mod_entry(cat_id, title, description, link, date, user_id) VALUES(" . $_POST['cat'] . ",'" . $_POST['title'] . "','" . $_POST['description'] . "','" . $_POST['link'] ."',NOW()," . $_SESSION['USERID'] .");"; mysql_query($sql); header("Location: " . $basedir); } else { require("header.php"); ?> <h1>Add Tutorial</h1> <form action="addtutorial.php" method="POST"> <table cellpadding="5"> <tr> <td>Category</td> <td> <select name="cat"> <option value='select' selected>Select a Category</option> <?php $catsql = "SELECT * FROM categories;"; $catres = mysql_query($catsql); while($catrow= mysql_fetch_assoc($catres)) { echo "<option value='" . $catrow['id'] . "'>" . $catrow['name'] . "</option>"; } ?> </select> </td> </tr> <tr> <td>Title</td> <td><input type="text" name="title"></td> </tr> <tr> <td>Description</td> <td><textarea name="description" rows="10" cols="50"></textarea></td> </tr> <tr> <td>Link</td> <td><input type="text" name="link"></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Add Tutorial"></td> </tr> </table> </form> <?php } } require("footer.php"); ?> PHP: when users fill the form and click submit button, the same file is again called and if statement get executed and values should get inserted into database, then it should redirect to the $basedir,,,, but when i click submit, the page is taking to $basedir, but the values are not get inserted into database,,, what is the problem
Edit your query to this: $sql = "INSERT INTO `mod_entry` (`cat_id`, `title`, `description`, `link`, `date`, `user_id`) VALUES('" . $_POST['cat'] . "', '" . $_POST['title'] . "', '" . $_POST['description'] . "', '" . $_POST['link'] . "', NOW(), '" . $_SESSION['USERID'] . "');"; mysql_query($sql) or die(mysql_error()); PHP:
first if(isset($_SESSION['USERNAME'])) Code (markup): is not important to wrtite == TRUE this will work if(isset($_SESSION['USERNAME'])) Code (markup):