I am having a problem with INSERT INTO statement. If I hard code the values into the query they get written to the database with no problem. However, if I use varibales, I get an error, could not execute query.
Do I need to specify the scope of the variable such as "form.$award" or what?
Here is my code:
////////////////////////////////////////////////////////////////////////////////
<?
if ((!$award) ||(!$song)){
header("location: awardsinput.shtml");
exit;
}
$db_name = "dbase";
$table_name = "awards";
$connection =mysql_connect ("localhost", "username", "pwd") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("carry-on_");
$db = @mysql_select_db($db_name, $connection) or die("could not select database.");
$sql = 'INSERT INTO awards ( awardID , award , song ) ';
$sql .= 'VALUES ( \'\', \'$award\', \$song\' );';
$sql .= '';;
$result = @($sql, $connection) or die("couldnt execute query.");
?>
<html>
<head>
<title>add record</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1 align="center"> Adding a record to<? echo "$table_name"; ?></h1><br>
<table width="75%" border="1" cellspacing="3" cellpadding="3">
<tr>
<tH>Award</th>
<th>Song</th>
</tr>
<tr>
<td><? echo "$award"; ?></td>
<td><? echo "$song"; ?></td>
</tr>
</table>
</body>
</html>
😕
Any pointers would be greatful
TIA
Jay