Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Senior Member
    Join Date
    Apr 2016
    Posts
    717
    Member #
    53891
    Liked
    11 times

    php db connect error

    hi, im getting the following error with my php pdo connect attempt

    Fatal error: Uncaught exception 'PDOException' with message 'invalid data source name' in C:\xampp\htdocs\phpcourse\db&php\include\db.php:3 Stack trace: #0 C:\xampp\htdocs\phpcourse\db&php\include\db.php(3) : PDO->__construct('', NULL, NULL) #1 C:\xampp\htdocs\phpcourse\db&php\insert.php(3): require_once('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\phpcourse\db&php\include\db.php on line 3
    very little code to show just two files

    PHP Code:
    <?php

    require_once("include/db.php");
    if (isset(
    $_POST["submit"])){
      if (!empty(
    $_POST["EName"])&&!empty($_POST["ssn"])){

      }else{
        echo 
    "please fill in name and ssn";
      }

    }
     
    ?>

    <!doctype html>
    <html>

    <head>
      <title> Insert into database </title>
      <link rel="stylesheet" href="include/style.css"
    </head>

    <body>
      <div class="formbox">

        <form class="" action="insert.php" method="post">
          <fieldset>
            <span class="fieldinfo"> employee name:</span>
            <br>
            <input type="text" name="EName" value="">
            <br>
            <span class="fieldinfo"> social security no:</span>
            <br>
            <input type="text" name="ssn" value="">
            <br>
            <span class="fieldinfo"> department:</span>
            <br>
            <input type="text" name="dept" value="">
            <br>
            <span class="fieldinfo"> salary:</span>
            <br>
            <input type="text" name="salary" value="">
            <br>
            <span class="fieldinfo"> home address:</span>
            <br>
            <textarea name="address" rows="8" cols="80"></textarea>
            <br>
            <input type="submit" name="submit" value="submit your record">

          </fieldset>
        </form>

      </div>

    </body>
    </html>
    and the db conncet code in the other file

    PHP Code:
    <?php

    $connectingdb 
    = new PDO(`mysql:host=localhost;dbname=record`,`root`,``);


    ?>
    i havent set any password for the db either
    any help is greatly appreciated

  2.  

  3. #2
    Junior Member
    Join Date
    Mar 2019
    Location
    Mansfield
    Posts
    2
    Member #
    60493
    The error is occurring at line 3 of db.php but you haven't shown the contents of that file have you?


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 01:57 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com