View Full Version : PHP MySQL form error

07-16-2012, 07:09 PM
I have a form set up to show events and when an admin is logged it it gives him the option to delete an event. Whenever i hit the delete form for some reason its not reading the whole event title. i have the events set up in a MySQL database and am echoing out the events. here is my code:

include_once "connect_to_mysql.php";
$data = mysql_query("SELECT * FROM calendar ORDER BY year, month, date DESC") or die(mysql_error());
while($info = mysql_fetch_array( $data ))

$month = ereg_replace("[^A-Za-z]", "", $info['month']); // filter out numbers
$endmonth = ereg_replace("[^A-Za-z]", "", $info['endmonth']); // filter out numbers

echo "<form action='' method='post' enctype='multipart/form-data' name='form' id='form' onsubmit='return validate_form ( );'>
<td width='300' valign='top' style='padding-right:10px;'>" .$month. ", " .$info['date'].
"&nbsp;" .$info['year']. " &mdash; " .$endmonth. ",&nbsp;" .$info['enddate']. "&nbsp;" .$info['endyear']. "</td>
<td width='440' style='padding-left:10px;' valign='top' >
<font size='+1' color='#179ceb'><strong>" .$info['event']. "</strong></font><br />" .$info['description']. "</td>
<td><select name='deleteevent'><option value=''><option value='delete'>delete event</select><br /><br />
<font size='-1' color='red'>*WARNING:<br /></font>
<font size='-4' color='red'>Delete action can NOT be undone.</font>
<input name='event2' type='hidden' id='event2' value=" .$info['event']. "/>
<input type='submit' name='delete' id='delete' value='Delete Event' />
</form><br /><hr />";

if (array_key_exists('delete', $_POST)) {

include_once "connect_to_mysql.php";
$event2 = $_POST['event2'];
$delete = $_POST['deleteevent'];
$sql = mysql_query("SELECT * FROM calendar");
while($row = mysql_fetch_array($sql)){

if ($delete == "delete") {

$sql = mysql_query("DELETE FROM calendar WHERE event='$event2'");
$successmsg = '<div style=\'padding:10px; background-color:#333;\'><center><font color=\'#fff\'>The event "' .$event2. '" has been deleted</font></center></div>
<br /><br />';

} else if ($delete == "") {

$successmsg = '<div style=\'padding:10px; background-color:#333;\'><center><font color=\'#fff\'>Please select and event to be deleted</font></center></div>
<br /><br />';


something happens from when i hit the delete user button to when it reads the form where it shows only the first word of the event title.

thank you for any help!