PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 21st, 2013, 12:22 PM
natturefrk natturefrk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 37 natturefrk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 20 m 46 sec
Reputation Power: 1
I get database not selected

I have went ahead and just learned how use pdo and I having a problem when I am trying to put the path into the database.

here is my connect file:
PHP Code:
<?php

$connect
['db'] = array(

    
'dbhost'  => '127.0.0.1',
    
    
'dbname'  => 'portfolio',
    
    
'user'  => 'root',
    
    
'pass'  => ''

);


$db = new PDO('mysql:host= ' $connect['db']['dbhost'] . '; dbname = '$connect['db']['dbname'], $config['db']['user'], $config['db']['password']);


?>



Is there an error in my syntax? If not can it be included into another file?

then here is where the above script is being included:

PHP Code:
<?php

//error_reporting(0);


if($_POST['submit']){
        
    
//assigning variables to different values of $_FILES array
    
$name addslashes($_FILES['upload']['name']);

    
$tn   addslashes($_FILES['upload']['tmp_name']);

    
$size $_FILES['upload']['size'];
    
    
    
//other variables
    
$album_name $_POST['album_name'];
    
    
$file_directory 'upload/upload/'.$album_name;

    
    
//upload sec
    
$to 'upload/upload/'$album_name .'/'.$name;
    
    
$exts = array('jpg''jpeg''gif''png');
    
    
$ext strtolower(end(explode('.'$name)));


    
//vars for db
       
        //RIGHT HERE    
        
include 'upload/connect.php';
    
    
$directory_path 'upload/upload/'.$album_name;
    
    
$desc $_POST['description'];
            
    
$sql "INSERT INTO Group_1(dir_path, image_description) VALUES(:directory_path, :desc)";    

    
$q $db -> prepare($sql);    
    
    
    
    if(
in_array($ext$exts) === FALSE){
        
        echo 
'That file type is not supported!<br /><br /><a href="upload/index.php">Go Back</a>';
        
    }elseif(
$size 1073741824){
        
        echo 
'Sorry, but that file is to big! Only files that are no bigger than 1gb!<br /><br /><a href="upload/index.php">Go Back</a>';
        
    }else{
            
        if(!
file_exists($file_directory)){
                
            
mkdir('upload/upload/'.$album_name);
            
                
$q -> exacute(array(
                              
                              
':directory_path'  => '$directory_path',
                
                  
':desc' => '$desc'
                
                
));
                
            if(!
move_uploaded_file($tn$to)){
                    
                echo 
'Sorry, but the upload failed!<br /><br /><a href="upload/index.php">Go Back</a>';
                    
            }else{
                
                echo 
'File successfully uploaded!<br /><br /><a href="upload/index.php">Go Back</a>';    
            
            }
                    
        }else{
                
            if(!
move_uploaded_file($tn$to)){
                    
                echo 
'Sorry, but upload failed!<br /><br /><a href="upload/index.php">Go Back</a>';
                    
            }else{
                    
                echo 
'File successfully uploaded!<br /><br /><a href="upload/index.php">Go Back</a>';
                    
            }
                
        }
                
    }
            
}

?>

Reply With Quote
  #2  
Old February 21st, 2013, 12:57 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
For one thing you never instantiate $q.

P.S. It is 'execute' not 'exacute'.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old February 21st, 2013, 08:57 PM
natturefrk natturefrk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 37 natturefrk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 20 m 46 sec
Reputation Power: 1
I dont quite know what you mean about instantiate $q. I am new to PDO and still learning how to do because I am use to using the old method. Could I please have an example if is not to much trouble of what your talking about?

Reply With Quote
  #4  
Old February 22nd, 2013, 07:07 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
Sounds like you are unfamiliar with OOP. Northie wrote an excellent introduction so go here first. For a better job than I can do on using PDO go here.

Last edited by gw1500se : February 22nd, 2013 at 07:09 AM.

Reply With Quote
  #5  
Old February 22nd, 2013, 07:35 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,881 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 9 h 36 m 16 sec
Reputation Power: 813
No offense, gw1500se, but I think you're really on the wrong track here.

$q doesn't have to be "instantiated", it simply holds the return value of $db, as you can see in this line:
PHP Code:
 $q $db -> prepare($sql); 


So nothing wrong with how he/she uses PDO or OOP in general.

As far as I can tell, the problem is due to the spaces in the DSN string. Remove them so that you only have
Code:
mysql:host=...;dbname=...


And turn on your error reporting. The PDO instantiation alone should spill out plenty of error messages.
Comments on this post
gw1500se agrees: None taken, I am here to learn too. Dopey me completely missed that somehow.

Reply With Quote
  #6  
Old February 22nd, 2013, 10:59 AM
natturefrk natturefrk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 37 natturefrk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 20 m 46 sec
Reputation Power: 1
I changed it to this and still I get no database selected:

PHP Code:
<?php

$dbhost 
'localhost';

$dbname 'portfolio';

$dbuser 'root';

$dbpass '';


$db = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);

//THIS LINE DOES NOT RETURN NOTHING=
$db ->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);

?>

Reply With Quote
  #7  
Old February 22nd, 2013, 12:14 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
You need to add some error checking:
PHP Code:
try {
   
$db = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
}
catch (
PDOException $e) {
   die(
"Connection failed: ".$e->getMessage();


Reply With Quote
  #8  
Old February 22nd, 2013, 12:20 PM
natturefrk natturefrk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 37 natturefrk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 20 m 46 sec
Reputation Power: 1
I tried the above code and I get no errors, just a blank page

Reply With Quote
  #9  
Old February 22nd, 2013, 12:22 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
Oops. Syntax error in my code. Add the missing ).
PHP Code:
die("Connection failed: ".$e->getMessage()); 

Reply With Quote
  #10  
Old February 22nd, 2013, 12:25 PM
natturefrk natturefrk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 37 natturefrk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 20 m 46 sec
Reputation Power: 1
I caught that syntax error and still no errors just a blank page. I it is quite allright, everybody makes mistakes. You should see some of the noob mistakes i make.

Reply With Quote
  #11  
Old February 22nd, 2013, 12:30 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
If you're still getting a blank page then there must be a syntax error somewhere. Check the httpd log.

Reply With Quote
  #12  
Old February 22nd, 2013, 12:42 PM
natturefrk natturefrk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 37 natturefrk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 20 m 46 sec
Reputation Power: 1
Well I have to go to work now but will be on later. If you were talking about httpd.pid in the logs folder of xampp then all it said was 387 but when I went into the error log it said this:

[Fri Feb 22 11:48:08 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Fri Feb 22 11:48:11 2013] [notice] Digest: generating secret for digest authentication ...
[Fri Feb 22 11:48:11 2013] [notice] Digest: done
[Fri Feb 22 11:48:12 2013] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations

I dont know if this means anything?

Reply With Quote
  #13  
Old February 22nd, 2013, 12:56 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
Not with respect to the PHP problem. Make sure error logging is turned on in php.ini.

Reply With Quote
  #14  
Old February 22nd, 2013, 12:57 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
Not with respect to the php error. Make sure error logging is turned on in php.ini.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > I get database not selected

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap