Jump to content


Photo

Updating an existing record


  • Please log in to reply
9 replies to this topic

#1 benjamin_boothe

benjamin_boothe
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 23 August 2006 - 09:31 PM

I'm trying to edit records from the web. I can display the list of records, but I can't display the lists of records to edit.

I am trying to display the records with the use of an id.

Basically, I trying to SELECT a record WHERE id=$id.

Here is the code:

<!--set up the table -->
<TABLE BORDER="1" CELLPADDING="5">



<TR>
  <TH>Title</TH>
  <TH>First name</TH>
  <TH>Last name</TH>
  <TH>Date of birth</TH>
  <TH>UK residency</TH>
  <TH>Marital status</TH>
  <TH>Disability</TH>
  <TH>Employment status</TH>
  <TH>Address line 1</TH>
  <TH>Area</TH>
  <TH>Town</TH>
  <TH>County</TH>
  <TH>Post code</TH>
  <TH>Telephone work</TH>
  <TH>Telephone home</TH>
  <TH>Fax number</TH>
  <TH>Email</TH>
 </TR>
<?

$id = isSet($_POST['id']) ? $_POST['id'] : '';

include 'includes/db_conn.txt';



// build and execute the query
    $select = "SELECT title, first_name, surname, date_of_birth, uk_residency,
     marital_status, disability, employment_status, address_line_1, area, town,
     county, post_code, telephone_work, telephone_home, fax_number, email FROM policy_holder
     WHERE id=$id";
    $result= mysqli_query($link, $select);

while ($row = mysqli_fetch_array($result)) {
  $t = $row['title'];
  $fn = $row['first_name'];
  $sn = $row['surname'];
  $dob = $row['date_of_birth'];
  $uk = $row['uk_residency'];
  $ms = $row['marital_status'];
  $d = $row['disability'];
  $es = $row['employment_status'];
  $ad1 = $row['address_line_1'];
  $a = $row['area'];
  $tn = $row['town'];
  $c = $row['county'];
  $pc = $row['post_code'];
  $tw = $row['telephone_work'];
  $th = $row['telephone_home'];
  $fax = $row['fax_number'];
  $em = $row['email'];
  $id = $row['id'];

  echo <<<END
<TR>
  <TD>$t</TD>
  <TD>$fn</TD>
  <TD>$sn</TD>
  <TD>$dob</TD>
  <TD>$uk</TD>
  <TD>$ms</TD>
  <TD>$d</TD>
  <TD>$es</TD>
  <TD>$ad1</TD>
  <TD>$a</TD>
  <TD>$tn</TD>
  <TD>$c</TD>
  <TD>$pc</TD>
  <TD>$tw</TD>
  <TD>$th</TD>
  <TD>$fax</TD>
  <TD>$em</TD>
  <TD><a href="mysqli_list_update.php?id=$id">Edit details</a></TD>
</TR>
END;
}
?>
<!-- Close table -->
</TABLE>

I get this message when I trying to run it:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in E:\Program Files\Apache Group\Apache2\htdocs\policylist.php on line 40


Help me please!!!

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 23 August 2006 - 09:44 PM

change this line:

$result= mysqli_query($link, $select);

to:

$result= mysqli_query($link, $select) or die(mysqli_error());

And let us know what the output is then.

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 August 2006 - 09:45 PM

It appears your query is failing and that $result holds the value of FALSE. Try some error handling to try and track down the problem.

$result= mysqli_query($link, $select) or die(mysqli_error());


#4 benjamin_boothe

benjamin_boothe
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 23 August 2006 - 09:49 PM

This is the error that I get now:

Warning: mysqli_error() expects exactly 1 parameter, 0 given in E:\Program Files\Apache Group\Apache2\htdocs\policylist.php on line 38


What does this mean I have to do?

#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 23 August 2006 - 09:50 PM

supply the connection name...looks like "$link"

so it should be:

$result= mysqli_query($link, $select) or die(mysqli_error($link));


#6 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 24 August 2006 - 01:29 AM

I think you guys are spelling mysql wrong...I am not sure if 'mysqli' is just a different way or not...but if it isn't the code should be:

$result= mysql_query($link, $select) or die(mysql_error($link));


#7 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 24 August 2006 - 01:41 AM

http://www.php.net/mysqli

When in doubt....look in the manual

#8 benjamin_boothe

benjamin_boothe
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 24 August 2006 - 09:47 AM

This is the error I get now with adding - $result= mysql_query($link, $select) or die(mysql_error($link));

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4


I don't know where it is referring to.  Can somebody look at my code to see where the problem is.

Look above in the post to see my code for the list page.

#9 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 24 August 2006 - 01:29 PM

echo out your query so you can see what it is that is causing the problem.

#10 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 24 August 2006 - 01:35 PM

Just a guess, but Im thinking $id might not be getting populated. As hitman said, echo() your query and lets take a look.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users