iisthesloth Posted April 25, 2008 Share Posted April 25, 2008 Hey guys. This has been bugging me all morning and it should be quite simple. I'm working on the administrative side of a site right now which has 1 MySQL table with 5 rows (id, title, author, text, date). I have a simple form in which the user is able to preview or submit the data. The problem is submitting, although the script is returning no errors and seems to work well, but simply does not add in the rows at all. Heres what I have: <?PHP $dates = getdate(); //convert all the posts to variables: $title = $_POST['title']; $text = $_POST['text']; $author = $_POST['author']; $date = $_POST['date']; $id = $_POST['id']; ?> <form method="post"> <h3>Date</h3> <input type='text' name='date' value='<? echo $dates['month']; echo ' '; echo $dates['mday']; echo ', '; echo $dates['year']; ?>' size=20> <h3>Title</h3> <input type='text' name='title' value='<? echo $title; ?>' size=60> <h3>Content</h3> <textarea name="text" rows="5" cols="60"><? echo $text; ?></textarea> <h3>Author</h3> <input type='text' NAME='author' VALUE='<? echo $author; ?>' size=10 > <input type="submit" name="preview" value="PREVIEW"> <input type="submit" name="submit" value="Submit"> </form> <div id="updates"> <?PHP require_once('../../mysql_conn.php'); //preview if($_POST['preview']) { echo '<h1>'.$date.'</h1>'; echo '<h2>'.$title.'</h2>'; echo '<p>'.$text.'</p>'; echo '<h3>'.$author.'</h3>'; } else { } //submit if($_POST['submit']) { require_once('../../mysql_conn.php'); $query = "INSERT INTO posts (id, title, text, author, date) VALUES ('NULL', '$title', '$text', '$author', '$date')"; $result = @mysql_query ($query); echo '<h2>Updated!</h2>'; echo '<h4><a href="http://rolldc.com/">Check it out</a></h4>'; mysql_close(); } else { } ?> </div> Thanks! Link to comment https://forums.phpfreaks.com/topic/102889-adding-data-to-mysql-database-problem/ Share on other sites More sharing options...
947740 Posted April 25, 2008 Share Posted April 25, 2008 The name seems to say it, but I am just checking. Does the mysql_conn.php connect to the database? It may seem like a stupid question, but it is just good to double-check that kind of stuff. Link to comment https://forums.phpfreaks.com/topic/102889-adding-data-to-mysql-database-problem/#findComment-527077 Share on other sites More sharing options...
iisthesloth Posted April 25, 2008 Author Share Posted April 25, 2008 Yeah, it does. Link to comment https://forums.phpfreaks.com/topic/102889-adding-data-to-mysql-database-problem/#findComment-527079 Share on other sites More sharing options...
urbantricker Posted April 25, 2008 Share Posted April 25, 2008 Hi, The line: $result = @mysql_query ($query); Try this: $result = mysql_query ($query) or die(mysql_error()); This will stop executing your script and display any MySQL erros you may have, this will help you narrow it down to see if it is an SQL problem. Let me know if this works. Link to comment https://forums.phpfreaks.com/topic/102889-adding-data-to-mysql-database-problem/#findComment-527080 Share on other sites More sharing options...
iisthesloth Posted April 25, 2008 Author Share Posted April 25, 2008 Wow, it worked. For some reason my ID number isn't updating though. It's just staying at 0. hmm Link to comment https://forums.phpfreaks.com/topic/102889-adding-data-to-mysql-database-problem/#findComment-527085 Share on other sites More sharing options...
urbantricker Posted April 25, 2008 Share Posted April 25, 2008 Instead of: $query = "INSERT INTO posts (id, title, text, author, date) VALUES ('NULL', '$title', '$text', '$author', '$date')"; Try $query = "INSERT INTO posts (title, text, author, date) VALUES ('$title', '$text', '$author', '$date')"; Link to comment https://forums.phpfreaks.com/topic/102889-adding-data-to-mysql-database-problem/#findComment-527087 Share on other sites More sharing options...
iisthesloth Posted April 25, 2008 Author Share Posted April 25, 2008 Perfect. I can't thank you enough. Link to comment https://forums.phpfreaks.com/topic/102889-adding-data-to-mysql-database-problem/#findComment-527088 Share on other sites More sharing options...
urbantricker Posted April 25, 2008 Share Posted April 25, 2008 No problem Link to comment https://forums.phpfreaks.com/topic/102889-adding-data-to-mysql-database-problem/#findComment-527089 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.