Jump to content

Help on touching up Admin


danlew

Recommended Posts

I have put together this code from one of the tutorials found here http://www.php-mysql-tutorial.com/cms-admin-php-mysql.php

and so far have this working;

 

cms-admin.php

<?php

  require_once('db.inc.php');

if(isset($_GET['del']))

{

// remove the article from the database

$query = "DELETE FROM news WHERE id = '{$_GET['del']}'";

mysql_query($query) or die('Error : ' . mysql_error());

 

// then remove the cached file

$cacheDir  = dirname(__FILE__) . '/cache/';

$cacheFile = $cacheDir . '_' . $_GET['id'] . '.html';

 

@unlink($cacheFile);

 

// and remove the index.html too because the file list

// is changed

@unlink($cacheDir . 'index.html');

 

// redirect to current page so when the user refresh this page

// after deleting an article we won't go back to this code block

header('Location: ' . $_SERVER['PHP_SELF']);

exit;

}

?>

<html>

<head>

<title>Admin Page For Content Management System (CMS)</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript">

function delArticle(id, title)

{

if (confirm("Are you sure you want to delete '" + title + "'"))

{

window.location.href = 'cms-admin.php?del=' + id;

}

}

</script>

</head>

 

<body>

<?php

$query = "SELECT id, title FROM information ORDER BY id";

$result = mysql_query($query) or die('Error : ' . mysql_error());

?>

<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#999999">

<tr align="center" bgcolor="#CCCCCC">

  <td width="500"><strong>Title</strong></td>

  <td width="150"><strong>Action</strong></td>

</tr>

<?php

while(list($id, $title) = mysql_fetch_array($result, MYSQL_NUM))

{

 

?>

<tr bgcolor="#FFFFFF">

  <td width="500">

  <?php echo $title;?>

  </td>

  <td width="150" align="center"><a href="article2.php?id=<?php echo $id;?>" target="_blank">view</a>

  | <a href="cms-edit.php?id=<?php echo $id;?>">edit</a> | <a href="javascript:delArticle('<?php echo $id;?>', '<?php echo $title;?>');">delete</a></td>

</tr>

<?php

}

 

include 'library/closedb.php';

?>

</table>

<p align="center"><a href="cms-add.php">Add an article</a></p>

</body>

</html>

 

but when I go to ww.nzsocietythai.org/library/cms-admin.php I have a few errors which I dont understand. Secondly I need to edit the code to suit my datasbe which has 3 tables 1 table has an image file, which will involve uploading images, how can I add this code to suit?

 

Kindly awaiting suggestions and possible help on code!

Link to comment
Share on other sites

Ok I have put together the code successfully from the tutorial link above, but I am stuck with adding image upload option to one of my tables in php.

 

This is what I have done so far but it doesnt seems to be uploading?

 

<html>

<head>

<title>Add An Article</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">

<!--

.box {

font-family: Arial, Helvetica, sans-serif;

font-size: 12px;

border: 1px solid #000000;

}

-->

</style>

</head>

 

<body>

<?php

  require_once('db.inc.php');

if(isset($_POST['save']))

{

$title  = $_POST['title'];

$content = $_POST['content'];

$images = $_POST['images'];

 

if(!get_magic_quotes_gpc())

{

$title  = addslashes($title);

$content = addslashes($content);

$images = addslashes($images);

}

 

 

$query = "INSERT INTO events (title, content, images) VALUES ('$title', '$content', 'images')";

mysql_query($query) or die('Error ,query failed');

 

 

echo "Article '$title' added";

}

?>

<FORM ACTION="upload.php" METHOD="post" ENCTYPE="multipart/form-data">

  <table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center">

    <tr>

      <td width="100">Title</td>

      <td><input name="title" type="text" class="box" id="title"></td>

    </tr>

    <tr>

      <td width="100">Content</td>

      <td><textarea name="content" cols="50" rows="10" class="box" id="content"></textarea></td>

    </tr>

    <tr>

      <td width="100">Image</td>

      <td><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="34%" HEIGHT="75">

       

        <TR>

          <TD WIDTH="6%" HEIGHT="24" BGCOLOR="silver"> </TD>

          <TD WIDTH="88%" HEIGHT="24" BGCOLOR="#FFFFFF"><P ALIGN="CENTER">

              <INPUT TYPE="file" NAME="fileupload" SIZE="30">

                </TD>

          <TD WIDTH="6%" HEIGHT="24" BGCOLOR="#FFFFFF"> </TD>

        </TR>

        <TR>

          <TD HEIGHT="24" COLSPAN="3" BGCOLOR="#FFFFFF"><CENTER>

              <P>

                <INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Upload File">

                </CENTER></TD>

        </TR>

      </TABLE></td>

    </tr>

    <tr>

      <td colspan="2" align="center"><input name="save" type="submit" class="box" id="save" value="Save Article"></td>

    </tr>

  </table>

