Current location: Hot Scripts Forums » Programming Languages » PHP » Updating MySQL data through cms


Updating MySQL data through cms

Reply
  #1 (permalink)  
Old 12-01-03, 02:09 PM
barryfreed barryfreed is offline
New Member
 
Join Date: Dec 2003
Location: Boston
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Updating MySQL data through cms

Hi.
For the longest time now, I have been trying to create a CMS using PHP and MySQL. I can add to a database, and can delete from it, but when I try to do the Update command, nothing happens.
I can get the text from the DB to appear in text boxes, but when I change the text and resubmit it to the database, nothing happens. Please let me know what I'm doing wrong. Here is what the code looks like:

<?php

$dbcnx = @mysql_connect('localhost', 'login', 'password');
mysql_select_db('blog');

if (isset($_POST['submit'])):
// The details have
// been updated.

$Date = $_POST['Date'];
$Title = $_POST['Title'];
$ID = $_POST['ID'];
$Story = $_POST['Story'];
$sql = "UPDATE items SET
Date='$Date',
Title='$Title'
WHERE ID='$ID'";
if (@mysql_query($sql)) {
echo('<p>details updated.</p>');
} else {
echo('<p>Error updating details: ' .
mysql_error() . '</p>');
}

?>

<p><a href="list.php">Return to list</a></p>

<?php
else: // Allow the user to edit the author
// with ID=$id


$author=@mysql_query("SELECT Date, Title, Story
FROM items
WHERE ID='$ID'");
if (!$author) {
die('<p>Error fetching author details: ' .
mysql_error() . '</p>');
}

$author = mysql_fetch_array($author);

$Date = $author['Date'];
$Title = $author['Title'];
$Story = $author['Story'];

// Convert special characters for safe use
// as HTML attributes.
$Date = htmlspecialchars($Date);
$Title = htmlspecialchars($Title);

?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Edit the author:<br />
ID: <input type="text" name="ID" value="<?=$ID?>" /><br />
Date: <input type="text" name="Date" value="<?=$Date?>" size="20" maxlength="255" /><br />
Title: <input type="text" name="Title" value="<?=$Title?>" size="20" maxlength="255" /><br />
Story:
<textarea name="Story" cols="60" rows="30" tabindex="textarea"><?=$Story?>
</textarea>
<br />
<input type="hidden" name="ID" value="<?=$ID?>" />
<input type="submit" name="submit" value="SUBMIT" /></p>
</form>

<?php endif; ?>

Please let me know where I'm messing up. Thanks.
Reply With Quote
  #2 (permalink)  
Old 12-02-03, 01:09 AM
redbarron redbarron is offline
New Member
 
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Are you quoting the values before inserting them? In Perl you need to escape all values with the quote() function, otherwise a vlaue with a quote in it would cause errors. Also make sure that you have the right to update tables. Some paranoid admins dont grant this right.

John
Reply With Quote
  #3 (permalink)  
Old 12-02-03, 03:43 AM
Stefan's Avatar
Stefan Stefan is offline
Junior Code Guru
 
Join Date: Jun 2003
Location: Utrecht, The Netherlands
Posts: 599
Thanks: 0
Thanked 0 Times in 0 Posts
have you checked the sourcecode of the form to make sure the ID is indeed passed on?
Reply With Quote
  #4 (permalink)  
Old 12-02-03, 05:32 AM
fyrestrtr fyrestrtr is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
Are you sure about
PHP Code:

if (isset($_POST['submit'])): 

or did you just make a typo? Also, add
PHP Code:

error_reporting(E_ALL); 

as the first line of php to get more descriptive error messages.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
Aplication for data entry via telnet to mysql DB JavierAlvarez Script Requests 2 11-27-03 10:29 AM
help plz: format retrieved Mysql data in HTML with PHP paulj000 PHP 2 10-19-03 08:03 PM
Pulling data from MySQl Database w/ PHP? dayzeday PHP 6 10-07-03 07:01 AM


All times are GMT -5. The time now is 06:06 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.