Question

if (isset($_POST['submit']))
{

for($i=7;$i<=150;$i++)
{
$res= mysql_query("INSERT INTO pokemons (pk_name, pk_type, path) VALUES ('nm', 'typ', '<img src=/images/'".$i."'.png>')");  
echo $res;

}

I tried a simple insert php code which would insert image path. Its not showing any error..and technically its correct! Then too rows are not added?

Was it helpful?

Solution

Try:

if (isset($_POST['submit']))
{   
    for($i=7;$i<=150;$i++)
    {
        $res= mysql_query("INSERT INTO pokemons (pk_name, pk_type, path) VALUES ('nm', 'typ', '<img src=/images/".$i.".png>')");            
    }
}

OTHER TIPS

you missed one curly bracket to close if condition

<?php
if (isset($_POST['submit']))
{

    for($i=7;$i<=150;$i++)
    {
       $res= mysql_query("INSERT INTO pokemons (pk_name, pk_type, path) VALUES ('nm', 'typ', '<img src=/images/'".$i."'.png>')");  
       var_dump($res);

    }
}
?>

note : $res is resource , you can print it .. try var_dump($res) instead

try to write indented code, it will help you to trace brackets easily

Also check if mysql connection is successful or not

you can append die() on mysql_query() like below

mysql_query("INSERT INTO pokemons (pk_name, pk_type, path) VALUES ('nm', 'typ', '<img src=/images/'".$i."'.png>')") or die(mysql_error())

php variable $i shoudn't be in ""

 <?php
if (isset($_POST['submit']))
{

    for($i=7;$i<=150;$i++)
    {
       $res= mysql_query("INSERT INTO pokemons (pk_name, pk_type, path) VALUES ('nm', 'typ', '<img src=/images/'.$i.'.png>')");  
       var_dump($res);

    }
}
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top