This Code Not Working

Discussion in 'PHP' started by gr8webseller, Dec 6, 2009.

  1. #1
    <?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
     
    gr8webseller, Dec 6, 2009 IP
  2. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #2
    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:
     
    CoreyPeerFly, Dec 6, 2009 IP
  3. gr8webseller

    gr8webseller Peon

    Messages:
    1,097
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you very much, now it is working
     
    gr8webseller, Dec 6, 2009 IP
  4. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    first
    if(isset($_SESSION['USERNAME'])) 
    Code (markup):
    is not important to wrtite == TRUE
    this will work
    if(isset($_SESSION['USERNAME'])) 
    Code (markup):
     
    astkboy2008, Dec 6, 2009 IP