Reply
cant update db
Old 04-09-2008, 11:00 AM cant update db
Average Talker

Posts: 23
PHP Code:
<a href="../index.php">Back to index</a><br>
<br>
<?php
include("connect.php");


$msg_id $_POST['msg_id'];
$sent_on $_POST['sent_on'];
$sent_by $_POST['sent_by'];
$subject $_POST['subject'];
$message $_POST['$message'];

 

$update "UPDATE `sysmsg` SET msg_id='$msg_id',sent_on='$sent_on',sent_by='$sent_by',subject='$subject',message='$message'";
$rsUpdate mysql_query($update) or die("Mysql Query Error For:<br />".$update."<br /><br />MySQL Said: ".mysql_error());
if (
mysql_affected_rows($rsUpdate) >= 1)
{
   echo 
"Update successful.";
}else{
   echo 
"No rows were updated";
}
mysql_close();
?>
io get this error

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/runningp/public_html/members/include/updatedsysmsg.php on line 17
No rows were updated
runnerjp is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 04-09-2008, 03:00 PM Re: cant update db
rogem002's Avatar
Webmaster Talker

Posts: 611
Name: Mike
Location: United Kingdom
Try:

PHP Code:
<a href="../index.php">Back to index</a><br>
<br>
<?php
include("connect.php");


$msg_id $_POST['msg_id'];
$sent_on $_POST['sent_on'];
$sent_by $_POST['sent_by'];
$subject $_POST['subject'];
$message $_POST['$message'];

 

$update "UPDATE `sysmsg` SET msg_id='$msg_id',sent_on='$sent_on',sent_by='$sent_by',subject='$subject',message='$message'";
$rsUpdate mysql_query($update) or die("Mysql Query Error For:<br />".$update."<br /><br />MySQL Said: ".mysql_error());
if (
mysql_affected_rows() >= 1)
{
   echo 
"Update successful.";
}else{
   echo 
"No rows were updated";
}
mysql_close();
?>
Judging from http://uk2.php.net/manual/en/functio...ected-rows.php the bit you put "$rsUpdate" into should only contain "INSERT, UPDATE, REPLACE or DELETE"
__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 

Last edited by rogem002 : 04-09-2008 at 03:02 PM.
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-09-2008, 03:56 PM Re: cant update db
Average Talker

Posts: 23
ok i have got it to update 2 field subject and sent_by ,,, i have 2 more problems (cheers rogem)

the 1st is that for some reason it does not update message :S and the second im not sure how to make it so it adds the date to whcih the db was chnaged ,,,, any ideas??

ill post both parts to aid with help with the message part because i dont seem to know why it does not wrok :S
PHP Code:
<?php
session_start
(); 
    require_once 
'../settings.php';
        
checkLogin ('1');

$qProfile "SELECT * FROM sysmsg ORDER BY msg_id DESC";
$rsProfile mysql_query($qProfile);
$row mysql_fetch_array($rsProfile);
extract($row);
$msg_id = ($msg_id);
$sent_on = ($sent_on);
$sent_by = ($sent_by);
$subject = ($subject);
$message = ($message);

mysql_close();?>

<p>Subject: <b><?php echo $subject?></b></p><p><i>Posted by:<?php echo $sent_by?> on <?php echo $sent_on?></i></p>
<p><?php echo $message?><br><br></p>

<? if($id == 1){ echo "<a href=\"http://www.runningprofiles.com/members/index.php?page=admin\">Admin Index</a>\n";}?>
PHP Code:
<a href="../index.php">Back to index</a><br>
<br>
<?php
include("connect.php");


$msg_id $_POST['msg_id'];
$sent_on $_POST['sent_on'];
$sent_by $_POST['sent_by'];
$subject $_POST['subject'];
$message $_POST['$message'];

 

$update "UPDATE `sysmsg` SET msg_id='$msg_id',sent_on='$sent_on',sent_by='$sent_by',subject='$subject',message='$message'";
$rsUpdate mysql_query($update) or die("Mysql Query Error For:<br />".$update."<br /><br />MySQL Said: ".mysql_error());
if (
mysql_affected_rows() >= 1)
{
   echo 
"Update successful.";
}else{
   echo 
"No rows were updated";
}
mysql_close();
?>
runnerjp is offline
Reply With Quote
View Public Profile
 
Old 04-09-2008, 06:55 PM Re: cant update db
Junior Talker

Posts: 4
Your SQL shound't contain a WHERE clause, telling which row to update? Without that, it will update all rows (maybe that's what you want).

If you want to put the date the row was last updated, you could add a column of type datetime, and every time you update a row you set that column to NOW() (UPDATE table_name SET blah=blah,updated_at=NOW() WHERE id=some_id)

Last edited by doug_matt : 04-09-2008 at 06:56 PM.
doug_matt is offline
Reply With Quote
View Public Profile
 
Old 04-09-2008, 07:15 PM Re: cant update db
Average Talker

Posts: 23
yes i do want all of it to be updated so thats fine but for some reason message does not update and i can not understand why ?
runnerjp is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 12:28 AM Re: cant update db
Ultra Talker

Posts: 308
mysql_affected_rows function takes database connection resource as its argument. Earlier you were passing it query result resource and now you aren't passing it any argument, thats the reason why it doesn't show update successful message. As far as second question is concerned, add a timestamp field to the table you're updating, mysql will update it every time you update a row.
__________________
tiny url
dman_2007 is offline
Reply With Quote
View Public Profile Visit dman_2007's homepage!
 
Old 04-10-2008, 06:27 AM Re: cant update db
Average Talker

Posts: 23
hey dman... i have found that the rest of the form upodates tho its just the message 1 that is not surly strange? lol


i have changed few errors ect but the message is still not updating the wierd thing is, is that when i got an error i got told that the message area was blank :S like so UPDATE `sysmsg` SET sent_by`='Admin', `subject`='321', `message`='', `sent_date`='1207822877' WHERE `msg_id`=''

it updates everything but the message

also the date isi got Date: Thu 04 2008 but this could be any thu in the month is there away so its shows 10-04-2008

PHP Code:
<?php
session_start
(); 
    require_once 
'../settings.php';
        
checkLogin ('1');

$qProfile "SELECT * FROM sysmsg ORDER BY msg_id DESC";
$rsProfile mysql_query($qProfile);

while(
$row mysql_fetch_array($rsProfile)){
    
$msg_id $row['msg_id'];
    
$sent_on $row['sent_on'];
    
$sent_by $row['sent_by'];
    
$subject $row['subject'];
    
$message $row['message'];
    
$datetime $row['sent_date'];
    
    echo(
"<p>Subject: <b>".$subject."</b></p><p><i>Posted by:".$sent_by." on ".$sent_on."</i> - Date: ".date("D m Y",$datetime)."</p>
    <p>"
.$message."<br><br></p>");
}
mysql_close();

if(
$id == 1){
    echo 
"<a href=\"http://www.runningprofiles.com/members/index.php?page=admin\">Admin Index</a>\n";
}

?>
PHP Code:
<a href="../index.php">Back to index</a><br>
<br>
<?php
include("connect.php");

// $msg_id should not change - do not let the user change this, use the message id to find the message you are wanting to edit.
$msg_id mysql_escape_string($_POST['msg_id']);
$sent_on mysql_escape_string($_POST['sent_on']);
$sent_by mysql_escape_string($_POST['sent_by']);
$subject mysql_escape_string($_POST['subject']);
$message mysql_escape_string($_POST['$message']);

// This gives the unix timestamp of the current time down to the second.
$timedate time();

// make sure $msg_id POSTED from the previous page is an id that you want to change. ALSO make sure `sent_date` field exists.
$update "UPDATE `sysmsg` 
    SET 
    `sent_on`='$sent_on',
    `sent_by`='$sent_by',
    `subject`='$subject',
    `message`='$message',
    `sent_date`='$timedate'
    
    WHERE `msg_id`='$msg_id'
"
;
$rsUpdate mysql_query($update) or die("Mysql Query Error For:<br />".$update."<br /><br />MySQL Said: ".mysql_error());
if (
mysql_affected_rows() >= 1)
{
   echo 
"Update successful.";
}else{
   echo 
"No rows were updated";
}
mysql_close();
?>
this is not the main issue tho as the message is strange can any 1 help ??
runnerjp is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to cant update db
 

Thread Tools

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

vB 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.15600 seconds with 12 queries