473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

'Edit' form doesn't update the database.

jwagener
Hi,

I am building a content menager/news manager and am having trouble with my edit page.

I have never embarked on a project like this before and am a bit of noob to php and mysql development.


Here are the symtoms: There are no errors but when i click the EDIT button nothing happens and the original text is still there.

Here is the code:

[PHP]
<?php

$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("boxkitecmsbeta", $connection);

// Display the data in the form.
$query = "SELECT * FROM news";
$result = mysql_query($query);

$row = mysql_fetch_array($result);

?>
[/PHP]
[HTML]
<form action="<?php echo $self ?>" method="post">
<input type="hidden" name="<?php echo $update ?>">
News ID: <font color="red"><?php echo $row['id'] ?><br /></font>
Date / Time: <font color="red"><?php echo $row['date_updated'] ?><br /><br /></font>
Title: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp; <input type="text" name="$title" value="<?php echo $row['title'] ?>" size="35"><br />
Short Story: <textarea name="$short_story" cols="45" rows="10"><?php echo $row['short_story'] ?></textarea><br />
Long Story: <textarea name="$long_story" cols="45" rows="10"><?php echo $row['long_story'] ?></textarea><br />
<input type="submit" value="edit">
</form>
[/HTML]

please could someone go through my, very very simple, code and see where my problems lie??

Thanks

J
Jun 29 '07 #1
6 1650
ronnil
134 Expert 100+
Have you checked the result source to see if any errors pop up there? i see that you're using <?php ?> tags inside the html-tags. If any warning/non-fatal error messages where to show, your browser simply ignores it.

In you can see the source by clicking View > Page Source (or ctrl+U in firefox)
Jun 29 '07 #2
Hi, thanks 4 ur response. Could you see anything wrong in the code because i can see no errors.

But im going to do some serious debugging and create 'or die()' functions.
Jun 29 '07 #3
kovik
1,044 Expert 1GB
You have a lot of variables that come out of nowhere, such as $self, $update, and $title. Also, the $title isn't in any PHP tags, so it's a literal string.

And where do you handle the form posting? If "nothing's happening," your posting code would be the culprit, not the form.
Jun 29 '07 #4
I do dont i. hahaha


I notice that i have not given you all my code. lol

anyway, i think i look like a fool.


[PHP]
<?php

$id = $_POST['id'];
$date_updated = $_POST['date_updated'];
$short_story = $_POST['short_story'];
$long_story = $_POST['long_story'];

$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("boxkitecmsbeta", $connection);

function updateNews($updateNews) {
// Insert the updated content.
$sql = "UPDATE news SET title='$title', short_story='$short_story', long_story='$long_story', date_updated='NOW()'";
$tin = mysql_query($sql)
or die("Query UPDATE news failed: " . mysql_error());
}

// Display the data in the form.
$query = "SELECT * FROM news";
$result = mysql_query($query)
or die("Query SELECT * FROM news failed: " . mysql_error());

$row = mysql_fetch_array($result);

?>

<form action="editnews.php" method="post">
News ID: <font color="red"><?php echo $row['id'] ?><br /></font>
Date / Time: <font color="red"><?php echo $row['date_updated'] ?><br /><br /></font>
Title: <input type="text" name="<?php echo $title ?>" value="<?php echo $row['title'] ?>" size="35"><br />
Short Story: <textarea name="<?php echo $short_story ?>" cols="45" rows="10"><?php echo $row['short_story'] ?></textarea><br />
Long Story: <textarea name="<?php echo $long_story ?>" cols="45" rows="10"><?php echo $row['long_story'] ?></textarea><br />
<input type="submit" value="edit">
</form>
[/PHP]

anyway, heres the revised code. Please have a look at it.
Jun 29 '07 #5
kovik
1,044 Expert 1GB
Firstly, you haven't checked if any of those post variables exist before attempting to use them. Secondly, you never use your updating function. It just sits there.
Jun 29 '07 #6
pbmods
5,821 Expert 4TB
Heya, jwagener.

Just wanted to say that your CMS project is very ambitious, and I think it's great that you're 'getting your feet wet', as it where by building such a comprehensive application.

Keep at it. By the time you're done, you'll know a heck of a lot more about PHP, MySQL and application design than you did when you started.

I think you'll like the end result.
Jun 29 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Jim | last post by:
Hi, Let me explain how I'd generally do things. For a page where the user edits data, I'd generally call it something like editfred.php (for example), the page which updates the data would be...
25
by: dixie | last post by:
I have some code that adds new records into a table for each ID in a list box when a button on a form is clicked. This works fine. My problem now is that I wish to be able to edit all the records...
1
by: MissiMaths | last post by:
I am creating a reference table of all the information used to draw a sample. I start by first clearing the table in form1 using a delete query. Then after the user selects certain options, i...
2
by: Sky | last post by:
Hello: Another question about trying to wring functionality from a DataGrid... Have a DB table of "Contacts" -- 14 or more fields per record Show in datagrid -- but only 5 columns (First,Last,...
1
by: JeremyGrand | last post by:
I've read what's available here, but can't seem to make this work right. I'm experimenting with components on a form, although I'd rather create the pieces & assemble them in code, but that's...
9
bhcob1
by: bhcob1 | last post by:
Hey guys, 'Update or CancelUpdate without AddNew or Edit' On my database i keep occasionly get this error when i try and edit a field, it is not everytime. It will be working fine and then this...
2
by: sara | last post by:
I use Allen Browne's Audit Trail code in everything I do and I love it. Recently, I've run into a problem I can't figure out. I have a database with about 35 lookup tables. I am creating an...
2
by: colesslow | last post by:
i have these asp files to edit a record in my sql server..but it can't be done. the error is Error Type: ADODB.Recordset (0x800A0E7D) The connection cannot be used to perform this operation. It...
1
by: chromis | last post by:
Hi, I'm having trouble fully implementing the edit section of a contact admin system, so far I have written the following: - Bean (Contact.cfc) - Data Access object (ContactDAO.cfc) - Gateway...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.