Results 1 to 4 of 4

Thread: Newbie Question - connecting to MySQL with PHP

  1. #1
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Newbie Question - connecting to MySQL with PHP

    Hi all

    I am trying to create a simple login to a webpage. From watching you tube tutorials I have put together the basics, and i understand the processing. However when i run my login processing script i get the following error from the php script:

    Parse error: syntax error, unexpected ';'

    My code PHP code is, the error occurs at $con = msql_connect("****","*****","****");

    PHP Code:
    $username $_POST["username"]; 
    $password $_POST["password"];
    $login $_GET["login"];

    if(
    $login=='yes')(

    $con msql_connect("****","*****","****");

    msql_select_db("Login");

    $get msql_query("select count(id) FROM Login WHERE user='$username' and pass='$password'");

    $result msql_result($get,0);

    if(
    $result!=1}(

    echo 
    "Invalid Login";
    )Else(
    echo 
    "Login Sucessfull";
    )

    Cannot understand the problem when all the examples i have seen show a semi colon at the end of the line as shown?

    Am i wrong somewhere else?.....any help would be greatly appreciated

    Note I have omitted the actual login details for my SQL database from the line and replaced with stars

    thanks
    Last edited by Transentient; 10-15-2011 at 09:14 PM. Reason: formatting changes

  2. #2
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Pay attention to your parenthesis and brackets. They are different from one another.

    Also, it might be a good idea to get used to using tabs, spaces, and line spacing to improve the readability of your code.

    This should work:

    Code:
    $username = $_POST["username"];
    $password = $_POST["password"];
    $login = $_GET["login"];
    
    if($login == 'yes') {
    
        $con = msql_connect("****", "*****", "****");
    
        msql_select_db("Login");
    
        $get = msql_query("select count(id) FROM Login WHERE user='$username' and pass='$password'");
    
        $result = msql_result($get, 0);
    
        if($result != 1) {
    
            echo "Invalid Login";
    
        } else {
    
            echo "Login Sucessfull";
    
        }
    
    }

  3. #3
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi Jason

    Many thanks for your help

    But i now get this error Fatal error: Call to undefined function msql_connect()

    From this line of the previous code $con = msql_connect("mysql19.streamline.net", "homenetne1", "*****");

    I have double checked, the server name where the MySQL is hosted is correct, details provided by my host, the Database name is correct, generated by my host, and the password, although not shown here is also correct.

    My host also gave me an ip address for the MySQL server, tried this also same error.

    Your help is greatly appreciated

    Thanks

  4. #4
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Use: mysql_connect(); NOT msql_connect();

    if you are using a MySQL database.

    Although msql_connect() is a valid function.

  5. The Following User Says Thank You to JasonDFR For This Useful Post:

    Transentient (10-16-2011)

Bookmarks

Posting Permissions

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