Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus bios bsod crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop mac malware memory monitor motherboard network operating system printer problem ram registry router security slow software sound svchost.exe trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
trying to update single record

Reply  
Thread Tools
ckdoublenecks's Avatar
Member with 109 posts.
 
Join Date: May 2009
Location: florida
Experience: Intermediate
02-Sep-2010, 06:15 PM #1
trying to update single record
I have this program where I select specific records to update (apt). When I select, all matching records are displayed. So far, so good. Trouble is when I update any of the matching records, all of them end up the same. How can I update just the one ?

PHP Code:
<?php
mysql_connect
(localhost,root,"");
mysql_select_db(test) or die( "Unable to select database");
if(!empty(
$_POST["submit"]))
{
 
$apt $_POST['apt'];
 
$query="SELECT * FROM testtable Where apt='$apt'";
 
$result=mysql_query($query);
 if(
mysql_num_rows($result))
 {
  echo 
"<form action='#' method='post'><b>Maintenance Update Test :<br /><br />
         <table border='1'>
          <tr>
          <th>apt</th>
          <th>name</th>
          <th>date received</th>
          <th>symptom</th>
          <th>action</th>
          <th>date completed</th>
          </tr>"
;
  while(
$row mysql_fetch_assoc($result))
  {
   echo 
"<tr>
          <td><input type='text' name='apt' value='" 
$row['apt'] . "'></td>
          <td><input type='text' name='name' value='" 
$row['name'] . "'></td>
          <td><input type='text' name='datereceived' value='" 
$row['datereceived'] . "'></td>
          <td><input type='text' name='symptom' value='" 
$row['symptom'] . "'></td>
          <td><input type='text' name='action' value='" 
$row['action'] . "'></td>
          <td><input type='text' name='datecomplete' value='" 
$row['datecomplete'] . "'></td>
         </tr>"
;
   }
echo 
"</table>
<input type='submit' name='update' value='Update Record' />
echo</form>"
;
}  
 else{echo 
"No listing for appartment $apt.<br />Please select another.<br />";}
}
if(!empty(
$_POST["update"]))
{
$sql "UPDATE maintdata SET
 apt = '" 
mysql_real_escape_string($_POST['apt']) . "',
 name = '" 
mysql_real_escape_string($_POST['name']) . "',
 datereceived = '" 
mysql_real_escape_string($_POST['datereceived']) . "',
 symptom = '" 
mysql_real_escape_string($_POST['symptom']) . "',
 action = '" 
mysql_real_escape_string($_POST['action']) . "',
 datecomplete = '" 
mysql_real_escape_string($_POST['datecomplete']) . "'
WHERE apt='"
.$_POST["apt"]."'";
 
mysql_query($sql) or die("Update query failed.");
 echo 
"Record for appartment ".$_POST["apt"]." has been updated";
 }
?>
<form method="post" action="#">
 <br />
 <input type="text" name="apt"/> <p>
<input type="submit" name="submit" value="select apartment"/>
</form>
maneetpuri's Avatar
Member with 124 posts.
 
Join Date: Oct 2008
03-Sep-2010, 07:37 AM #2
Hi,

I assume that you have a unique ID for each record, pass it as the parameter to the edit script and define it in the where clause of the Update SQL and it will just update that record.

Hope this helps.

Cheers,

~Maneet
ckdoublenecks's Avatar
Member with 109 posts.
 
Join Date: May 2009
Location: florida
Experience: Intermediate
03-Sep-2010, 04:39 PM #3
yeah I figured as much but I haven't quite got it yet. I changed it to the below and got this error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' on line 24. I don't see it? Can someone give me some guidance?

PHP Code:
<?php 
mysql_connect
(localhost,root,""); 
mysql_select_db(test) or die( "Unable to select database"); 
if(!empty(
$_POST["submit"])) 

 
$apt $_POST['apt']; 
 
$query="SELECT * FROM testtable Where apt='$apt'"
 
