Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Having An UPDATE Problem...
Old 10-27-2005, 09:14 PM Having An UPDATE Problem...
Novice Talker

Posts: 9
Trades: 0
Hey guys, i'm having a bit of trouble with this news updating system...I have a main manage page which lists all of the news entries and beside each one there is an "edit entry" link which brings it to a page where the user is able to update the information and then submit it.
Here is the code for the page that "Edit Entry" is linked too.
PHP Code:
<?

require_once('../../mysql_connect.php');
$query "SELECT name, date, message FROM news WHERE id=$id";
$result = @mysql_query($query);
$row mysql_fetch_array ($resultMYSQL_NUM);
echo 
'<div id="wrapper" align="center">
<span class="title"><b>Edit News Entry</b></span><br /><br />
<form method="post" action="editnews_handler.php">

<span>Date:</span><br />

<INPUT TYPE="TEXT" NAME="date" VALUE="' 
$row[1] . '" size=20><br /><br>

<span>Message:</span><br />
<textarea name="message" cols="60" rows="5" wrap="physical">' 
$row[2] . '</textarea>
<br />
<span style="font-size:10px">**Try to keep image\'s width smaller than 400 pixles!</span>
<br />
<br />

<span>Name:</span><br />

<div class="submit"><INPUT TYPE="TEXT" NAME="name" VALUE="' 
$row[0] . '"  size=40 ></div><br /><br />

<INPUT TYPE="submit" name="submit" value="submit news">

</form>
</div>'
;

mysql_close();
?>
This page displays the information in the form perfectly. The problem is it's handler. Which is this:

PHP Code:
<? 
if($_POST['submit']) 
{
require_once(
'../../mysql_connect.php');
$query "UPDATE news SET message='$a', name='$b', date='$c' WHERE id=$id";
$result mysql_query($query);}
?>
Query Updated.
<br />
<a href="/manage" target="_self">Go Back</a>
Now I know i have not named these variables yet, but i'm not really sure how, or even if this method is correct.
Any help is very appreciative. Thanks!

Last edited by iisthesloth; 10-27-2005 at 10:07 PM..
iisthesloth is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-28-2005, 03:04 AM
Novice Talker

Posts: 12
Trades: 0
What is the error message that you are getting?

Roj
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
niyogi is offline
Reply With Quote
View Public Profile
 
Old 10-28-2005, 12:05 PM
Novice Talker

Posts: 9
Trades: 0
Now im not getting an error, its just not updating...

I am trying to make it so when you click on "Edit Entry", it displays the entry in a new page and also the information in the correct form. Which it does. But when you click to submit the new information, it is soposed to update the old info with a handler page. The mySQL database has 4 tables. id, name, date, and message. I am not sure how to write the handler page for updated submited information.

I changed the handler's page to this (whcih is the page that should update the current information, but it just isn't having any effect.
PHP Code:
<?
if($_POST['submit'])
{
$name $_POST['name'];
$date $_POST['date'];
$message $_POST['message'];
$id $_GET['id'];

require_once(
'../../mysql_connect.php');
$query "UPDATE news SET message='$message', name='$name', date='$date' WHERE id=$id";
$result mysql_query($query);}
?>

Last edited by iisthesloth; 10-30-2005 at 11:50 AM..
iisthesloth is offline
Reply With Quote
View Public Profile
 
Old 10-28-2005, 02:11 PM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Trades: 0
Hi there,

You need to pass the $id variable in the form as it is only the form fields that will be passed to the handler.
Basically the handler is not picking up the $_GET['id'] variable as it is not passed on. You need to insert a hidden form field called id that has the value of the news item id you are trying to update.

Hope this helps

Ian
__________________
Found this useful? - HIT MY TALKUPATION!


Please login or register to view this content. Registration is FREE
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 10-28-2005, 02:57 PM
Novice Talker

Posts: 9
Trades: 0
hmm interesting. Thanks for the help...
This is what I did, I'm probably doing something wrong.

PHP Code:
<?

require_once('../../mysql_connect.php');
$query "SELECT name, date, message FROM news WHERE id=$id";
$result = @mysql_query($query);
$row mysql_fetch_array ($resultMYSQL_NUM);
echo 
'<div id="wrapper" align="center">
<span class="title"><b>Edit News Entry</b></span><br /><br />
<form method="post" action="editnews_handler.php">

<span>Date:</span><br />

<INPUT TYPE="TEXT" NAME="date" VALUE="' 
$row[1] . '" size=20><br /><br>
<input type="hidden" name="id" value="'
.$row['1'].'" />

