I have made up a php script and am struggling to input data into an online table and put it into the database.
The online table is here:-
http://asap-digital.org/admin/attendees.php?id=309
all I want to do is to put the data entered into this online table into a new database table.
Here is the code that I have right now:-
[php]<?php
error_reporting(E_ERROR);
session_start();
include("…/includes/config.php");
//if(!isLoggedIn()){
//header(“Location: login.php”);
//}
if(isset($_POST[‘submit’])){
foreach($_POST[‘attended’] as $userID){
$attendedList .= “$userID,”;
}
mysql_query(“UPDATE asap_session SET attended = CONCAT(attended, ‘$attendedList’) WHERE id = '”.$_GET[‘id’]."’");
foreach($_POST[‘attended’] as $userID){
{
echo “
// echo $userID;
$query = mysql_query(“SELECT attendence FROM accounts WHERE id = $userID”) or die(mysql_error());
$vattendence = mysql_fetch_array($query);
$Attendence = $vattendence[‘attendence’];
$Attendence2 = $Attendence +0;
mysql_query(“UPDATE accounts SET attendence = ‘$Attendence2’ WHERE id = $userID”);
$tablename = date(“MjY”);
// $monsterIds = array();
//while(($row = mysql_fetch_array($result)) !== false) {
// $monsterIds[] = $row[‘id’];
//}
//mysql_query(“INSERT INTO user_team (m1, m2, m3, m4, m5, m6) VALUES (’{$monsterIds[0]}’, ‘{$monsterIds[2]}’, ‘{$monsterIds[3]}’, ‘{$monsterIds[4]}’, ‘{$monsterIds[5]}’)”) or die(mysql_error());
$attendeesIDs = array();
$result = mysql_query("
SELECT name
FROM accounts
WHERE id = $userID") or
die(mysql_error());
while(($row = mysql_fetch_array($result)) !== false) {
echo “Comment1” , $Comment1; “
”;
echo “
”;
echo "Name: " . $row[0] . "<br />";
echo "<br />";
mysql_query(“INSERT INTO “.$tablename.” (name, Comment1) VALUES (’. $row[0] .’, $Comment1)”) or die(mysql_error());
exit;}
}
}
}
if(isset($_POST[‘complete’])){
mysql_query(“UPDATE asap_session SET complete = ‘1’ WHERE id = '”.$_GET[‘id’]."’");
}
$query = mysql_query(“SELECT * FROM asap_session WHERE id = '”.$_GET[‘id’]."’") or die(mysql_error());
$result = mysql_fetch_array($query);
// Header of form
$body .= “<div id=“header”>”;
$body .= “”;
$body .= “<h3 style=\align=“left”>Session Attendees:- “.$result[‘activity’].”:- “.$result[‘house’].” “.($result[‘complete’] == 0 ? “(Active)” : “(Complete)”).””;
$body .= “<p style=“margin: 0 0 10px 15px;”>Date:- “.$result[‘date’].”
”;$body .= “<div style=“margin-left: 15px;”><a href=“index.php”>Dashboard - <a href=“session.php”>Create Session”;
// Main form section
$body .= “<div id=“main” style=“margin-top: 15px;”>”;
$body .= “<form action=”" method=“POST”>";
$body .= “<table width=“35%”>”;
$body .= “
$body .= "<td align="right"width=12>Attended? ";
$body .= “<td align=“left”>Name”;
$body .= “<td align=“left”>Input comment 1”;
$body .= “<td align=“left”>Input comment 2”;
$body .= “<td align=“left”>Click here to edit”;
//$body .= “<td align=“left”>Click here to delete”;
$body .= “
$attended = explode(",", $result[‘attended’]);
while($row = mysql_fetch_array( $result ))
if($result[‘complete’] == 1){
$and = " AND (";
foreach($attended as $user){
if($user <> '')
$and .= "id LIKE '%".$user."%' OR ";
}
$and = substr($and, 0, -4);
$and .= ")";
}
$query = mysql_query(“SELECT * FROM accounts WHERE house LIKE '%”.$result[‘house’]."%’ $and ORDER BY name ASC") or die(mysql_error());
while($row = mysql_fetch_assoc($query)){
$body .= “
$body .= “<td align=“right”><input type=“checkbox” name=“attended[]” “.(in_array($row[‘id’], $attended) ? “checked=“checked” disabled=“disabled”” : “” ).” value=”".$row[‘id’].""/>";
$body .= “<td align=“left”>”.$row[‘name’].":- “.$row[‘house’].”";
$body .= "<td align=\"right\"><input type=\"text\" name=\"comment1\" value=\"".$_POST['Comment1']."\"/></td>";
$Comment1 = $_POST[‘Comment1’];
$body .= "<td align=\"right\"><input type=\"text\" name=\"comment2[]\" ".(in_array($row['id'], $Comment2) ? : "" )." value=\"".$_POST['id']."\"/></td>";
$body .= '<td align=\"left\"><b><font color="#663300"><a href="edit.php?id=' . $row['id'] . '">edit</a></font></b></td>';
// $body .= ‘<td align=“left”>delete’;
$body .= “
}
$body .= “”;
if($result[‘complete’] == 0){
$body .= “<div align=“left”><input type=“submit” name=“submit” value=“Update Session”/> <input type=“submit” name=“complete” value=“Complete Session”/>”;
}
$body .= “”;
$body .= “<div class=“clear”>”;
$body .= “”;
include("…/includes/header.php");
include("…/includes/footer.php");
render($header, $body, $footer)
?>
Any supprt is most welcomed.
Stephen