hello everyone,
I'm trying to insert records into a subtopic table.First, I'm getting all the topics into a list box and then I'm selecting a topic and then will hit a button.It shows me a text box where i can enter a sub-topic name corresponding to the topic and will hit the insert button.
After the insert st is executed, it displays me the error mesg"Something is wrong in the syntax".
Could somebody pls figure out where the error is???
My subtopic table has 3 fields(TOPIC_ID, SUBTOPIC_ID, SUBTOPIC_NAME)SUBTOPIC_ID being auto-increment.
Thanks in advance
<?php
//Database connection
?>
<html>
<head>
<title>Insert subtopics</title>
</head>
<body>
<?
if (isset($HTTP_POST_VARS ["TOPIC_ID"])) {
$TOPIC_ID=(int)$HTTP_POST_VARS ["TOPIC_ID"];
$q=mysql_query("select * from topic where TOPIC_ID=$TOPIC_ID");
if (!mysql_num_rows($q))
$TOPIC_ID=0;
} else {
$TOPIC_ID=0;
}
if ($TOPIC_ID) {
$headline=trim($HTTP_POST_VARS ["headline"]);
if (strlen($headline)) {
mysql_query("INSERT INTO subtopic (TOPIC_ID, SUBTOPIC_ID, SUBTOPIC_NAME) VALUES ($TOPIC_ID, $SUBTOPIC_ID, '$headline')")
or die("Invalid query: " . mysql_error());
echo "Subtopic inserted!";
}
}
// To display the form
echo "<html><form method=post action=\"$PHP_SELF\">";
echo "<select name=TOPIC_ID>";
$q=mysql_query("SELECT * FROM topic ORDER BY TOPIC_NAME");
while ($l=mysql_fetch_array($q)) {
$selected="";
if ($l["TOPIC_ID"]==$TOPIC_ID)
$selected="selected=1";
echo "<option value=\"".$l["TOPIC_ID"]."\" $selected>".$l["TOPIC_NAME"];
}
echo "</select>";
echo " <input type=submit name=submitname value=\"Change\"> ";
echo "<br><br>";
if ($TOPIC_ID) {
echo "Headline: <input name=headline size=40><br>";
echo "<input type=submit value=\"Insert\">";
}
echo "</form>";
?>
</body>
</html>