Trouble inserting record

I am having the hardest time inserting a new record. I am not receiving any errors either… It’s not inserting.


<?
error_reporting(1);
$dblink = mysql_connect("localhost", "user", "pass") or die(mysql_error());
echo "Connected to MySQL<br />";

mysql_select_db("db", $dblink);


$i=1;
while($i<=10)
  {

//insert here

$code = createRandomPassword(); 


mysql_query("INSERT INTO `safestsu_lil`.`id` (`code`, `enabled`) VALUES ('$code', '1')");
																		 
//mysql_query("INSERT INTO 'safestsu_lil'.'id' ('code', 'enabled') VALUES ('$code', '1')");

echo "http://www.site.com/go/?id=" . $code . "\
<br>";

  $i++;
  }
  
  
  
  function createRandomPassword() { 

    $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz023456789"; 
    srand((double)microtime()*1000000); 
    $i = 0; 
    $pass = '' ; 

    while ($i <= 7) { 
        $num = rand() % 33; 
        $tmp = substr($chars, $num, 1); 
        $pass = $pass . $tmp; 
        $i++; 
    } 

    return $pass; 

} 


?>

I removed the loop and just tested it to insert one row. It output the following:

INSERT INTO `safestsu_lil`.`id` (`code`, `enabled`) VALUES ('YDTWCOCO', '1')

I think ran the query from php my admin and it inserted. It wont insert script-side for some reason…



#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$i=1' at line 1 


Print out the query and run it directly in MySQL to see the issue. If it inserts fine its a PHP issue otherwise the query is incorrectly formed.



<?

error_reporting(1);

$dblink = mysql_connect("localhost", "user", "pass") or die(mysql_error());

echo "Connected to MySQL<br />";



mysql_select_db("db", $dblink);





$i=1;

while($i<=10)

  {



//insert here



$code = createRandomPassword(); 



$sql = "INSERT INTO `safestsu_lil`.`id` (`code`, `enabled`) VALUES ('$code', '1')";

echo '<p>',$sql,'</p>'; // copy and paste this output directly into MySQL to debug issue
exit;

mysql_query($sql);

                                                                         

//mysql_query("INSERT INTO 'safestsu_lil'.'id' ('code', 'enabled') VALUES ('$code', '1')");



echo "http://www.site.com/go/?id=" . $code . "\
<br>";



  $i++;

  }

  

  

  

  function createRandomPassword() { 



    $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz023456789"; 

    srand((double)microtime()*1000000); 

    $i = 0; 

    $pass = '' ; 



    while ($i <= 7) { 

        $num = rand() % 33; 

        $tmp = substr($chars, $num, 1); 

        $pass = $pass . $tmp; 

        $i++; 

    } 



    return $pass; 



} 





?>

Disregard. This version of PHP is dumb or something. I had to do the following to get it to insert from php…


INSERT INTO `safestsu_lil`.`id` (`code`, `enabled`) VALUES (\\'6nwws325\\', \\'1\\');

Never mind, that didn’t fix it. I dun’ goofed. I’m gonna go stick a glock in my mouth and make a brain-slushie now.