Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP edit DB records page - not working

    Im trying to make a page that i can edit individual records from my database on. The following is part of the code for the page that passes along the variable.

    When someone hits the edit button for one of teh records, the correct page opens(cust_edit.php) and the url reflects the customer ID of that record (i.e. sliquid.com/protected/cust_edit.php?customerID=xxx)

    PHP Code:
    $search_results .= "  
    <tr align=center bgcolor="
    .$color.">  
    <td><font face=\"Tahoma\" size=\"1\">$row[firstname]</font></td>  
    <td><font face=\"Tahoma\" size=\"1\">$row[lastname]</font></td>  
    <td><font face=\"Tahoma\" size=\"1\">$row[city]</font></td>  
    <td><font face=\"Tahoma\" size=\"1\">$row[state]</font></td>  
    <td><font face=\"Tahoma\" size=\"1\"><a href=\"mailto:$row[email]\">$row[email]</a></font></td>  
    <td><font face=tahoma size=1><form action='cust_edit.php'><input type='hidden' name='customerID' value='$row[customerID]'><input type='submit' value='Edit'></form></font></td> 
    </tr>"

    OK, so that is working correctly from what I can tell. So now the page that grabs the ID, and lets me edit the record.
    Im trying to keep it simple until it works, so theres only some of the echo code there.
    PHP Code:
    <?php 
     ini_set
    ('error_reporting'E_ALL);  
     
    ini_set('display_errors''On'); 

    include(
    "dbconnection.php"); 
    $id=$_GET['customerID'];  
    $result odbc_query("SELECT * FROM customers WHERE customerID='$id' ",$cnx);  
         while(
    $myrow odbc_fetch_assoc($result))  
                 {  
    echo
    "  
    $firstname= $row[firstname];   
    $lastname= $row[lastname];   
    $address1= $row[address1];   
    $address2= $row[address2];   
    $city= $row[city];   
    $state= $row[state];   
    $zip= $row[zip];   
    $email= $row[email];   
    $referral= $row[referral];   
    $lubricant= $row[lubricant];    


    <!-- Your Form Stuff here -->  
    <input type=\"hidden\" name=\"customerID\" value=\"<? echo $id; ?>\">  
        First Name:<br>   
        <input type=\"text\" name=\"firstname\" value=\"<? echo $firstname; ?>\">  
        <br>  
        Last Name:<br>    
    <input type=\"text\" name=\"lastname\" value=\"<? echo $lastname; ?>\"> 


    "  
    }  
    ?>
    all i get when I hit submit on the previous page is this page, blank, with no error reported. Viewing source shows me nothing either, just
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
    <BODY></BODY></HTML>

    any ideas?

  • #2
    Regular Coder
    Join Date
    Mar 2005
    Location
    Brighton, UK
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    go into php.ini and check that display_errors is on, if not, turn it on and see if you get any errors.

    **EDIT**

    Sorry, didnt see the line in your code, think it needs to be this:

    ini_set('display_errors', true);

    rather than

    ini_set('display_errors', 'On');

  • #3
    New Coder
    Join Date
    Jan 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The two lines I have for error reporting work on several of my other pages, but I tried yours anyway. It didnt seem to make any difference.

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Location
    Brighton, UK
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    "  
    }  
    ?> 
    should be

    PHP Code:
    ";
    }
    ?> 

  • #5
    New Coder
    Join Date
    Jan 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, now were getting somewhere... Thanks Jak!

    now i think i have an error in my mysql to odbc translation

    727
    Fatal error: Call to undefined function: odbc_query() in d:\inetpub\sliquid\wwwRoot\protected\cust_edit.php on line 8

    727 is the echo'd customer ID.

    line 8 is
    $result = odbc_query("SELECT * FROM customers WHERE customerID='$id' ",$cnx);

    is the error telling me that the odbc_query() is wrong, or the $cnx? $cnx is called in an include. it works on several other pages.

    Heres the code
    PHP Code:
    <?php
     ini_set
    ('error_reporting'E_ALL); 
     
    ini_set('display_errors''On');

    include(
    "dbconnection.php");
    $id=$_GET['customerID']; 
    echo 
    "$id";
    $result odbc_query("SELECT * FROM customers WHERE customerID='$id' ",$cnx); 
         while(
    $row odbc_fetch_assoc($result)) 
                 { 
    echo

    $firstname= $row[firstname];  
    $lastname= $row[lastname];  
    $address1= $row[address1];  
    $address2= $row[address2];  
    $city= $row[city];  
    $state= $row[state];  
    $zip= $row[zip];  
    $email= $row[email];  
    $referral= $row[referral];  
    $lubricant= $row[lubricant];   


    <!-- Your Form Stuff here --> 
    <input type=\"hidden\" name=\"customerID\" value=\"<? echo $id; ?>\"> 
        First Name:<br>  
        <input type=\"text\" name=\"firstname\" value=\"<? echo $firstname; ?>\"> 
        <br> 
        Last Name:<br>   
    <input type=\"text\" name=\"lastname\" value=\"<? echo $lastname; ?>\">


    "
    ;
    }
    ?>
    Also, Ive been clued in that I do not need a loop, since there is only one record that will match the ID. I have tried to remove the while loop, but everything I do takes me back to the blank page with no error.
    Last edited by croix; 02-10-2006 at 07:39 PM.

  • #6
    Regular Coder
    Join Date
    Mar 2005
    Location
    Brighton, UK
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont personally use any of the ODBC functions in PHP, as i only use MySQL, but from what i can tell, there is no PHP function called odbc_query.

    The function in php for executing a query via ODBC is odbc_exec. Unless you have defined your own "odbc_query" function in the dbconnection.php file? If so, then for some reason its not working because PHP is saying it dosent exist.

    Your right, you dont need the loop, but if you just remove these lines:

    PHP Code:
    while($row odbc_fetch_assoc($result))  {
    ...

    it wont work becuase the loop defined $row, so if you remove the loop, you have to add this line:

    PHP Code:
    $row odbc_fetch_assoc($result); 
    Hope that helps.

  • #7
    New Coder
    Join Date
    Jan 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Updated Code:
    PHP Code:
    <?php
     ini_set
    ('error_reporting'E_ALL); 
     
    ini_set('display_errors''On');


    include(
    "dbconnection.php");
    $id=$_GET['customerID']; 
    echo 
    "$id";
    $query "SELECT * FROM customers WHERE customerID= '$id' ";
    $result odbc_exec($cnx$query); 
         while(
    $row odbc_fetch_array($result)) 
                 { 
    $row['firstname'] = $firstname;
    $row['lastname'] = $lastname;
    $row['address1'] = $address1;
    $row['address2'] = $address2;
    $row['city'] = $city;
    $row['state'] = $state;
    $row['zip'] = $zip;
    $row['email'] = $email;
    $row['referral'] = $referral;
    $row['lubricant'] = $lubricant;

    echo
    "  
    $firstname= $row[firstname];   
    $lastname= $row[lastname];   
    $address1= $row[address1];   
    $address2= $row[address2];   
    $city= $row[city];   
    $state= $row[state];   
    $zip= $row[zip];   
    $email= $row[email];   
    $referral= $row[referral];   
    $lubricant= $row[lubricant];    


    <!-- Your Form Stuff here -->  
    <input type=\"hidden\" name=\"customerID\" value=\"<? echo $id; ?>\">  
        First Name:<br>   
        <input type=\"text\" name=\"firstname\" value=\"<? echo $firstname; ?>\">  
        <br>  
        Last Name:<br>    
    <input type=\"text\" name=\"lastname\" value=\"<? echo $lastname; ?>\"> 


    "


    ?>
    Updated Error:

    727
    Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in d:\inetpub\sliquid\wwwRoot\protected\cust_edit.php on line 10

    Warning: odbc_fetch_array(): supplied argument is not a valid ODBC result resource in d:\inetpub\sliquid\wwwRoot\protected\cust_edit.php on line 11

  • #8
    Regular Coder
    Join Date
    Mar 2005
    Location
    Brighton, UK
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "Data type mismatch" indicates that a variable has been parsed as the wrong type. Is the customerID field a text/string field? If its a number/integer field then you dont need the single quote marks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •