Hello, newbie here trying to learn mysql and im stuck. I hope someone here can help me out. I created an HTML form containing 4 fields (Title, Subtitle, Summary, Story Text) and Im trying to get it write to the database and Im getting a different error now.
After you submit, I get the following error:
Could add the entry because: You have an error in your SQL syntax near '' at line 1. The query was INSERT INTO ts1news (ts1_title, ts1_subtitle, ts1_summary, ts1_story).
Here is the code:
<body>
<?php
// Address error handing.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
if (isset ($_POST['submit'])) { // Handle the form.
// Connect and select.
if ($dbc = @mysql_connect ('localhost', '******', '******')) {
if (!@mysql_select_db ('******')) {
die ('<p>Could select the database because: <b>' . mysql_error() . '</b></p>');
}
} else {
die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>');
}
// Define the query.
$query = "INSERT INTO ts1news (ts1_title, ts1_subtitle, ts1_summary, ts1_story)";
// Execute the query.
if (@mysql_query ($query)) {
print '<p>The text has been added.</p>';
} else {
print "<p>Could add the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>";
}
mysql_close();
}
// Display the form.
?>
<form action="add_entry.php" method="post">
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><h1>Top Story 1 </h1></td>
</tr>
<tr>
<td>Story Title:</td>
<td><input name="ts1_title" type="text" id="ts1_title" /></td>
</tr>
<tr>
<td>Sub Title: </td>
<td><input name="ts1_subtitle" type="text" id="ts1_subtitle" /></td>
</tr>
<tr>
<td>Summary Text </td>
<td><textarea name="ts1_summary" cols="50" rows="5" id="ts1_summary"></textarea></td>
</tr>
<tr>
<td>Main Story Text </td>
<td><textarea name="ts1_story" cols="50" rows="5" id="ts1_story"></textarea></td>
</tr>
</table>
<input type="submit" name="submit" value="Add to Database" />
</form>
</body>
test it out for yourself at:
http://lsm.infinitegrafix.com/add_entry.php