want to update results on record

  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

http://www.buildingdoctors.co.uk/formview.php this is the results screen. you can input a number and see the corresponding record. what i want to do now is be able to update the records. there is a notes section whereby all updates and extra notes can be placed. i need a code or if statement (or a combination) in order for the update to work. i got 3 submit buttons with this code:
PHP Code: [ Select ]
$OFFSET = $_POST['offset'] ? $_POST['offset'] : 1;
 
if($_POST['button'] == 'next'){
 
$OFFSET++;
 
}else{
 
$OFFSET--;
 
}
 
if($_POST['button'] == 'go'){
 
$OFFSET = $_POST['offset'];
 
}
  1. $OFFSET = $_POST['offset'] ? $_POST['offset'] : 1;
  2.  
  3. if($_POST['button'] == 'next'){
  4.  
  5. $OFFSET++;
  6.  
  7. }else{
  8.  
  9. $OFFSET--;
  10.  
  11. }
  12.  
  13. if($_POST['button'] == 'go'){
  14.  
  15. $OFFSET = $_POST['offset'];
  16.  
  17. }


i think i need a 4th button called UPDATE. i want to update the record. any ideas on how to do this?
  • Cafu
  • Student
  • Student
  • Cafu
  • Posts: 97

Post 3+ Months Ago

It's pretty much the same as adding a record only you use an UPDATE statement rather than an INSERT statement. Usually you want to have a "hidden" input on your form containing the id of the row to be updated.

Perhaps you can be more specific... are you having trouble with the SQL syntax?
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

yes i am having trouble with the syntax of the code
  • Cafu
  • Student
  • Student
  • Cafu
  • Posts: 97

Post 3+ Months Ago

try this:

http://www.w3schools.com/sql/sql_update.asp
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

you misunderstand me. i want to be able to put in a script that will allow myself or my colleague to update the record regardless of whose name it is. what is certain is that there are fields. what is not certain is what the fields will have in them
Code: [ Select ]
UPDATE Person SET FirstName = 'Nina'
WHERE LastName = 'Rasmussen'
  1. UPDATE Person SET FirstName = 'Nina'
  2. WHERE LastName = 'Rasmussen'
doesn't help me but
Code: [ Select ]
UPDATE Person SET FirstName = $name WHERE phone= $phone
is more helpful. i am wondering what i need to do inorder to get this set up and then how to link this to a button called UPDATE
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i have this code for my update but something is missing. its not updating at all. no error message comes up at all even tho the database hanst bee updated. something is missing but i dont know what it is.

PHP Code: [ Select ]
if($_POST['button'] == 'update'){
 
$updatenote = "update gstrialforma set otherpreferences='$otherpreferences' where name='$name' and email='$email'";
 
$result = mysql_query($updatenote) or die ("Couldn't update at all.");
 
}
  1. if($_POST['button'] == 'update'){
  2.  
  3. $updatenote = "update gstrialforma set otherpreferences='$otherpreferences' where name='$name' and email='$email'";
  4.  
  5. $result = mysql_query($updatenote) or die ("Couldn't update at all.");
  6.  
  7. }
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i changed the code to this:
PHP Code: [ Select ]
if($_POST['button'] == 'update'){
 
$updatenote = ("update gstrialforma set otherpreferences='$otherpreferences' where id = $_POST['id']");
 
$updateresult = mysql_query($updatenote) or die ("Couldn't update at all.");
 
}
  1. if($_POST['button'] == 'update'){
  2.  
  3. $updatenote = ("update gstrialforma set otherpreferences='$otherpreferences' where id = $_POST['id']");
  4.  
  5. $updateresult = mysql_query($updatenote) or die ("Couldn't update at all.");
  6.  
  7. }

i have this hidden code in the form aswell:
PHP Code: [ Select ]
<input name="id" type="hidden" value="<?php $record['id']?>">

but i get this error:
Code: [ Select ]
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /cgi/patch/to/formview.php on line 26

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 111 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.