MySQL Forums
Forum List  »  PHP

Submit form Problems
Posted by: Edward Comarzan
Date: June 08, 2005 07:50AM

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

Options: ReplyQuote


Subject
Written By
Posted
Submit form Problems
June 08, 2005 07:50AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.