News AdministrationInvalid image type:- " . $_FILES['newimage']['name'] . ". It has been ignored.\n"; } } else { $newatt=''; } } else { $newatt=''; } // now replace the original image if reqd. if ($newatt!=='') { $att=$newatt; } $linkurl=$HTTP_POST_VARS["linkurl"]; $attdesc1=$HTTP_POST_VARS["attdesc1"]; $attdesc1=str_replace("'",'\\\'',$attdesc1); // escape single quotes $attdesc2=$HTTP_POST_VARS["attdesc2"]; $attdesc2=str_replace("'",'\\\'',$attdesc2); // escape single quotes // check for new attachment(s) if (isset($_FILES['newattachment1']['name'])) { if ($_FILES['newattachment1']['name']!=='') { // check valid file type if ( ($_FILES['newattachment1']['type'] == "application/msword") or ($_FILES['newattachment1']['type'] == "application/pdf") or ($_FILES['newattachment1']['type'] == "text/plain") or ($_FILES['newattachment1']['type'] == "application/rtf") or ($_FILES['newattachment1']['type'] == "application/vnd.ms-excel") or ($_FILES['newattachment1']['type'] == "application/vnd.ms-powerpoint") ) { $newatt1=$_FILES['newattachment1']['name']; $newatt1=str_replace("'",'',$newatt1); // remove single quotes $newatt1=str_replace(' ','',$newatt1); // remove spaces } else { $newatt1=''; // invalid type echo "Invalid file type:- " . $_FILES['newattachment1']['name'] . ". It has been ignored. \n"; } } else { $newatt1=''; } } else { $newatt1=''; } // now replace the original attachment if reqd. if ($newatt1!=='') { $att1=$newatt1; } if (isset($_FILES['newattachment2']['name'])) { if ($_FILES['newattachment2']['name']!=='') { // check valid file type if ( ($_FILES['newattachment2']['type'] == "application/msword") or ($_FILES['newattachment2']['type'] == "application/pdf") or ($_FILES['newattachment2']['type'] == "text/plain") or ($_FILES['newattachment2']['type'] == "application/rtf") or ($_FILES['newattachment2']['type'] == "application/vnd.ms-excel") or ($_FILES['newattachment2']['type'] == "application/vnd.ms-powerpoint") ) { $newatt2=$_FILES['newattachment2']['name']; $newatt2=str_replace("'",'',$newatt2); // remove single quotes $newatt2=str_replace(' ','',$newatt2); // remove spaces } else { $newatt2=''; // invalid type echo "Invalid file type:- " . $_FILES['newattachment2']['name'] . ". It has been ignored. \n"; } } else { $newatt2=''; } } else { $newatt2=''; } // now replace the original attachment if reqd. if ($newatt2!=='') { $att2=$newatt2; } $dbh=mysql_connect("localhost","demo","demo") or die("Could not connect: " . mysql_errno() . ": " . mysql_error()); mysql_select_db("demodb") or die("Select failed: " . mysql_errno() . ": " . mysql_error()); // build the sql and update the database if ($newsid!=='-1') { // amend record $query="update e2bnnews set title='$title', brief_desc='$desc', story='$story', contact_name='$name', contact_email='$email', contact_phone='$phone', establishment='$est', start_date='$start_date', expiry_date='$expiry_date', image='$att', imgdesc='$imgdesc', status='$status', linkurl='$linkurl', atturl1='$att1', attdesc1='$attdesc1', atturl2='$att2', attdesc2='$attdesc2' "; // finish it off $query.=" where id=$newsid"; $sth=mysql_query($query) or die("Update failed: " . mysql_error() . "SQL = " . $query); echo " Record '$title' has been updated. \n"; } else { // create record $query="insert into e2bnnews (title,brief_desc,story,contact_name,contact_email,contact_phone,establishment,start_date,expiry_date,image,imgdesc,confirmation,status,linkurl,atturl1,attdesc1,atturl2,attdesc2) values ('$title', '$desc', '$story', '$name', '$email', '$phone', '$est', '$start_date', '$expiry_date', '$att', '$imgdesc', '$conf', '$status', '$linkurl','$att1','$attdesc1','$att2','$attdesc2')"; $sth=mysql_query($query) or die("Insert failed: " . mysql_error() . "SQL = " . $query); // confirm record creation $query="select id from e2bnnews where title='$title' and brief_desc='$desc'"; $sth=mysql_query($query) or die("Query failed: " . mysql_error() . " SQL = " . $query); $num_rows = mysql_num_rows($sth); // if there is NOT a record, display error if ($num_rows==0) { echo " There was a problem submitting your news item. \n"; } else { $row=mysql_fetch_array($sth, MYSQL_ASSOC); echo "Your news item has been submitted. \n"; echo "The item will appear on the web site when it has been approved. \n"; } } // deal with any attachment(s) (copy to server) if ($newatt!=='') { copy ($_FILES['newimage']['tmp_name'], "resources/$att") or die ("Could not store image"); echo "Your file " . $att . " (type:" . $_FILES['newimage']['type'] . ", size:" . $_FILES['newimage']['size'] . ") has been attached to your submission. \n"; } // deal with any attachment(s) (copy to server) if ($newatt1!=='') { copy ($_FILES['newattachment1']['tmp_name'], "resources/$att1") or die ("Could not store attachment"); echo "Your file " . $att1 . " (type:" . $_FILES['newattachment1']['type'] . ", size:" . $_FILES['newattachment1']['size'] . ") has been attached to your submission. \n"; } if ($newatt2!=='') { copy ($_FILES['newattachment2']['tmp_name'], "resources/$att2") or die ("Could not store attachment"); echo "Your file " . $att2 . " (type:" . $_FILES['newattachment2']['type'] . ", size:" . $_FILES['newattachment2']['size'] . ") has been attached to your submission. \n"; } } ?> SQL = " . $query); $num_rows = mysql_num_rows($sth); // if there is NOT a record, display error if ($num_rows==0) { echo "Record not found!\n"; } else { // delete record $query="delete from e2bnnews where id=$newsid"; $sth=mysql_query($query) or die("Delete failed: " . mysql_error() . "SQL = " . $query); echo " Record has been deleted.\n"; } } ?>
Record not found!'; $title=''; $desc=''; } else { $statmsg='Delete entry'; $row=mysql_fetch_array($sth, MYSQL_ASSOC); $title=$row['title']; $desc=$row['brief_desc']; } ?>No news item selected!'; } else { $newsid='-1'; if (isset($_POST["newsitem"])) { $newsid=$_POST["newsitem"]; } if ($_POST["display"]==='Create new entry') { $newsid='-1'; } $query="select * from e2bnnews where id=$newsid"; $sth=mysql_query($query) or die("Query failed: " . mysql_error() . "SQL = " . $query); $num_rows = mysql_num_rows($sth); // if there is NOT a record, display error if ($num_rows==0) { $statmsg=' Create new entry'; $title=''; $desc=''; $story=''; $name=''; $email=''; $phone=''; $est=''; $start=''; $exp=''; $image=''; $imgdesc=''; $status=''; $conf=''; $start[0]=''; $start[1]=''; $start[2]=''; $exp[0]=''; $exp[1]=''; $exp[2]=''; $linkurl=''; $atturl1=''; $attdesc1=''; $atturl2=''; $attdesc2=''; } else { $statmsg='Amend entry'; $row=mysql_fetch_array($sth, MYSQL_ASSOC); $title=$row['title']; $desc=$row['brief_desc']; $story=$row['story']; $name=$row['contact_name']; $email=$row['contact_email']; $phone=$row['contact_phone']; $est=$row['establishment']; $start=explode('-',$row['start_date']); $exp=explode('-',$row['expiry_date']); $image=$row['image']; $imgdesc=$row['imgdesc']; $status=$row['status']; $conf=$row['confirmation']; $linkurl=$row['linkurl']; $atturl1=$row['atturl1']; $attdesc1=$row['attdesc1']; $atturl2=$row['atturl2']; $attdesc2=$row['attdesc2']; } ?>
|