www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22

Thread: PHP and mySQL connection string

  1. #16
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    Without seeing the current code, all we can do is speculate (since your originally posted code does not contain a "$a" on line 3).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  2. #17
    Join Date
    Apr 2014
    Posts
    33
    thanks for the comments, here is the code so far:

    config.php (the connection to the database)
    Code:
    <?php 
    
    ini_set('display_errors', true); // change to false when you go live
    error_reporting(E_ALL);
    
    //Mysql Connect  |   mysql_connect("host= 3306","username","");
    //Below example to connect in localhost
    $a=mysql_connect("localhost","root","");
    if($a == false) {
        die("Connect failed: ".mysql_error());
    }
    //select your database
    $b=mysql_select_db("database_name",$a);
    if($b == false) {
        die("DB select failed: ".mysql_error());
    }
    ?>
    and here is the submit_form.php code
    Code:
    <?php
    //select your database
    $b=mysql_select_db("database_name",$a);
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $username=$_POST['username'];
    //$confirmusername=$_POST['confirmusername'];
    $password=$_POST['password'];
    $confirmpassword=$_POST['confirmpassword'];
    $email=$_POST['email'];
    $confirmemail=$_POST['confirmemail'];
    
    //Database connection
    require_once("config.php");
    
    //mysql query to insert value to database
    $query=mysql_query("INSERT INTO registration (`firstname`, `lastname`, `username`, `confirmusername`, `password`, `confirmpassword`, `email` ,`confirmemail`) VALUES ('$firstname', '$lastname', '$username', '$password', '$confirmpassword', '$email' , '$confirmemail')");
    
    
    
    //if value inserted successyully disply success message
    if($query)
    {
        
        echo 'Registred successfully..!!</div>';
    }else
    {
    //error message
        echo '<unable to registred !!</div>';
    }
    ?>
    Hope this helps with the problems that I'm having

  3. #18
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    Start by getting rid of the call to mysql_select_db() in the submit_form.php file, since (a) you do it in the config.php file, and (b) you can't do it until after you require config.php in the first place.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #19
    Join Date
    Apr 2014
    Posts
    33
    hey nogdog thanks for all your support, got a new problem for you sorry to be such a pain but at least its better than just a plan white blank screen that i was getting earlier in the week!

    Notice: Undefined variable: a in C:\xampp\htdocs\submit-form.php on line 3

    Warning: mysql_select_db() expects parameter 2 to be resource, null given in C:\xampp\htdocs\submit-form.php on line 3

    Notice: Undefined variable: a in C:\xampp\htdocs\config.php on line 9
    Connect failed:

  5. #20
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    In submit_form.php, delete or comment out the line in red (but leave it in the config file):
    Code:
    <?php
    //select your database
    $b=mysql_select_db("database_name",$a);
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $username=$_POST['username'];
    //$confirmusername=$_POST['confirmusername'];
    $password=$_POST['password'];
    $confirmpassword=$_POST['confirmpassword'];
    $email=$_POST['email'];
    $confirmemail=$_POST['confirmemail'];
    
    //Database connection
    require_once("config.php");
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #21
    Join Date
    Apr 2014
    Posts
    33
    hey i've done what you have said and it seems to have worked as now this is what is showing up (i feel kind of happier with this!)

    Notice: Undefined variable: a in C:\xampp\htdocs\config.php on line 9
    Connect failed:

  7. #22
    Join Date
    Apr 2014
    Posts
    33
    hi guys i;m now getting the following error message


    Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\config.php on line 8

    Notice: Undefined variable: b in C:\xampp\htdocs\config.php on line 14
    DB select failed:

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles