Having trouble validating using mysqli

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gerrybytes
    New Member
    • Apr 2008
    • 11

    Having trouble validating using mysqli

    I am using a form in html as a login. However when passing this info php to be validated I get an error from mysql statements.

    A point in the right direction would be of great help. I've been stuck on this for quite a while. The error is recevied when tring to connect to the database i am using.[php]<?php
    session_start() ;
    $host="hostname ";
    $user="username ";
    $db_password="p assword";
    $database="data base name";
    $user_name = $_POST['user_name']; //this is from the html page
    $password = $_POST['password']; //this is from the html page

    $cxn = mysqli_connect( $host,$user,$db _password)or die("cannot connect");
    mysqli_select_d b($database) or die("cannot connect to database");

    $query = "SELECT * FROM table_name
    WHERE user_name='$use r_name' AND password='$pass word'";

    $result = mysqli_query($q uery, $cxn) or die ('error making query');
    $affected_rows = mysqli_num_rows ($result);

    if($affected_ro ws ==1) {
    print 'validated';
    }
    else {
    print 'not valid';
    }

    ?>[/php]Thanks G
    Last edited by ronverdonk; Apr 9 '08, 10:49 AM. Reason: code tags
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Have a look at the mysqli_query correct syntax in the php documentaton HERE and you'll see the cause.

      Btw: this is NOT a MySQL error, but a PHP one. So I will move this thread to the PHP forum.

      Ronald

      Comment

      Working...