Nexy Posted June 1, 2008 Share Posted June 1, 2008 Why Hello There! I seem to be having a problem with insertion. I don't see what's the problem. <?php $news = mysql_real_escape_string($_POST['text']); $news = nl2br($_POST['text']); $title = mysql_real_escape_string($_POST['title']); $set = "1"; $date = date('m-j-Y'); if($_POST['subnews'] && !empty($news) && !empty($title)) { if($_SESSION['username']) { mysql_query("INSERT INTO news(user, subject, date, news) VALUES ('".$_SESSION['username']."', '$title', '$date', '$news')"); $set = "2"; } else if($_COOKIE['user']) { mysql_query("INSERT INTO news(user, subject, date, news) VALUES ('".$_COOKIE['user']."', '$title', '$date', '$news')"); $set = "2"; } } if($_SESSION['username'] || $_COOKIE['user']) { echo "<form action='#' method='post'> <fieldset id='account'> <legend>You can add news in here:</legend> <p style='color: white'>HTML format codes are allowed.</p> <label for='title'>Title:</label> <input type='text' id='title' name='title' tabindex='6' style='width: 200px' /> <p /> <label for='text'>News:</label><br /> <textarea id='text' name='text' rows='10' cols='40' tabindex='7'></textarea> <br /> <input type='submit' id='subnews' name='subnews' value='Add News' /> <input type='reset' value='Clear News' /> </fieldset> </form>"; } else { include("includes/error.php"); } ?> Ok, the problem is, it only Inserts once. When I click submit again with something in there, it doesn't insert anything. Also, for some reason, the field called 'id'(primary key) starts off at 0, when with some other of my tables, id starts off at 1. Any idea what may be wrong? Thank You! Quote Link to comment https://forums.phpfreaks.com/topic/108263-solved-insert-problem/ Share on other sites More sharing options...
EXiT Posted June 1, 2008 Share Posted June 1, 2008 Can you post your database table Quote Link to comment https://forums.phpfreaks.com/topic/108263-solved-insert-problem/#findComment-555028 Share on other sites More sharing options...
EXiT Posted June 1, 2008 Share Posted June 1, 2008 Have you set the id field to AUTO_INCREMENT? And put ' or die(mysql_error()) ' before the ';' at the end of both your mysql_query()'s Quote Link to comment https://forums.phpfreaks.com/topic/108263-solved-insert-problem/#findComment-555030 Share on other sites More sharing options...
.josh Posted June 1, 2008 Share Posted June 1, 2008 is this script being included in some other script? because I see you using session variables but no session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/108263-solved-insert-problem/#findComment-555031 Share on other sites More sharing options...
Nexy Posted June 1, 2008 Author Share Posted June 1, 2008 Thank You! I forgot to set it to auto_increment. To answer all those questions: I did put "or die(mysql_error());" and it is being included from another script. Thank you once again, it works! Quote Link to comment https://forums.phpfreaks.com/topic/108263-solved-insert-problem/#findComment-555153 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.