Jump to content

[SOLVED] inserting data into MySQL


black_box

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.