Text from one textbox causing two elements to delete. Can't figure it out. Help?

I’m creating a simple textbox area that someone can enter text into a textbox, send it to the database and display it later. It has 10 textboxes setup. I can enter text into every box and click submit and they will all be submitted to the database as long as I don’t have anything in textbox 2. In which case it will delete whatever was in textbox 2, push whatever was in textbox 3 and below to the next textbox and push the text in textbox 10 completely off the page.

Any idea why this would happen? Here’s the code to the two pages involved:

[code]<?php

// start the session
session_start();

if (!session_is_registered($_SESSION[‘myusername’])) {
header (‘location:./login.php’);
}
$i=1;
require_once(’./dbconnect.php’);
$sql="SELECT event FROM events";
$result=mysql_query($sql);
mysql_close();

?>

Admin Portal
<?php while ($i<10) { echo ' '; $i++; } ?>

Admin Portal

Logout

Event ' . $i . ' '; $row = mysql_fetch_array($result); if ($row) { $msg=$row[0]; echo $msg; }; echo '
[/code]

[php]<?php
$position = 1;
$dbControl = 9;
$event = array();

if (!empty($_POST[‘event1’])) {
$event[] = $_POST[‘event1’];
}

if (!empty($_POST[‘event2’])) {
$event[] = $_POST[‘event’];
}

if (!empty($_POST[‘event2’])) {
$event[] = $_POST[‘event’];
}

if (!empty($_POST[‘event3’])) {
$event[] = $_POST[‘event3’];
}

if (!empty($_POST[‘event4’])) {
$event[] = $_POST[‘event4’];
}

if (!empty($_POST[‘event5’])) {
$event[] = $_POST[‘event5’];
}

if (!empty($_POST[‘event6’])) {
$event[] = $_POST[‘event6’];
}

if (!empty($_POST[‘event7’])) {
$event[] = $_POST[‘event7’];
}

if (!empty($_POST[‘event8’])) {
$event[] = $_POST[‘event8’];
}

if (!empty($_POST[‘event9’])) {
$event[] = $_POST[‘event9’];
}

if (!empty($_POST[‘event10’])) {
$event[] = $_POST[‘event10’];
}

include (’./dbconnect.php’);
mysql_query("DELETE FROM events");
foreach ($event as $msg) {
mysql_query(“INSERT INTO events (position, event, date) VALUES (’$position’, ‘$msg’, curdate() )”) or die(mysql_error());
$position++;
}

mysql_close();
header(“location:./admin.php”);
?>[/php]

you have this statement twice, then you missed the 2 in the $_POST
[php]
if (!empty($_POST[‘event2’])) {
$event[] = $_POST[‘event’];
}

if (!empty($_POST[‘event2’])) {
$event[] = $_POST[‘event’];
}
[/php]

[php]
if (!empty($_POST[‘event1’])) {
$event[] = $_POST[‘event1’];
}

if (!empty($_POST[‘event2’])) {
$event[] = $_POST[‘event2’];
}

if (!empty($_POST[‘event3’])) {
$event[] = $_POST[‘event3’];
}

if (!empty($_POST[‘event4’])) {
$event[] = $_POST[‘event4’];
}

if (!empty($_POST[‘event5’])) {
$event[] = $_POST[‘event5’];
}

if (!empty($_POST[‘event6’])) {
$event[] = $_POST[‘event6’];
}

if (!empty($_POST[‘event7’])) {
$event[] = $_POST[‘event7’];
}

if (!empty($_POST[‘event8’])) {
$event[] = $_POST[‘event8’];
}

if (!empty($_POST[‘event9’])) {
$event[] = $_POST[‘event9’];
}

if (!empty($_POST[‘event10’])) {
$event[] = $_POST[‘event10’];
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service