black_box Posted November 28, 2007 Share Posted November 28, 2007 I am having a problem inserting data into MySQL what can be the problem ?? $SQL_insert = "INSERT into borrow VALUES ('','$bok_id','$bok_nam','$stu_id','$stu_nam','$DOI','$due_dat','','')"; mysql_query($SQL_insert)or die("Couldnot insert"); Database structure: The first column is auto increament and last two columns can be null. Date is also in : m/d/y format so MySQL should accept tht as it is. So what can be the problem please help me i m stuck for 4 hrs Link to comment https://forums.phpfreaks.com/topic/79313-solved-inserting-data-into-mysql/ Share on other sites More sharing options...
Silverado_NL Posted November 28, 2007 Share Posted November 28, 2007 try removing the quotes around the id's , if im not mistaken mysql will treat '1' as a string and not an integer. so something like this would be my guess. <?php $SQL_insert = "INSERT into borrow VALUES ('',$bok_id,'$bok_nam',$stu_id,'$stu_nam','$DOI','$due_dat','','')"; ?> hope this helps Link to comment https://forums.phpfreaks.com/topic/79313-solved-inserting-data-into-mysql/#findComment-401453 Share on other sites More sharing options...
black_box Posted November 28, 2007 Author Share Posted November 28, 2007 Nope Same thing i tried this b4 bt no change i dnt knw wht can be the problem with it Link to comment https://forums.phpfreaks.com/topic/79313-solved-inserting-data-into-mysql/#findComment-401461 Share on other sites More sharing options...
revraz Posted November 28, 2007 Share Posted November 28, 2007 Remove the empty ' ' for the ID and the last two empy ' '. If they can be null, then don't even send it. May want to specify the columns too. Link to comment https://forums.phpfreaks.com/topic/79313-solved-inserting-data-into-mysql/#findComment-401462 Share on other sites More sharing options...
revraz Posted November 28, 2007 Share Posted November 28, 2007 See here http://www.phpfreaks.com/forums/index.php/topic,169634.msg748788.html#msg748788 Link to comment https://forums.phpfreaks.com/topic/79313-solved-inserting-data-into-mysql/#findComment-401466 Share on other sites More sharing options...
black_box Posted November 28, 2007 Author Share Posted November 28, 2007 even though i remove the null ' ' ..its same and cnnot insert Link to comment https://forums.phpfreaks.com/topic/79313-solved-inserting-data-into-mysql/#findComment-401470 Share on other sites More sharing options...
Wolphie Posted November 28, 2007 Share Posted November 28, 2007 Try $SQL_insert = mysql_query(sprintf("INSERT INTO `borrow` ( `table_name`, `table_name`, `table_name`, `table_name`, `table_name`, `table_name`, `table_name`, `table_name`, `table_name` ) VALUES ( '', '%d', '%s', '%d', '%s', '%s', '', '', '')", $bok_id, $bok_name, $stu_id, $stu_nam, $DOI, $due_date)) or die('Error: ' . mysql_error()); The table_name's are for you to enter the table names for each table where you want to insert the data. e.g. `bok_name` for the variable $bok_name // `bok_name` being the table name, and $bok_name being the variable. I'm assuming that $bok_id and $stu_id are integer's therefore i've used %d for them rather than %s for strings. Alternitavely $SQL_insert = mysql_query(sprintf("INSERT INTO `borrow` ( `table_name`, `table_name`, `table_name`, `table_name`, `table_name` ) VALUES ( '%d', '%s', '%d', '%s', '%s' )", $bok_id, $bok_name, $stu_id, $stu_nam, $DOI, $due_date)) or die('Error: ' . mysql_error()); I have removed the all of the ('')'s which contain no data Link to comment https://forums.phpfreaks.com/topic/79313-solved-inserting-data-into-mysql/#findComment-401479 Share on other sites More sharing options...
black_box Posted November 28, 2007 Author Share Posted November 28, 2007 Yap thts the thing i forget to put those column names .now its working perfectly ..thanx all of u guys ... I love this forum too much cuz u make me feel happy thanx again Link to comment https://forums.phpfreaks.com/topic/79313-solved-inserting-data-into-mysql/#findComment-401490 Share on other sites More sharing options...
Wolphie Posted November 28, 2007 Share Posted November 28, 2007 Most welcome. Link to comment https://forums.phpfreaks.com/topic/79313-solved-inserting-data-into-mysql/#findComment-401491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.