Jump to content

chrscote

Members
  • Posts

    10
  • Joined

  • Last visited

chrscote's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am writing a small page in which I want a combo box giving a list of options taken from a database table where the ID from the table is the value and the string is the actual option. I am trying to set it up using a foreach statement, but I keep getting the following error message: Notice: Array to string conversion in issue.php on Line 87. Here is the code I'm using to create this array. First, this is in the beginning of the file to get the array: $sqlStatuses = "SELECT StatusID, Status FROM Status"; try { $rsStatuses = $db->query($sqlStatuses); $arrAllStatus = $rsStatuses->fetchAll(); } catch (Exception $e) { echo $e->getMessage(); } Then in the page body, I am using: <select id="status"> <?php foreach ($arrAllStatus as $statID=>$status) { echo "<option value=\"$statID\"$selected>$status</option>"; } ?> </select> The errors I am getting are on the echo line. Do the variables I use after the "as" have to be the same as the fields in the table? I didn't think so. Chris
  2. I was trying to simplify things by just showing you the query I'm calling and how I created it. Here is the whole page with a couple of items using static values that already exist in the database for the issue query: $dbName = $_SERVER["DOCUMENT_ROOT"] . "/Ridley/RLCompRepair.accdb"; //echo $dbName."<br />"; if (!file_exists($dbName)) { die("Could not find database file.<br />".$dbName); } try { $db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};;Dbq=$dbName"); //echo "DB is connected: $dbName<br />"; } catch(PDOException $e) { echo "Error: ".$e->getMessage()."<br />"; $db = null; } error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); //Set default computer ID and Image Name values to check later $imgName = "none.gif"; $target_dir = "images/"; $imageUploaded = false; //Get values to edit the Customers table //This needs to be here so we can use it in the receipt. $fName = $_POST["fName"]; $lName = $_POST["lName"]; $street = $_POST["address"]; $city = $_POST["city"]; $state = $_POST["state"]; $zip = $_POST["zip"]; $phone = $_POST["phone"]; $compID = 0; $custID = $_POST["custId"]; $contactChg = $_POST["contactChg"]; $compChg = $_POST["compChanged"]; $retCust = $_POST["returnCust"]; //This is a new customer who has not been added to the database. try { $sql = "INSERT INTO Customers (FirstName, LastName, Street, City, State, Zip, Telephone) "; $sql .= "VALUES ('$fName', '$lName', '$street', '$city', '$state', '$zip', '$phone')"; $db->query($sql); echo "New Customer $sql<br />"; $sqlID = "SELECT @@identity AS ID FROM Customers"; $result = $db->query($sqlID); $row = $result->fetch(); $custID = $row["ID"]; } catch (Exception $e) { echo $e.getMessage(); } //Get values for Computers table $model = $_POST["model"]; $sn = $_POST["sn"]; if ($sn=="") { $sn = "---"; } $login = $_POST["login"]; $pw = $_POST["pw"]; $compID = $_POST["compSel"]; echo "compChg=$compChg, compID=$compID<br />"; if ($compID == "0") { //We are adding a new computer for this customer $sql = "INSERT INTO Computers (ComputerModel, ComputerSN, LogIn, Password, CustomerID)". " VALUES ('$model', '$sn', '$login', '$pw', '$custID')"; $db->query($sql); echo "New computer $sql<br />"; $sqlCompID = "SELECT @@identity AS ID FROM Computers"; $result = $db->query($sqlCompID); while ($row = $result->fetch()) { $compID = $row["ID"]; } } //Now, we're ready to add the issue to the Issues table $dateReq = date('n/j/Y'); $issue = $_POST["issue"]; $added = $_POST["added"]; $custID = 1; $compID = 1; $sqlIssue = 'INSERT INTO Issues (DateRequested, CustomerID, ComputerID, Issue, ItemsIncl, ImageName) '. 'VALUES (#'.$dateReq.'#, '.$custID.', '.$compID.', "'.$issue.'", "'.$added.'", "'.$imgName.'")'; try { $db->query($sqlIssue); echo "Added Issue<br /> $sqlIssue<br />"; } catch (Exception $e) { echo "Error adding issue: ".$e->getMessage(); } When I submit my form from the previous page, the first 2 queries work great. I get new customer and computer records. Also, I get the following text written printed from the echo lines: New Customer INSERT INTO Customers (FirstName, LastName, Street, City, State, Zip, Telephone) VALUES ('New', 'Newberg', '345 abc lane', 'Unlucky', 'CT', '66634', '643-234-5689') compChg=1, compID=0 New computer INSERT INTO Computers (ComputerModel, ComputerSN, LogIn, Password, CustomerID) VALUES ('Dell', '---', 'nnewberg', 'nnewberg!', '9') Added Issue INSERT INTO Issues (DateRequested, CustomerID, ComputerID, Issue, ItemsIncl, ImageName) VALUES (#1/17/2015#, 1, 1, "Testing", "Testing", "none.gif") I don't get any of the error echo lines. Chris
  3. OK, here is the code for this particular query: //Now, we're ready to add the issue to the Issues table $dateReq = date('n/j/Y'); $issue = $_POST["issue"]; $added = $_POST["added"]; $custID = 1; $compID = 1; $sqlIssue = 'INSERT INTO Issues (DateRequested, CustomerID, ComputerID, Issue, ItemsIncl, ImageName) '. 'VALUES (#'.$dateReq.'#, '.$custID.', '.$compID.', "'.$issue.'", "'.$added.'", "'.$imgName.'")'; try { $db->query($sqlIssue); echo "Added Issue<br /> $sqlIssue<br />"; } catch (Exception $e) { echo "Error adding issue: ".$e->getMessage(); } I added the 2 lines from ginerjm's signature and still do not get any error messages. Chris
  4. I'm using PD to connect to the database and for my queries. What I don't understand is that I have other insert queries that are working fine. In fact, before the query from above, I use 2 other insert statements that add a customer's name and info in one table and their computer info in another. But for some reason, when it gets to this query, just afterwards, it doesn't do anything. I don't even get an error message from my try..catch: try { $db->query($sqlIssue); echo "Added Issue<br /> $sqlIssue<br />"; } catch (Exception $e) { echo "Error adding issue: ".$e->getMessage(); } where $sqlIssue is the string of the query.
  5. What do you mean by DB driver? I have php_pdo_mssql, and php_pdo_odbc selected in my extensions.
  6. I am trying to create a query to insert data into a table in my Access database. I have the following query: INSERT INTO Issues (DateRequested, CustomerID, ComputerID, Issue, ItemsIncl, ImageName) VALUES (#1/14/2015#, 1, 1, "Computer freezes while I'm on the internet.", "AC Adapter", "none.gif") which should be performed from within my PHP page. However, when I check the database afterward, the new record isn't there. I then tried performing the query directly in Access and it worked fine. Why would it work in Access, but not when I run the same query in PHP? Chris
  7. Thank you mikosiko! I think that did the trick! At least it didn't give me the error. I'll try running the rest of the code in my page. Chris
  8. I have changed my $db line to: $db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};;Dbq=$dbName"); but I am still getting the same error message when I echo getMessage() on the PDOException. Here is a list of all the extensions I have enabled: php_curl php_gd2 php_mbstring php_mssql php_mysql php_mysqli php_pdo_mssql php_pdo_mysql php_pdo_sqlite I assumed that the mssql was the extension that needs to be set to handle Access, am I correct in that assumption. And just to be absolutely clear, I am using WAMP Version 2.4 with PHP 5.4.16. Any and all help is greatly appreciated. Thank you in advance, Chris
  9. I am using WAMP server for my PHP Server and am trying to connect to an Access Database with the extension of accdb, but I keep getting the error "could not find driver". Here is the code I'm trying to run: $dbName = $_SERVER["DOCUMENT_ROOT"]."/Ridley/RLCompRepair.accdb"; if (!file_exists($dbName)) { die("Could not find database file."); } try { $db = new PDO("odbc:Driver={MS Access Database (*.mdb, *.accdb)};Dbq=$dbName"); } catch (PDOException $e) { echo "Error: ".$e->getMessage(); } I have enabled the php_pdo_odbc extension, so I'm pretty sure this is not the problem. Could someone please let me know what is wrong? Chris
×
×
  • 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.