Jump to content

[SOLVED] cant seem to update database


runnerjp

Recommended Posts

hey guys i got this data

 

<link rel="stylesheet" type="text/css" href="http://www..com/css/login.css">
<?php
session_start(); 
require_once '../settings.php';
	checkLogin ('1');

$qProfile = "SELECT * FROM sysmsg ";
$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();?>
<title>Update Image</title>
<? var_dump($month);
?>
<form id="FormName" action="include/updatedsysmsg.php" method="post" name="FormName">
<table width="523" border="0" align="center" cellpadding="0" cellspacing="2">
<tr><td width="150"><div align="right">
<label for="dob">Gender</label>
</div>
</td>
<td colspan="2"><select class="input" id="sent_by" name="sent_by"> 
<option value="Admin" >Admin</option>
<option value="Support" >Support</option>
</select></td>
</tr>
<tr><td width="150"><div align="right">
<label for="about_me">Subject</label>
</div>
</td>
<td colspan="2"><input class="input" id="events" name="subject" type="text" size="25" value="<?php echo $subject ?>" maxlength="255"></td>
</tr>
<tr><td width="150"><div align="right">
<label for="events">Message</label>
</div>
</td>
<td colspan="2"><textarea class="input" id="message" name="message" rows="4" cols="40"><?php echo $message ?></textarea></td>
</tr>
<tr>
<td width="150"></td>
<td width="112"><input name="submitButtonName" type="submit" class="submit-btn" value=""></td>
<td width="253"> </td>
</tr>
</table>
</form>

 

user clicks submit and it goes to the page where the form is processed and added to db...or it should do but doesnt ??

 

<a href="../index.php">Back to index</a><br>
<br>
<?php


include("connect.php");

$id = $_POST['id'];
$about_me = $_POST['about_me'];
$events = $_POST['events'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$gender = $_POST['gender'];
$year = $_POST['birthyear'];
$month = $_POST['birthmonth'];
$day = $_POST['birthday'];
$dob = $day.'-'.$month.'-'.$year;


$update = "UPDATE users SET dob='$dob', about_me = '$about_me', events = '$events', first_name = '$first_name', gender = '$gender', last_name = '$last_name' WHERE id='$id' ";
$rsUpdate = mysql_query($update);
if ($rsUpdate)
{
echo "Update successful.";
} mysql_close();
?>

 

wierd thing is i get the echo o update successful :S

 

have i made a silly mistake as this should be easy lol

 

 

 

 

 

 

Link to comment
Share on other sites

woops i pasted wrong form at the bottom its ment to be

<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);
if ($rsUpdate)
{
echo "Update successful.";
} mysql_close();
?>

 

 

and yes im updating the current record

 

basicly all it is is a news feed that the admins or support can update

Link to comment
Share on other sites

try this:

 

$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();
?>

Link to comment
Share on other sites

also are you aware of syntax error?

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

 

should be:

 

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

Link to comment
Share on other sites

hey im not awear of syntax error.... i corrected it lol so easy to miss out the "("

 

 

i added the code you kindly wrote for me but i got 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

Link to comment
Share on other sites

sorry my mistake, ive never used this function before (stupid eh?).

 

Please use php.net - you can figure it out if you really wanted: http://php.net/mysql_affected_rows

---

 

the argument it asks for is "MySQL Link Identifier" (ie, the mysql connection variable).

 

it also does not need one, as without it, it will assume the last mysql connection made (or current open connection).

------

 

if you cant figure out what i mean, i mean try :P, then ill post the answer, or someone else will anyway lol

 

 

hope this helps,

Link to comment
Share on other sites

i had read through and still not quite sure i tried chnaging it to 

<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 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($Update) >= 1)
{
   echo "Update successful.";
}else{
   echo "No rows were updated";
}
mysql_close();
?>

i could really do with telling me what to do so i can discover where i have gone wrong lol

Link to comment
Share on other sites

ok i have got it to update 2 field subject and sent_by ,,, i have 2 more problems

 

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
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";}?>




<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();
?>

 

 

 

Link to comment
Share on other sites

im very sorry - i went to sleep :(. the original answer was to change

if (mysql_affected_rows($rsUpdate) >= 1)

to

if (mysql_affected_rows() >= 1)

again - sorry

-------

 

for your next question

for some reason it does not update message

How do you mean? no changes at all? is the query working? try this:

 

<?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";
}

?>

This assumes you have already made changes to the DB according to the nest piece of code (for DATE functionality). notice the date() function, more info is found here: www.php.net/date


For you next question

im not sure how to make it so it adds the date to whcih the db was chnaged

This can be controversal - i use the time() function for a timestamp (date in seconds since the unix epoch).

Some other people prefer to use the in-built mysql DATE and TIMESTAMP functions, so they can perform on-the-fly date calculations in queries - though personally ive never had problems with timestamps.

 

So, as i am unsure how exactly to work the MySQL DATE Functions etc, im going to show you my way of dealign with dates in mysql -

 

<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();
?>

Link to comment
Share on other sites

hey thanks for help

 

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

 

 

this is not the main issue tho as the message is strange can any 1 help ??

Link to comment
Share on other sites

change

 

$message = mysql_escape_string($_POST['$message']);

 

to

 

$message = mysql_escape_string($_POST['message']);

----

 

also the msg_id is missing, make sure you have put a hidden input field with the name msg_id in the form.

eg: <input type="hidden" name="msg_id" value="$msg_id">

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.