To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

Go Back   IT Management Forum > Intranet Journal > Support Questions & Advice

Support Questions & Advice Get advice and answers to your questions on desktop support, server support and application support.

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-22-2008, 07:45 AM
leeroy leeroy is offline
Registered User
 
Join Date: Sep 2008
Posts: 3
Content managment system

i have been following the cms tutorial posted on your forum has helped me gain a good knowledge in php and mySQL now the problem i have is i am trying to develop a code to edit articles now almost the whole code works apart from the submit part of the code when i login to edit the sections i displays the data alows me to edit the data when i click submit it should post the new querys to mySQL insted it just takes me back to the editArticle.php page, Can anybody help please

Here is the code

<?php
require_once("../includes/Sentry.php");

$sentry = new Sentry();
if ($HTTP_POST_VARS['user'] != ''){
$sentry->checkLogin($HTTP_POST_VARS['user'],$HTTP_POST_VARS['pass'],4,'welcome.php','failed.php');
}

if ($HTTP_GET_VARS['action'] == 'logout'){
if ($sentry->logout()){
echo '<center>You have been logged out</center><br>';
}
}
?>
<?
// Require the classes
require_once('../includes/DbConnector.php');
require_once('../includes/Validator.php');

// Create an object (instance) of the DbConnector and Validator
$connector = new DbConnector();
$validator = new Validator();

//select which database you want to edit
mysql_select_db("web176-contentms");

//If cmd has not been initialized
if(!isset($cmd))
{
//display all the thearticle
$result = mysql_query("select * from cmsarticles order by id");

//run the while loop that grabs all the thearticle scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the thearticle
$title=$r["title"];//take out the title
$id=$r["ID"];//take out the id

//make the title a link
echo "<a href='editArticle.php?cmd=edit&id=$id'>$title - Edit</a>";

echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["Submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM cmsarticles WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>

<form action="editArticle.php" method="post">
<input type=hidden name="ID" value="<?php echo $myrow["id"] ?>">

Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>
Message:<TEXTAREA NAME="thearticle" ROWS=10 COLS=30><? echo $myrow["thearticle"] ?></TEXTAREA>
<br>

<input type="hidden" name="cmd" value="edit">

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

</form>

<? } ?>
<?
if ($_POST["$Submit"])
{
$title = $_POST["title"];
$thearticle = $_POST["thearticle"];

$sql = "UPDATE cmsarticles SET title='$title',thearticle='$thearticle' WHERE id=$id";
//replace theArticles with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>
Reply With Quote
  #2 (permalink)  
Old 01-06-2009, 01:06 PM
Chip Chip is offline
Registered User
 
Join Date: Jan 2009
Location: Cardiff
Posts: 6
can't say i'm entirely certain as to why this problem is arising, however there are a couple of things I noticed about the code:

line 5: if ($HTTP_POST_VARS['user'] != ''){
you've opened " but not closed it

can't remember if it matters but on this line
$sql = "UPDATE cmsarticles SET title='$title',thearticle='$thearticle' WHERE id=$id";
you've got quotes around $title and $thearticle but not around $id
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 04:01 AM.





Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0