first post here and a newbie at php programming.
I am trying to insert $val(2) into mysql database. My code is as follows:
$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());
}
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.
Addendum:
I didn't include the lines:
$url = "http:xxxxxxxxxxxxx.com"; //url here
$str = file_get_contents($url);
in my first post.
The real solution is to change:
$test to $sql
and to comment out the 2 lines below
file_get_content($url)
$str = file_get_contents($url);
These 2 lines has to be placed on top (before the $username= "xxx" line) for it to work. Apologies for the misleading question.