Insert into mysql not working
<p>first post here and a newbie at php programming.</p>

<p>I am trying to insert $val(2) into mysql database. My code is as follows: </p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>$username = "xxx";
$password = "xxx";
$hostname = "xxx";
$val= "2";

$connection=mysql_connect ($hostname, $username, $password)
or die("Unable to connect to MySQL");

$selected = mysql_select_db("database",$connection)
or die("Could not select examples");

$url = "http:xxxxxxxxxxxxx.com"; //url here
$str = file_get_contents($url);

$sql = "INSERT INTO testtable (data)
VALUE ('".$val."')";
   
$ins= mysql_query($test);
if(! $ins )
{
 die('Could not insert: ' . mysql_error());
}</code></pre>
</div>
</div>
</p>

<p>When i run the code, there is no error printed out, but no data is being inserted into the table. Can someone point out the problem. I would appreciate the help. </p>

<p>Addendum: </p>

<p>I didn't include the lines:</p>

<pre><code>$url = "http:xxxxxxxxxxxxx.com";    //url here
$str = file_get_contents($url);
</code></pre>

<p>in my first post. </p>

<p>The real solution is to change:</p>

<pre><code>$test to $sql
</code></pre>

<p>and to comment out the 2 lines below</p>

<pre><code>file_get_content($url) 
$str = file_get_contents($url);
</code></pre>

<p>These 2 lines has to be placed on top (before the $username= "xxx" line) for it to work. Apologies for the misleading question.</p>