WHERE clause in INSERT statement using mysql/php -


after searching on google, came know that, can not use clause in insert query.. want insert value on column "book_4" "student_id = 1"

how can ?? there alternate ?

will thankful !

$query = "insert issued_books (book_4) values ('$issuedbooknumber')" ; 

edited: more details using insert query, when insert value in column "student_id" in table. columns in row of student_id (except student_id) shows 0 in db. dun know 0 means according db. might null or numeric 0. if numeric 0, should updated using update statement. whenever i'm trying update it, never updates using update statement. that's why i'm asking !

p.s: columns have datatype int.

hope understand want :)

here complete code. suppose: student_id created having value 2. issuedbooknumber = 51

using above values: result = new row created having columns 0 except column "issuedbooknumber" having value = 51.

while want, result should be: on row student_id = 2, book_4 should 51.

the point is, when inserted value on student_id, other columns becomes 0 on same row. when of column on same row having number except 0 (that automatically came on columns when inserted value in student_id). update query work.. !

$issuedbooknumber = $_post['issuedbooknumber'];      $student_id = $_post['studentid'];       $fetchingquery = "select * issued_books student_id='" . $student_id . "'";       $runfetchingquery = mysql_query($fetchingquery);        while ( $row = mysql_fetch_array( $runfetchingquery ) ) {            $book_1 = $row[ 'book_1' ];           $book_2 = $row[ 'book_2' ];           $book_3 = $row[ 'book_3' ];           $book_4 = $row[ 'book_4' ];           $book_5 = $row[ 'book_5' ];            }            if(!empty($book_4))           {                $update =  "update issued_books set book_4='$issuedbooknumber' student_id= '$student_id'";              mysql_query ($update);           }            else           {                $addquery = "insert issued_books (book_4) values ('$issuedbooknumber')";     mysql_query ($addquery);           } 

that not insert. that's update. insert statements insert new row. update statements update existing row.

update issued_books set book_4 = '$issuedbooknumber' student_id = '$student_id' 

(i'm assuming you've escaped $issuedbooknumber , $student_id)


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -