Jump to content

Write array keys to SQL


ccnaboy_2000

Recommended Posts

To elaborate on what MadTechie said...

 

You could just use

 

<?php
foreach($array as $key => $value) {
      // $key = the key
      // $value = the value
      // Do insert queries
}
?>

 

just use $key and $value for the insert queries

 

More info on how to actually insert values into sql...

http://www.google.com/search?hl=en&safe=off&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=Ebe&q=php+sql+insert&btnG=Search

well I can get it to print the array data properly to the screen. But i think my SQL Query may be malformed. It keeps die'ing on the query.

 

$query = "INSERT INTO repository ('url') VALUES ('$link')";
mysql_query($query) or die("cannot execute query");

 

Is my syntax wrong?

//database connection here
$url['0'] = "whatever1";
$url['1'] = "whatever2";
$url['2'] = "whatever3";
//same thing as $url = array('whatever1','whatever2','whatever3');
echo "The fallowing links were enterd into the database:<br>";
foreach($url as $link)
{
$query = "INSERT INTO repository ('url') VALUES ('$link')";
mysql_query($query) or die("cannot execute query");
echo $link."<br>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.