Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

connect to sql

  • 30-03-2013 09:31AM
    #1
    Posts: 106 ✭✭


    44787-creating-loginregistration-forms-with-php

    <?php
    if($_GET["regname"] && $_GET["regemail"] && $_GET["regpass1"] && $_GET["regpass2"] )
    {
    if($_GET["regpass1"]==$_GET["regpass2"])
    {
    $servername="localhost";
    $username="root";


    $conn= mysql_connect($servername,$username)or die(mysql_error());
    mysql_select_db("test",$conn);
    $sql="insert into users (name,email,password)values('$_GET[regname]','$_GET[regemail]','$_GET[regpass1]')";
    $result=mysql_query($sql,$conn) or die(mysql_error());
    print "<h1>you have registered sucessfully</h1>";

    print "<a href='index.php'>go to login page</a>";
    }
    else print "passwords doesnt match";
    }
    else print"invaild data";
    ?>


    Hi guys, trying to connect to a data base and having some trouble. Do I simple just put into the above

    $password="password";

    I have tryed this and I get and error message unable to connect.

    thanks


Comments

  • Registered Users, Registered Users 2 Posts: 1,477 ✭✭✭azzeretti


    Cannot say I know php at all but it looks like you're not passing enough information to your connection function. Shouldn't you need more than server name and username? Password too?


  • Registered Users, Registered Users 2 Posts: 7,041 ✭✭✭Seachmall


    [PHP]$conn = mysql_connect($host,$user,$pass);[/PHP]

    Presumably you need a password to connect to the DB, especially as you're connecting as root.


Advertisement