Jump to content

benjamin_boothe

Members
  • Posts

    36
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

benjamin_boothe's Achievements

Member

Member (2/5)

0

Reputation

  1. 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.
  2. 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?
  3. 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!!!
  4. Hello Wildteen! Now it is just showing the headers and no fields to update. There is already data in the table for this form.
  5. Sorry, What I am changing on those lines?
  6. [quote] Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in E:\Program Files\Apache Group\Apache2\htdocs\edit_policy_holder.php on line 62 [/quote] This is the error msg I get when trying to create a web form that edits records in a database. This is my code: [code] <HTML> <HEAD> <STYLE> BODY {font-family:arial;} .error {font-weight:bold; color:#FF0000;} </STYLE> </HEAD> <BODY> <h2>Edit Policy Holder Details:</h2> <? // connect to the database include 'includes/db_conn.txt'; // has form been submitted? if ($_POST){   foreach($_POST as $k => $v){     $v = trim($v) ;     $$k = $v;   }     // build UPDATE query   $update = "UPDATE policy_holder SET     title='$t', first_name='$fn', surname='$sn', date_of_birth='$dob', uk_residency='$uk',     marital_status='$ms', disability='$d', employment_status='$es', address_line_1='$ad1',     area='$a', town='$tn', county='$c', post_code='$pc', telephone_work='$tw',     telephone_home='$th', fax_number='$fax', email='$em'     WHERE Id=$id";       // execute query and check for success   if (!mysqli_query($link, $update)){     $msg = "Error updating data - " .mysqli_error($link);   }else {   $msg = "Record successfully updated:";       // write table row confirming data       $table_row = <<<EOR       <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>       </TR>       EOR;     } // if not posted, check that an Id has been passed via the URL   } else {     if (!IsSet($_GET['id'])) {       $msg = "No policy owner selected!";     } else {       $id = $_GET['id'];       // build and execute the query       $select = "SELECT title, first_name, surname, date_of_birth, uk_residency,       marital_status, disability, employment_status, address_1_line, area, town, county,       post_code, telephone_work, telephone_home, fax_number, email FROM policy_holder       WHERE Id=$id";       $result = mysqli_query($link, $select);             // check that the record exists       if (mysqli_num_rows($result)<1) {         $msg = "No policy holder with that ID found!";       } else {       // set vars for form code       $form_start = "<FORM METHOD=\"post\"ACTION= \"" . $_SERVER['PHP_SELF']. "\">";       $form_end = <<<EOF       <TR>           <TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Submit changes" /></TD>           <TD COLSPAN="2"><INPUT TYPE="reset" VALUE="Cancel" /></TD>       </TR>       </FORM>       EOF;       // assign the results to an array 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_1_line'];   $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'];     // write table row with form fields   $table_row = <<<EOR <TR>     <TD><INPUT TYPE="text" NAME="title" VALUE="$t" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="first_name" VALUE="$fn" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="suranme" VALUE="$sn" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="date_of_birth" VALUE="$dob" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="uk_residency" VALUE="$uk" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="marital_status" VALUE="$ms" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="disability" VALUE="$d" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="employment_status" VALUE="$es" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="address_1_line" VALUE="$ad1" SIZE="25"/></TD>     <TD><INPUT TYPE="text" NAME="area" VALUE="$a" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="town" VALUE="$tn" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="county" VALUE="$c" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="post_code" VALUE="$pc" SIZE="10"/></TD>     <TD><INPUT TYPE="text" NAME="telephone_work" VALUE="$tw" SIZE="11"/></TD>     <TD><INPUT TYPE="text" NAME="telephone_home" VALUE="$th" SIZE="11"/></TD>     <TD><INPUT TYPE="text" NAME="fax_number" VALUE="$fax" SIZE="11"/></TD>     <TD><INPUT TYPE="text" NAME="email" VALUE="$em" SIZE="20"/></TD> </TR>   EOR; } // end 'if record exists' if       }       // end 'if ID given in URL' if       }       // end 'if form posted' if     }         // close connection     mysqli_close($link);         // print error/success message     echo (IsSet($msg)) ? "<div class=\"error\">$msg</div>" :"";     ?>     <TABLE BORDER="1" CELLPADDING="5">     <!-- Show start-of-form code if form needed -->     <? echo (IsSet($form_start)) ? $form_start :""; ?>         INPUT TYPE="HIDDEN" NAME="id" VALUE="<? echo $id ?>" />     <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>     <!-- Show appropriate table row code (none set if there were errors) -->     <? echo (IsSet($table_row)) ? $table_row :""; ?>         <!-- Show end-of-form code if we are displaying the form -->     <? echo (IsSet($form_end)) ? $form_end :""; ?>     </TABLE>         <br/><a href="policylist.php">Back to policy holder list</a>     </BODY>     </HTML> [/code] Can anybody spot where I am going wrong?
  7. Because the globals are off I had to use this piece of code.  This was because at first, I was getting 'Notice: Undefined' messages.  So I had to declare all of my variables like this: [code] $t = isSet($_POST['title']) ? $_POST['title'] : ''; $fn = isSet($_POST['first_name']) ? $_POST['first_name'] : ''; $sn = isSet($_POST['surname']) ? $_POST['surname'] : ''; $dob = isSet($_POST['date_of_birth']) ? $_POST['date_of_birth'] : ''; $uk = isSet($_POST['uk_residency']) ? $_POST['uk_residency'] : ''; $ms = isSet($_POST['marital_status']) ? $_POST['marital_status'] : ''; $d = isSet($_POST['disability']) ? $_POST['disability'] : ''; $es = isSet($_POST['employment_status']) ? $_POST['employment_status'] : ''; $ad1 = isSet($_POST['address_line_1']) ? $_POST['address_line_1'] : ''; $a = isSet($_POST['area']) ? $_POST['area'] : ''; $tn = isSet($_POST['town']) ? $_POST['town'] : ''; $c = isSet($_POST['county']) ? $_POST['county'] : ''; $pc = isSet($_POST['post_code']) ? $_POST['post_code'] : ''; $tw = isSet($_POST['telephone_work']) ? $_POST['telephone_work'] : ''; $th = isSet($_POST['telephone_home']) ? $_POST['telephone_home'] : ''; $fax = isSet($_POST['fax_number']) ? $_POST['fax_number'] : ''; $em = isSet($_POST['email']) ? $_POST['email'] : ''; [/code] Beforehand I was declaring the variable like this: For example, if wanted to declare the 'fax_number' form variable, I was doing this: [code]$fax = isSet($_POST['fax']) ? $_POST['fax'] : '';[/code] Which was why it was not reading the values that I was inputting, as I was not making the field names (form inputs) equal to the variables like this: [code]$fax = isSet($_POST['fax_number']) ? $_POST['fax_number'] : '';[/code] That was the issue all along!!
  8. Thanks a lot HeyRay2. I've been stressing like a muthafucka over dat shit!! It was staring at me right in the face.  Lack of sleep!!! Dis PHP shit has become an addiction man!!! I can't thank you enough bro'
  9. [code] if ($msg=="") {     $insert = "INSERT INTO policy_holder     ( id, 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)     VALUES ( NULL, '$t', '$fn', '$sn', '$dob', '$uk', '$ms', '$d', '$es', '$ad1', '$a',     '$tn', '$c', '$pc', '$tw', '$th', '$fax', '$em')"; [/code] That is the query I am running.  I echoed it to see what it is doing: [quote] INSERT INTO policy_holder ( id, 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) VALUES ( NULL, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '') [/quote] It's not returning the values in the db that I am putting into my form.
  10. The form successfully adds a record to the database. BUT.... it doesn't add what I put in the form, instead it adds 'NULL' to all of fields. So it looks like this: [img]http://localhost/policy_records.gif[/img] Is it beacuse the default value is NULL on all fields barring the id? If so, what can I do about that?
  11. Thankyou very much BUT... It does add records to the db but, all the entries have come up as NULL barring the date_of_birth field that prints today's date.  I want it to print the date that I put into the form.
  12. This is the error I am getting: [quote] Error inserting data - Incorrect date value: '' for column 'date_of_birth' at row 1 with query INSERT INTO policy_holder (id, 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) VALUES ( NULL, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '') [/quote] I have used NULL as my id (auto_increment) value as this worked when I inserted a record via SQL command line client. I have used DATE as my character type 'Foramt: YYYY-MM-DD', which I have used.  I cant see where the error is. Can somebody please help!!!  
  13. Here is the error message I get now with echoing the query in the error: [quote] Error inserting data - Incorrect date value: '' for column 'date_of_birth' at row 1 with query INSERT INTO policy_holder (id, 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) VALUES (NULL, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '') [/quote] I typed in NULL for my id auto_increment value because it worked when I entered a record via SQL command line client. Here are my table definitions, may be one day we'll get to the bottom of this: [img]http://localhost/policy_def.gif[/img]
  14. This is the query used: [quote]// if all data is there, build query   if ($msg=="") {     $insert = "INSERT INTO policy_holder     (id, 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)     VALUES ('', '$t', '$fn', '$sn', '$dob', '$uk', '$ms', '$d', '$es', '$ad1', '$a',     '$tn', '$c', '$pc', '$tw', '$th', '$fax', '$em')";     // open db connection     include 'includes/db_conn.txt';     // execute query and check for success     if (!mysqli_query($link, $insert)) {       $msg = "Error inserting data - "  .mysqli_error($link);     } else {       $msg = "Record succesfully added";       // set vars to "" for next form input       $t = $fn = $sn = $dob = $uk = $ms = $d = $es = $ad1 = $a = $tn = $c = $pc = $tw = $th =       $fax = $em = "";     }     mysqli_close($link);   } [/quote] But it produces this error: [quote]Error inserting data - Out of range value adjusted for column 'id' at row 1[/quote] What can I do to get this form working correctly??
×
×
  • Create New...

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.