...

View Full Version : PHP edit DB records page - not working



croix
02-10-2006, 04:34 PM
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)


$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
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?

Jak-S
02-10-2006, 04:43 PM
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');

croix
02-10-2006, 04:53 PM
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.

Jak-S
02-10-2006, 05:21 PM
"
}
?>

should be


";
}
?>

croix
02-10-2006, 06:04 PM
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
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.

Jak-S
02-11-2006, 11:36 AM
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 (http://uk.php.net/manual/en/function.odbc-exec.php). 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:


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:


$row = odbc_fetch_assoc($result);

Hope that helps.

croix
02-13-2006, 05:55 PM
Updated 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

Jak-S
02-14-2006, 11:08 AM
"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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum