contra10 Posted December 29, 2008 Share Posted December 29, 2008 heres my code <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); if (isset($_POST['post'])){ if(is_numeric($_GET['id'])){ $id = $_GET['id']; $query= "SELECT * FROM groups WHERE id = '$id'"; $result = mysql_query($query) or die(mysql_error());; $group = mysql_fetch_assoc($result); $groupname = "{$group['name']}"; $groupid = "{$group['id']}"; $query2= "SELECT id FROM users WHERE username = '$username'"; $result2 = mysql_query($query2) or die(mysql_error());; $usera = mysql_fetch_assoc($result2); $userid = "{$usera['id']}"; $userpost = mysql_real_escape_string($_POST['userpost']); $month = mysql_real_escape_string($_POST['month']); $day = mysql_real_escape_string($_POST['day']); $year = mysql_real_escape_string($_POST['year']); } //This makes sure they did not leave any fields blank if (!$_POST['userpost']) { die('You did not enter a post'); } // now we insert it into the database $insertpost = "INSERT INTO posts_grp (grpid, grpname, userid, username, grppost, month, day, year) VALUES ('$groupid', '$groupname', $userid', '$username', '$userpost', '$month', '$day', '$year')"; $add_post2 = mysql_query($insertpost) or die(mysql_error()); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0" width="800" align="center" height="100"> <tr> <td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr> <tr><input type='hidden' name='day' value='<?php $date = time () ; $day = date('d', $date); echo ($day); ?>'></td></tr> <tr><input type='hidden' name='month' value='<?php $date = time () ; $month = date('F', $date); echo ($month); ?>'></td></tr> <tr><input type='hidden' name='year' value='<?php $date = time () ; $year = date('Y', $date); echo ($year); ?>'></td></tr> <tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr> </table> </form> <?php } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0" width="800" align="center" height="100"> <tr> <td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr> <tr><input type='hidden' name='day' value='<?php $date = time () ; $day = date('d', $date); echo ($day); ?>'></td></tr> <tr><input type='hidden' name='month' value='<?php $date = time () ; $month = date('F', $date); echo ($month); ?>'></td></tr> <tr><input type='hidden' name='year' value='<?php $date = time () ; $year = date('Y', $date); echo ($year); ?>'></td></tr> <tr><td align="center"><input type="submit" name="post" value="Post"></td></tr> </table> </form> <?php } ?> and i get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'asd', '', '', '', '')' at line 2 Quote Link to comment https://forums.phpfreaks.com/topic/138689-mysql-error-in-syntax/ Share on other sites More sharing options...
MadTechie Posted December 29, 2008 Share Posted December 29, 2008 Your right their is an error Update to $insertpost = "INSERT INTO posts_grp (`grpid`, `grpname`, `userid`, `username`, `grppost`,` month`, `day`, `year`) VALUES ('$groupid', '$groupname', '$userid', '$username', '$userpost', '$month', '$day', '$year')"; Quote Link to comment https://forums.phpfreaks.com/topic/138689-mysql-error-in-syntax/#findComment-725112 Share on other sites More sharing options...
contra10 Posted December 29, 2008 Author Share Posted December 29, 2008 i fixed it Quote Link to comment https://forums.phpfreaks.com/topic/138689-mysql-error-in-syntax/#findComment-725125 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.