<span>Message:</span><br />
<textarea name="message" cols="60" rows="5" wrap="physical">' 
$row[2] . '</textarea>
<br />
<span style="font-size:10px">**Try to keep image\'s width smaller than 400 pixles!</span>
<br />
<br />

<span>Name:</span><br />

<div class="submit"><INPUT TYPE="TEXT" NAME="name" VALUE="' 
$row[0] . '"  size=40 ></div><br /><br />

<INPUT TYPE="submit" name="submit" value="submit news">

</form>
</div>'
;

mysql_close();
?>
I only added a hidden field for the date to test. You can also see it in the source code on the edit entry page. I kind of understand what your saying, but I need a little assistance. Thanks alot.
iisthesloth is offline
Reply With Quote
View Public Profile
 
Old 10-29-2005, 12:53 PM
Novice Talker

Posts: 9
Trades: 0
I guess I don't know where to put the hidden field. The handler or the page with the form?
iisthesloth is offline
Reply With Quote
View Public Profile
 
Old 10-30-2005, 03:52 PM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Trades: 0
Hi there again,

Sorry its a bit late, but I've been kind of busy. The hidden field goes into the form where you have put it, but your coding style is different to mine and I don't follow it that well. What I have noticed is that you are using the same row element for the date field AND the id field. This cannot be right as the two row elements for id and date must be distinct from each other (ie different columns in your table.

If I assume that your table is set out as follows:

col[0] = name, col[1] = date, col[2] = message and col[3] = id, the following code should work:
PHP Code:
<? 

require_once('../../mysql_connect.php'); 
$query "SELECT name, date, message FROM news WHERE id=$id"
$result = @mysql_query($query); 
$row mysql_fetch_array ($resultMYSQL_NUM); 
echo 
'<div id="wrapper" align="center"> 
<span class="title"><b>Edit News Entry</b></span><br /><br /> 
<form method="post" action="editnews_handler.php"> 

<span>Date:</span><br /> 

<INPUT TYPE="TEXT" NAME="date" VALUE="' 
$row[1] . '" size=20><br /><br> 
<input type="hidden" name="id" value="' 
$row[3] . '" /> 

<span>Message:</span><br /> 
<textarea name="message" cols="60" rows="5" wrap="physical">' 
$row[2] . '</textarea> 
<br /> 
<span style="font-size:10px">**Try to keep image\'s width smaller than 400 pixles!</span> 
<br /> 
<br /> 

<span>Name:</span><br /> 

<div class="submit"><INPUT TYPE="TEXT" NAME="name" VALUE="' 
$row[0] . '"  size=40 ></div><br /><br /> 

<INPUT TYPE="submit" name="submit" value="submit news"> 

</form> 
</div>'


mysql_close(); 
?>
Let me know how you get on.
Regards
Ian
__________________
Found this useful? - HIT MY TALKUPATION!


Please login or register to view this content. Registration is FREE
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 10-30-2005, 04:25 PM
Novice Talker

Posts: 9
Trades: 0
Still not updating...I'm starting to think it may be that the handler page is wrong. Which is this now.
PHP Code:
<?
if($_POST['submit'])
{
$name $_POST['name'];
$date $_POST['date'];
$message $_POST['message'];
$id $_GET['id'];

require_once(
'../../mysql_connect.php');
$query "UPDATE news SET message='$message', name='$name', date='$date' WHERE id=$id";
$result mysql_query($query);
} else {
echo 
'Query did not update.;';
}
?>
It's weird because i'm not getting any errors.
iisthesloth is offline
Reply With Quote
View Public Profile
 
Old 10-30-2005, 04:37 PM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Trades: 0
Doh! - I'm a clutz!!

You're right about the handler! You need to change the $id variable from $_GET to $_POST.

Ian
__________________
Found this useful? - HIT MY TALKUPATION!


Please login or register to view this content. Registration is FREE
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 10-30-2005, 05:25 PM
Novice Talker

Posts: 9
Trades: 0
So close!!! I think I figered out the problem. The hidden feild isn't picking up the id number. Like
PHP Code:
<input type="hidden" name="id" value="' . $row[3] . '" /> 
is just showing a blank value in the source code.
iisthesloth is offline
Reply With Quote
View Public Profile
 
Old 10-30-2005, 05:33 PM
Novice Talker

Posts: 9
Trades: 0
I got it! Thanks so much for the help. The problem was also in the form page.
PHP Code:
$query "SELECT name, date, message FROM news WHERE id=$id"
forgot to select "id" which was teh reason why the source code was displaying a blank value.
iisthesloth is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Having An UPDATE Problem...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47626 seconds with 12 queries