2

2000-10-01,2000-12-16,2000-11-17,2001-03-10,2001-09-10,2000-09-02,2000-11-02,2000-12-06,2000-11-02,2000-12-09,2000-12-01,2001-04-16.

Gambardella, Matthew,Ralls, Kim,Corets, Eva,Corets, Eva,Corets, Eva,Randall, Cynthia,Thurman, Paula,Knorr, Stefan,Kress, Peter,O'Brien, Tim,O'Brien, Tim,Galos, Mike

i have this value in variable $date and $author.i want to insert it into database. i have been trying using .

$sql = "insert into book values('','$author','{$date}') ";
7
  • So what is the problem Commented Feb 18, 2016 at 4:59
  • i am not able to insert all the data stored into $data and $author variable. Commented Feb 18, 2016 at 5:01
  • Are you getting any error. Like any violation's of constraint Commented Feb 18, 2016 at 5:02
  • you need to explode the string and insert the data into loop i guess. Commented Feb 18, 2016 at 5:02
  • @VR46 when i echo this variable it shows - 2000-10-01,2000-12-16,2000-11-17,2001-03-10,2001-09-10,2000-09-02,2000-11-02,2000-12-06,2000-11-02,2000-12-09,2000-12-01,2001-04-16. but when i insert it it shows 0000-00-00 . Commented Feb 18, 2016 at 5:04

3 Answers 3

1

Assuming, you have are having connection to mysql database.

$date = 
"2000-10-01,2000-12-16,2000-11-17,2001-03-10,2001-09-10,2000-09-02,2000-11-02,2000-12-06,2000-11-02,2000-12-09,2000-12-01,2001-04-16";

$authors="Gambardella,Matthew,Ralls,Kim,Corets,Eva,Corets,Eva,Corets,Eva,Randall,Cynthia,Thurman,Paula,Knorr,Stefan,Kress,Peter,O'Brien,Tim,O'Brien,Tim,Galos,Mike";



 $sql = "insert into book values('','".mysql_real_escape_string($author)."','".mysql_real_escape_string($date)."') ";
 echo mysql_query($sql);

The code above will insert all the data into the database.

Thanks

Sign up to request clarification or add additional context in comments.

3 Comments

Mysql_* is deprecated
@ShivRoy can you please mark it as answer, also you can use mysqli_real_escape_string if you dont want to use deprecated function mysql_real_escape_string.
Marking correct answer will help our community to easily look at correct answer and take correct action faster.
0

Please try query like below.

$sql = "insert into book values('','".$author."','".$date."') ";

And please echo and exit your query and then run it in databse that's why you identify what is issue.

Comments

0
<?php    
    // check on your DB connection
    $connDB = new mysqli ( $db_host, $db_username, $db_pass, $db_name );  

    $date = array("2000-10-01","2000-12-16");
    $author = array("Gambardella","Ralls");
    $count = 0;

foreach ($dates as $date)
{
   $sql_insert = "INSERT into book(something, author, date) values(',','$date','$author[$count]')";
   mysqli_query ( $connDB, $sql_insert );
   $count ++ ;
}
mysqli_close($connDB);
?>

2 Comments

Change the order of values
$date should be $dates

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.