$result=mysql_query($query); 
 if(
mysql_num_rows($result)) 
 { 
  echo 
"<form action='#' method='post'><b>Maintenance Update Test :<br /><br /> 
         <table border='1'> 
          <tr> 
          <th>apt</th> 
          <th>name</th> 
          <th>date received</th> 
          <th>symptom</th> 
          <th>action</th> 
          <th>date completed</th> 
          </tr>"

  while(
$row mysql_fetch_array($result)) 
  { 
   echo 
"<tr>
<td align="
center">".$id[]=$row['id']  $row['id']; ?></td>
<td><input type='text' name='apt' value='" . $row['apt'] . "'></td> 
          <td><input type='text' name='name' value='" . $row['name'] . "'></td> 
          <td><input type='text' name='datereceived' value='" . $row['datereceived'] . "'></td> 
          <td><input type='text' name='symptom' value='" . $row['symptom'] . "'></td> 
          <td><input type='text' name='action' value='" . $row['action'] . "'></td> 
          <td><input type='text' name='datecomplete' value='" . $row['datecomplete'] . "'></td> 
         </tr>"; 
   } 
echo "</table> 
<input type='submit' name='update' value='Update Record' /> 
echo</form>"; 
}   
 else{echo "No listing for appartment $apt.<br />
Please select another.<br />";} 

if(!empty($_POST["update"])) 

for($i=0;$i<$count;$i++){
$sql1="UPDATE testtable SET apt='$apt[$i]', name='$name[$i]', 'datereceived='$'datereceived[$i]', 'symptom='$'symptom[$i]', 'action='$'action[$i]', 'datecomplete='$'datecomplete[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1) or die("Update query failed."); 
 echo "Record for appartment ".$_POST["apt"]."  has been updated"; 
 } 
?> 
<form method="post" action="#"><br /> 
 <input type="text" name="apt"/> <p> 
<input type="submit" name="submit" value="select apartment"/> 
</form>

Last edited by ckdoublenecks; 04-Sep-2010 at 04:06 PM.. Reason: completion
maneetpuri's Avatar
Member with 124 posts.
 
Join Date: Oct 2008
07-Sep-2010, 03:47 AM #4
Hi,

This parse error is because you have used “ in the echo replace them with ‘ and also I noticed the concatenation operator was missing too in the same line.

Cheers,
ckdoublenecks's Avatar
Member with 109 posts.
 
Join Date: May 2009
Location: florida
Experience: Intermediate
07-Sep-2010, 09:46 PM #5
I'm trying to learn this but having trouble understanding everyone's suggestions. Below is my latest attempt but I get an error at the statement that's commented in. I hope someone can offer guidance ?

PHP Code:
<?php 
mysql_connect
(localhost,root,""); 
mysql_select_db(test) or die( "Unable to select database"); 
if(!empty(
$_POST["submit"])) 

$apt $_POST['apt']; 
$query="SELECT * FROM testtable Where apt='$apt'"
$result=mysql_query($query); 
if(
mysql_num_rows($result)) 

echo 
"<form action='#' method='post'><b>Maintenance Update Test :<br /><br /> 
<table border='1'> 
<tr> 
<th>apt</th> 
<th>name</th> 
<th>date received</th> 
<th>symptom</th> 
<th>action</th> 
<th>date completed</th> 
</tr>"

while(
$row mysql_fetch_array($result)) 

echo 
"<tr>
// *******************************************************
<td align='center'>"
.$id[]=$row['id'$row['id'];</td>
// ********************************************************
<td><input type='text' name='apt' value='" . $row['apt'] . "'></td
<
td><input type='text' name='name' value='" . $row['name'] . "'></td
<
td><input type='text' name='datereceived' value='" . $row['datereceived'] . "'></td
<
td><input type='text' name='symptom' value='" . $row['symptom'] . "'></td
<
td><input type='text' name='action' value='" . $row['action'] . "'></td
<
td><input type='text' name='datecomplete' value='" . $row['datecomplete'] . "'></td
</
tr>"; 

echo "
</table
<
input type='submit' name='update' value='Update Record' /> 
echo</
form>"; 

else{echo "
No listing for apartment $apt.<br />
Please select another.<br />";} 

if(!empty($_POST["
update"])) 

for($i=0;$i<$count;$i++){
$sql1="
UPDATE testtable SET apt='$apt[$i]'name='$name[$i]''datereceived='$'datereceived[$i]'
'symptom='$'symptom[$i]''action='$'action[$i]''datecomplete='$'datecomplete[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1) or die("
Update query failed."); 
echo "
Record for apartment ".$_POST["apt"]." has been updated"; 

?> 
<form method="
post" action="#"><br /> 
<input type="text" name="apt"/> <p
<
input type="submit" name="submit" value="select apartment"/> 
</
form>
ckdoublenecks's Avatar
Member with 109 posts.
 
Join Date: May 2009
Location: florida
Experience: Intermediate
08-Sep-2010, 08:45 PM #6
my latest attempt - I select the 'apt' but entering change for either of the 2 selected 'apt' records in the database doesn't update record. I have been trying, along with several others from several forums, to solve this problem but for every good suggestion I get the bad. Is anyone good enough at PHP to see the problem?

PHP Code:
<?php 
mysql_connect
(localhost,root,"");
mysql_select_db(test) or die( "Unable to select database");
if(!empty(
$_POST["submit"]))
{
 
$apt $_POST['apt'];
 
$query="SELECT * FROM testtable Where apt='$apt'";
 
$result=mysql_query($query);
 if(
mysql_num_rows($result))
 {
  echo 
"<form action='#' method='post'><b>Maintenance Update Test :<br /><br />
         <table border='1'>
          <tr>
          <th>apt</th>
          <th>name</th>
          <th>date received</th>
          <th>symptom</th>
          <th>action</th>
          <th>date completed</th>
          </tr>"
;
 while(
$row mysql_fetch_assoc($result))
  {
   echo 
"<tr>
          <td><input type='text' name='apt' value='" 
$row['apt'] . "'></td>
          <input type='hidden' name='id' value='"
.$row['id']."'>
          <td><input type='text' name='name' value='" 
$row['name'] . "'></td>
          <td><input type='text' name='datereceived' value='" 
.$row['datereceived'] . "'></td>
          <td><input type='text' name='symptom' value='" 
$row['symptom'] . "'></td>
          <td><input type='text' name='action' value='" 
$row['action'] . "'></td>
          <td><input type='text' name='datecomplete' value='" 
.$row['datecomplete'] . "'></td>
          <td><input type='submit' name='update' value='Update Record'></form></td>
         </tr>"
;
   }
echo 
"</table>";
}else{echo 
"No listing for apartment $apt.<br />Please select another.<br />";}
}
if(!empty(
$_POST["update"]))
{
$sql "UPDATE maintdata SET
apt = '" 
.mysql_real_escape_string($_POST['apt']) . "',
name = '" 
.mysql_real_escape_string($_POST['name']) . "',
datereceived = '" 
.mysql_real_escape_string($_POST['datereceived']) . "',
symptom = '" 
.mysql_real_escape_string($_POST['symptom']) ."',
action = '" 
.mysql_real_escape_string($_POST['action']) . "',
datecomplete = '" 
.mysql_real_escape_string($_POST['datecomplete']) . "'
WHERE id='"
.$_POST["id"]."'";
 
mysql_query($sql);
 echo 
"Record for apartment ".$_POST["apt"]." has been updated";
 }
?>
<form method="post" action="#"><br />
 <input type="text" name="apt"/> <p>
<input type="submit" name="submit" value="select apartment"/>
</form>
__________________
double your music - double your fun
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools


Similar Threads
Title Thread Starter Forum Replies Last Post
Google Redirecting, Win32\Alureon.H, unable to update LibbyLou Virus & Other Malware Removal 14 15-Jul-2010 05:19 PM
Solved: Access 2007 - Print single record selected on continuous form MuddyTurtle Business Applications 2 30-Jun-2010 04:43 PM
Trying to Fix PC, Stays on for 5 seconds. asweeba Hardware 2 30-Nov-2009 03:30 PM
Sound is totally gone after trying to use analog recorder dotbowels Hardware 4 23-Aug-2006 09:01 AM
Trying to update, update.exe generates errors. surferion Virus & Other Malware Removal 8 06-Nov-2004 12:26 AM


Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:29 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.