By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,391 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,391 IT Pros & Developers. It's quick & easy.

Having trouble validating using mysqli

P: 11
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
$database="database 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_db($database) or die("cannot connect to database");

$query = "SELECT * FROM table_name
WHERE user_name='$user_name' AND password='$password'";

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

if($affected_rows ==1) {
print 'validated';
else {
print 'not valid';

?>[/php]Thanks G
Apr 8 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 4,258
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.

Apr 9 '08 #2

Expert 2.5K+
P: 4,258
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.

Apr 9 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.