runnerjp Posted April 8, 2008 Share Posted April 8, 2008 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 https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/ Share on other sites More sharing options...
Barand Posted April 8, 2008 Share Posted April 8, 2008 user clicks submit and it goes to the page where the form is processed and added to db...or it should do but doesnt ?? Are you expecting to add new record? Your code will only update an existing record. Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-512479 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 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 https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-512812 Share on other sites More sharing options...
uniflare Posted April 9, 2008 Share Posted April 9, 2008 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 https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-512814 Share on other sites More sharing options...
uniflare Posted April 9, 2008 Share Posted April 9, 2008 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 https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-512815 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 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 https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-512828 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 oh i should say this is line 17 if (mysql_affected_rows($rsUpdate) >= 1) Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-512829 Share on other sites More sharing options...
uniflare Posted April 9, 2008 Share Posted April 9, 2008 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 , then ill post the answer, or someone else will anyway lol hope this helps, Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-512879 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 ok do i need to have a WHERE in it? Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-512885 Share on other sites More sharing options...
uniflare Posted April 9, 2008 Share Posted April 9, 2008 no read the error. its saying the function mysql_affected_rows($rsUpdate) is wrong, the argument ($rsUpdate) is invalid for that function. it needs to be something else Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-512893 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 humm but surly im updating my field lol Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-512916 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 i have had a play around and im stumped can any 1 aid me lol Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-512958 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 bmp Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-513031 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 ?? Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-513059 Share on other sites More sharing options...
AndyB Posted April 9, 2008 Share Posted April 9, 2008 http://ca.php.net/function.mysql-affected-rows - does that help? Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-513082 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 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 https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-513155 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 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 https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-513263 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 bmp Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-513346 Share on other sites More sharing options...
runnerjp Posted April 9, 2008 Author Share Posted April 9, 2008 ?? Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-513428 Share on other sites More sharing options...
uniflare Posted April 9, 2008 Share Posted April 9, 2008 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 https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-513465 Share on other sites More sharing options...
runnerjp Posted April 10, 2008 Author Share Posted April 10, 2008 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 https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-513716 Share on other sites More sharing options...
runnerjp Posted April 10, 2008 Author Share Posted April 10, 2008 .. Link to comment https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-513767 Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 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 https://forums.phpfreaks.com/topic/100220-solved-cant-seem-to-update-database/#findComment-513776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.