Re: cant insert into specific column in specific row...help?
| From: | Justin Patrin | Date: | Fri, 19 Mar 2004 17:39:52 +0000 |
| Subject: | Re: cant insert into specific column in specific row...help? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-33550@lists.php.net to get a copy of this message | ||
Aj Seelund wrote:
im trying to insert, or more or less, add to the number in a column called (comNum) in one a specific row in one table(dm_blog), and add other values to another table(comments). i have the comments table working fine, everything insert correctly, but im trying to add to the count (comNum) in dm_blog. im not quite sure how to go about doing this... im trying to select the cell and then add a value to it, but my targeting is off i think. heres a sample of the code im using:If you're trying to add to a column or change a field, you should be using an UPDATE SQL statement. -- paperCrane <Justin Patrin>//if posting a comment do this: if ($comms=="true") {//create a row in comments table $id is post number from dm_blog $id = $entryNum; if ($newTab=="true") { //set comNum to 1 if no comment yet $comNum = 1;//this is where im confused...//insert the values into the table for the comment $commPost = "INSERT INTO comments VALUES ('$id','$daUser', '$entryNumb', '$priv', '$comm')"; $add_to_comNum = 'SELECTcomNum' . ' FROMdm_blog' . ' WHERE 1 ANDentryNum= ' . $id .' LIMIT 0, 30';$commAdd = "INSERT INTO dm_blog VALUES ('$id','$daUser', '$entryNumb', '$priv', '$comm')"; $addComm = mysql_query($add_to_comNum) or die("error selecting and inserting $comNum into comNum on $id"); //output the comment or errors $CommResult = mysql_query($commPost) or die("(Error on line 70 of inputBlog.php) <br /><br /> tableName:$theTable <br /> entryNum:$entryNum <br /> entryNumb:$entryNumb<br /> priv:$priv <br />usr:$daUser<br /> comm:$comm"); }else{ //insert the values into the table for the comment $commPost = "INSERT INTO comments VALUES ('$id','$daUser', '$entryNumb', '$priv', '$comm')"; $post = "INSERT INTO dm_blog VALUES ('$comNum')";thanks in advance -aj seelund aj@beingdevious.com//output the comment or errors $CommResult = mysql_query($commPost) or die("(Error on line 78 of inputBlog.php) <br /><br /> tableName:$theTable <br /> entryNum:$entryNum <br /> priv:$priv <br />usr:$daUser<br /> comm:$comm"); $result2 = mysql_query($post) or die("(Error on line 85 of inputBlog.php) <br /> $post </td> \n\r </tr> \n\r </table> </body></html>"); }while($myrow = mysql_fetch_array($CommResult)){ $p_entryNumb = $myrow["entryNumb"]; $p_daUser = $myrow["daUser"]; echo "entryNumber: $p_entryNumb by [user: $p_daUser] has been added<br />"; }//if posting a new post in dm_blog do this:}else{$post = "INSERT INTO dm_blog VALUES ('$date', '$chapter', '$mood', '$theuser', '$message', '$entryNum' ,'$song','$t_level','$r_thought','$comNum')"; $result = mysql_query($post) or die("Uh oh! You fucked up dumbass! (Error on line 85 of inputBlog.php) <br /> $post </td> \n\r </tr> \n\r </table> </body></html>");}