CommonEnemy Posted October 25, 2010 Share Posted October 25, 2010 This is bothering me beyond belief I'm hoping that someone here might be able to help me. I've tried playing around with a few permissions, that could be the problem. Basically if I try to create/open a database it will create an error I've narrowed it down to this one line and it's the first one which leads me to believe that it's either a php configuration problem or a permissions thing. Running IIS 7.0 <html> <body> <?php $dbh = new PDO('sqlite:poems.sqlite'); ?> <?php //phpinfo(); $name=$_POST["userName"]; $contact=$_POST["userContact"]; $poem=str_replace(" ","<br />",$_POST["userPoem"]); $comment=str_replace(" ","<br />",$_POST["userComment"]); $query='INSERT INTO '.$dbh.' (name,contact,body,desc) VALUES ('.$name.','.$contact.','.$poem.','.$comment.')'; echo $query; /*$db->exec('INSERT INTO '.$db.' (name,contact,body,desc) VALUES ('.$name.','.$contact.','.$poem.','.$comment.')');*/ ?> <p> <b>Your name:</b> <?php echo $name; ?><br /> <b>Your contact info:</b> <?php echo $contact; ?><br /> <b>Your Poem:</b><br /> <?php echo $poem; ?><br /> <b>Your Comments:</b><br /> <?php echo $comment; ?> </p> </body> </html> <?php $dbh = null; ?> Any and all help is appreciated. Would Apache be any better? I'm considering just switching over if so. Quote Link to comment Share on other sites More sharing options...
trq Posted October 26, 2010 Share Posted October 26, 2010 Basically if I try to create/open a database it will create an error What error? Quote Link to comment Share on other sites More sharing options...
CommonEnemy Posted October 26, 2010 Author Share Posted October 26, 2010 Catchable fatal error: Object of class PDO could not be converted to string in C:\inetpub\wwwroot\form.php on line 21 Quote Link to comment Share on other sites More sharing options...
trq Posted October 26, 2010 Share Posted October 26, 2010 Ah, yeah, that'll be your problem. Your using $dbh, (which is a connection object) as the table name in your query (which should be a string). Quote Link to comment Share on other sites More sharing options...
CommonEnemy Posted October 26, 2010 Author Share Posted October 26, 2010 So it would be an integer then? I've tried converting it using "{ }" in an echo but I still get errors. Edit: If you look at the code, the query doesn't actually get executed, only echoed. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 26, 2010 Share Posted October 26, 2010 I think you should reread what thorpe posted and then read your query statement - Ah, yeah, that'll be your problem. Your using $dbh, (which is a connection object) as the table name in your query (which should be a string). The $dbh variable is NOT your table name, it is your database connection object. It does not belong in the query. Your table name belongs in the query. Quote Link to comment Share on other sites More sharing options...
CommonEnemy Posted October 26, 2010 Author Share Posted October 26, 2010 Right, I read it but since I'm not used to object/class programming I assumed that the database connection object could be represented as an integer which I could echo to see if my open function succeeded or not. That aside, I've cleaned up my query and I'm getting this error: Warning: PDO::exec(): SQLSTATE[HY000]: General error: 1 near "Morrison": syntax error in C:\inetpub\wwwroot\form.php on line 26 Array ( [0] => HY000 [1] => 1 [2] => near "Morrison": syntax error ) Where Morrison is the name. I've used sqlite before, awhile ago mind, and I can't see the syntax error regarding the query. Could it be a PHP error I've made? Got that one sorted out, forgot about the ' ' since they were already there for adding the strings together. New problem is: Warning: PDO::exec(): SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in C:\inetpub\wwwroot\form.php on line 26 Array ( [0] => HY000 [1] => 8 [2] => attempt to write a readonly database ) But I think I can handle it on my own, thanks for all your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.