CloudSex13 Posted February 19, 2009 Share Posted February 19, 2009 Hey everyone, thanks for reading. I have this bit of code here: function add() { if (isset($_POST['add'])) { $addtask = $_POST['task']; $addpriority = $_POST['priority']; $adddeadline = $_POST['deadline']; $getnexttaskid = mysql_query("SELECT TaskID FROM Tasks"); $amountoftasks = mysql_num_rows($getnexttaskid); $nexttaskid = $amountoftasks + 1; $getaccountid = mysql_query("SELECT AccountID FROM Accounts WHERE Username='".$_COOKIE['usercookieLP']."' LIMIT 1"); $getinfo = mysql_fetch_array($getaccountid); $AccountID = $getinfo['AccountID']; mysql_query("INSERT INTO Tasks SET TaskID='$nexttaskid', AccountID='$AccountID', Task='$addtask', Priority='$addpriority', Created=NOW(), Deadline='$adddeadline', Status='1'"); $added = "<p align=center><span class=success>The task has been created.</span></p>"; } echo " ".$added." <div class=box> <form method=post action=tasks.php?action=add> <table width=100% align=center border=0> <tr> <td width=40% align=right> Task: </td> <td width=60% align=left> <textarea name=task cols=35 rows=5></textarea> </td> </tr> <tr> <td width=40% align=right> Deadline: </td> <td width=60% align=left> <input type=text name=deadline class=text> </td> </tr> <tr> <td width=40% align=right> Priority: </td> <td width=60% align=left> <select name=priority class=text> <option value=3>Low</option> <option value=2>Medium</option> <option value=1>High</option> </select> </td> </tr> <tr> <td align=center width=100% colspan=2> <input type=submit class=button value='Add' name=add> </td> </tr> </table> </form> </div>"; } This code was working perfectly fine until I started messing around with the page layout. Basically, the code is flawless - no errors. Database connections are fine, all good. Like I said, it was just working. But for some reason, the INSERT INTO statement will not create a new row in the database now. Manually putting in a row using phpMyAdmin works, though. I've tried an alternative method using VALUES, but that had no luck. Would anyone have any ideas? I'm stumped. x.x Thanks if so - Best. Link to comment https://forums.phpfreaks.com/topic/145993-solved-insert-into-statement-refuses-to-work/ Share on other sites More sharing options...
Mchl Posted February 19, 2009 Share Posted February 19, 2009 Start with echoing mysql errors: mysql_query("INSERT INTO ...") or die(mysql_error()); same for the other query. Even better would be $query = "INSERT INTO ..."; mysql_query($query) or die(mysql_error().": $query"); Link to comment https://forums.phpfreaks.com/topic/145993-solved-insert-into-statement-refuses-to-work/#findComment-766445 Share on other sites More sharing options...
CloudSex13 Posted February 19, 2009 Author Share Posted February 19, 2009 "Duplicate entry '4' for key 1" I didn't even know you could echo errors like that for queries. Three cheers for self-learning, my God. That thing is my new best friend. THANK YOU! Link to comment https://forums.phpfreaks.com/topic/145993-solved-insert-into-statement-refuses-to-work/#findComment-766448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.