emediastudios Posted November 11, 2008 Share Posted November 11, 2008 Can someone pick whats wrong with my code please if($_SESSION[passed] == "y"){ $id=$_POST['id']; $title=$_POST['title']; $date=$_POST['date']; $text=$_POST['text']; $query = "INSERT INTO news id='NULL', title='$title', date='$date', text='$text'"; $result = mysql_query($query) or die(mysql_error()); header("Location: admin.php"); } else{ echo "You Must Be Logged In To Do That"; } Quote Link to comment https://forums.phpfreaks.com/topic/132250-small-insert-problem/ Share on other sites More sharing options...
kenrbnsn Posted November 11, 2008 Share Posted November 11, 2008 Can you give us a hint? What's it doing? What's it supposed to do? A quick glance shows me that <?php query = "INSERT INTO news id='NULL', title='$title', date='$date', text='$text'"; ?> is incorrect, try <?php query = "INSERT INTO news SET id='NULL', title='$title', date='$date', text='$text'"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/132250-small-insert-problem/#findComment-687514 Share on other sites More sharing options...
emediastudios Posted November 11, 2008 Author Share Posted November 11, 2008 Parse error: syntax error, unexpected '=' in C:\Program Files\Apache Group\Apache2\htdocs\wg\wgp\news_edit.php on line 24 line 24 ---------- query = "INSERT INTO news SET id='NULL', title='$title', date='$date', text='$text'"; Quote Link to comment https://forums.phpfreaks.com/topic/132250-small-insert-problem/#findComment-687517 Share on other sites More sharing options...
kenrbnsn Posted November 11, 2008 Share Posted November 11, 2008 And which is line 24? The code snippet above doesn't have 24 lines in it. Ken Quote Link to comment https://forums.phpfreaks.com/topic/132250-small-insert-problem/#findComment-687519 Share on other sites More sharing options...
emediastudios Posted November 11, 2008 Author Share Posted November 11, 2008 line 24 ---------- query = "INSERT INTO news SET id='NULL', title='$title', date='$date', text='$text'"; Quote Link to comment https://forums.phpfreaks.com/topic/132250-small-insert-problem/#findComment-687520 Share on other sites More sharing options...
emediastudios Posted November 11, 2008 Author Share Posted November 11, 2008 anyone? Please!! Quote Link to comment https://forums.phpfreaks.com/topic/132250-small-insert-problem/#findComment-687522 Share on other sites More sharing options...
kenrbnsn Posted November 11, 2008 Share Posted November 11, 2008 The snippet of code you posted has no syntax errors, please post more of your code. Don't bump too often. Ken Quote Link to comment https://forums.phpfreaks.com/topic/132250-small-insert-problem/#findComment-687524 Share on other sites More sharing options...
emediastudios Posted November 11, 2008 Author Share Posted November 11, 2008 Stupid me, no $ in query But now i get this problem Out of range value adjusted for column 'id' at row 1 Quote Link to comment https://forums.phpfreaks.com/topic/132250-small-insert-problem/#findComment-687525 Share on other sites More sharing options...
kenrbnsn Posted November 11, 2008 Share Posted November 11, 2008 That's what happens when I post when I should be asleep. Ken Quote Link to comment https://forums.phpfreaks.com/topic/132250-small-insert-problem/#findComment-687526 Share on other sites More sharing options...
emediastudios Posted November 11, 2008 Author Share Posted November 11, 2008 <?php include_once('includes/include.php'); $password = "*******"; if($_POST[password] == "" && $_SESSION[passed] != "y"){ $content .= "<form method='post' action='admin.php'><input type='password' name='password' value='password'><input type=submit></form>"; } else if($_POST[password] != ""){ if($password == $_POST[password]){ $_SESSION[passed] = "y"; } else{ echo "<script>window.location = 'admin.php';</script>"; } } if($_SESSION[passed] == "y"){ $title=$_POST['title']; $date=$_POST['date']; $text=$_POST['text']; $query = "INSERT INTO news SET id='', title='$title', date='$date', text='$text'"; $result = mysql_query($query) or die(mysql_error()); header("Location: admin.php"); } else{ echo "You Must Be Logged In To Do That"; } ?> My form looks like this <?php $content .= '<form action="news_edit.php" method="post"><table width="500"> <tr> <td colspan="2"><span class="bolder">Manage News</span></td> </tr> <tr> <td><span class="bolder">Title</span></td> <td> <input type="text" name="title" id="title" /> </td> </tr> <tr> <td><span class="bolder">Date</span></td> <td><input type="text" name="date" id="date" /></td> </tr> <tr> <td valign="top"><span class="bolder">News</span></td> <td> <textarea name="text" id="text" cols="45" rows="5"></textarea></td> </tr> <tr> <td><input name="id" type="hidden" value="id" /></td> <td><input type="reset" name="reset" id="reset" value="Reset" /> <input type="submit" name="submit" id="submit" value="Submit" /></td> </tr> </table> </form>'; } ?> (edited by kenrbnsn to add tags) Quote Link to comment https://forums.phpfreaks.com/topic/132250-small-insert-problem/#findComment-687527 Share on other sites More sharing options...
kenrbnsn Posted November 11, 2008 Share Posted November 11, 2008 If the field "id" in your table is of type "int" and set to "autoincrement", then you can just leave it out of the mysql insert statement: <?php $query = "INSERT INTO news SET title='$title', date='$date', text='$text'"; $result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error()); ?> I also find it very helpful to include the query in the die() statement. Ken Quote Link to comment https://forums.phpfreaks.com/topic/132250-small-insert-problem/#findComment-687652 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.