Advertisement

06.20.2008 at 03:11PM PDT, ID: 23503761
[x]
Attachment Details

Content management PHP Problem

Asked by Farouk007 in PHP and Databases, PHP Scripting Language, MySQL

I am a beginner at PHP coding and I would appreciate any help that is offered. I am trying to build a Content Management System for my website. I have made a mysql database, "Add Contentent Page" and "View Content Page". They all work wonderfully. I can Add and view my information with no problems.  Now I am buildng a Admin page where I can Edit and Delete the content. When I try this page I get a "You have an error in your SQL syntax near " at line 1.

I know what is causing this error but have no idea why it is happening. I have 5 fields in my Table = ID, projectname, Dateinput, status and content. When I call echo $projectname the date will come up, when I call echo $id the projectname will come up. Any help given is much appreciated.

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
<?php
include 'config.php';
   
   // connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
 
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
 
 
 
if(isset($_GET['del']))
{
   $query = "DELETE FROM projects 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 MGsoft Project Management</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function delArticle(id, projectname)
{
   if (confirm("Are you sure you want to delete '" + projectname + "'"))
   {
      window.location.href = 'cms-admin.php?del=' + id;
   }
}
</script>
</head>
 
<body>
<?php
$query   = "SELECT projectname, dateinput, status, content FROM projects 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>Projectname</strong></td>
<td width="150"><strong>Action</strong></td>
</tr>
<?php
while(list($id, $projectname, $dateinput, $status, $content) = mysql_fetch_array($result, MYSQL_NUM))
{
 
?>
<tr bgcolor="#FFFFFF">
<td width="500">
<?php echo $id;?>
</td>
<td width="150" align="center">
 
<a href="show2.php?id=<?php echo $content;?>" target="_blank">view</a>
| <a href="cms-edit.php?id=<?php echo $id;?>">edit</a>
| <a href="javascript:delArticle('<?php echo $id;?>',
'<?php echo $projectname;?>');">delete</a></td>
</tr>
 
}
 
 
mysql_close();
 
?>
</table>
<p align="center"><a href="cms-add.php">Add an article</a></p>
</body>
</html>
[+][-]06.20.2008 at 03:39PM PDT, ID: 21835452

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.20.2008 at 10:26PM PDT, ID: 21836449

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.21.2008 at 12:40AM PDT, ID: 21836757

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, PHP Scripting Language, MySQL
Sign Up Now!
Solution Provided By: Roonaan
Participating Experts: 3
Solution Grade: B
 
 
[+][-]06.23.2008 at 08:53AM PDT, ID: 21847508

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628