Jump to content

Archived

This topic is now archived and is closed to further replies.

benjamin_boothe

Updating an existing record

Recommended Posts

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:

[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>
[/code]

I get this message when I trying to run it:

[quote]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
[/quote]

Help me please!!!

Share this post


Link to post
Share on other sites
change this line:

[code]$result= mysqli_query($link, $select);[/code]

to:

[code]$result= mysqli_query($link, $select) or die(mysqli_error());[/code]

And let us know what the output is then.

Share this post


Link to post
Share on other sites
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.

[code=php:0]
$result= mysqli_query($link, $select) or die(mysqli_error());
[/code]

Share this post


Link to post
Share on other sites
This is the error that I get now:

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

What does this mean I have to do?

Share this post


Link to post
Share on other sites
supply the connection name...looks like "$link"

so it should be:

[code]$result= mysqli_query($link, $select) or die(mysqli_error($link));[/code]

Share this post


Link to post
Share on other sites
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:

[code]$result= mysql_query($link, $select) or die(mysql_error($link));[/code]

Share this post


Link to post
Share on other sites
This is the error I get now with adding - $result= mysql_query($link, $select) or die(mysql_error($link));

[quote]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[/quote]

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.

Share this post


Link to post
Share on other sites
Just a guess, but Im thinking $id might not be getting populated. As hitman said, echo() your query and lets take a look.

Share this post


Link to post
Share on other sites

×

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.