</form>

</body>

</html>

Link to comment
Share on other sites

Ok this is my latest trial run with code that can be seen below to get it working, image doesnt upload it gets an error saying - "Could Not Copy, Wrong Filetype" maybe its something to do with the file type I have named in the code or didnt create on my server?

 

I followed it all perfectly from tutorial here;

www.phpfreaks.com/tutorials/36/0.php

 

All help will be much appreciated...

 

 

<html>

<head>

<title>Add An Article</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">

<!--

.box {

font-family: Arial, Helvetica, sans-serif;

font-size: 12px;

border: 1px solid #000000;

}

-->

</style>

</head>

 

<body>

<?php

require_once('db.inc.php');

if(isset($_POST['save']))

{

$title = $_POST['title'];

$content = $_POST['content'];

$image = $_POST['image'];

 

if(!get_magic_quotes_gpc())

{

$title = addslashes($title);

$content = addslashes($content);

$image = addslashes($image);

}

 

 

$query = "INSERT INTO events (title, content, image) VALUES ('$title', '$content', '$image')";

mysql_query($query) or die('Error ,query failed');

 

 

echo "Article '$title' added";

}

?>

<form method="post">

<table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center">

<tr>

<td width="100">Title</td>

<td><input name="title" type="text" class="box" id="title"></td>

</tr>

<tr>

<td width="100">Content</td>

<td><textarea name="content" cols="50" rows="10" class="box" id="content"></textarea></td>

</tr>

<tr>

<td width="100"> </td>

<td><input type="file" name="imagefile">

<br>

<input type="submit" name="Submit" value="Submit">

<?

if(isset( $Submit ))

{

//If the Submitbutton was pressed do:

 

if ($_FILES['imagefile']['type'] == "image/jpg"){

copy ($uploaddir.$_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name'])

or die ("Could not copy");

echo "";

echo "Name: ".$_FILES['imagefile']['name']."";

echo "Size: ".$_FILES['imagefile']['size']."";

echo "Type: ".$_FILES['imagefile']['type']."";

echo "Copy Done....";

}

 

else {

echo "<br><br>";

echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";

}

}

 

?></td>

</tr>

<tr>

<td colspan="2" align="center"><input name="save" type="submit" class="box" id="save" value="Save Article"></td>

</tr>

</table>

</form>

</body>

</html>

Link to comment
Share on other sites

Use code tags

 

check comments in code

 

<html>
<head>
<title>Add An Article</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.box {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
border: 1px solid #000000;
}
-->
</style>
</head>

<body>
<?php
require_once('db.inc.php');
if(isset($_POST['save']))
{
$title = $_POST['title'];
$content = $_POST['content'];
$image = $_POST['image'];

if(!get_magic_quotes_gpc())
{
$title = addslashes($title);
$content = addslashes($content);
$image = addslashes($image);
}


$query = "INSERT INTO events (title, content, image) VALUES ('$title', '$content', '$image')";
mysql_query($query) or die('Error ,query failed');


echo "Article '$title' added";
}
?>
<form method="post">
<table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center">
<tr>
<td width="100">Title</td>
<td><input name="title" type="text" class="box" id="title"></td>
</tr>
<tr>
<td width="100">Content</td>
<td><textarea name="content" cols="50" rows="10" class="box" id="content"></textarea></td>
</tr>
<tr>
<td width="100"> </td>
<td><input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">
<?php
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:

if ($_FILES['imagefile']['type'] == "image/jpg"){ //<--- Note the type (check the change below and post the error)
copy ($uploaddir.$_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name'])
or die ("Could not copy");
echo "";
echo "Name: ".$_FILES['imagefile']['name']."";
echo "Size: ".$_FILES['imagefile']['size']."";
echo "Type: ".$_FILES['imagefile']['type']."";
echo "Copy Done....";
}

else {
echo "<br><br>";
echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['type'].")<br>"; //<--Note change from name to type
}
}

?></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="save" type="submit" class="box" id="save" value="Save Article"></td>
</tr>
</table>
</form>
</body>
</html>

 

post new error

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.