473,394 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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="password";
$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
2 1372
ronverdonk
4,258 Expert 4TB
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
Apr 9 '08 #2
ronverdonk
4,258 Expert 4TB
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
Apr 9 '08 #3

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

Similar topics

1
by: laredotornado | last post by:
Hi, How do I change the place where the mysql socket file gets created? I thought it was in the my.cnf file by changing the "socket" property. However, using MySQL 5.0 on my Fedora Core 5 Linux...
12
by: davids58 | last post by:
trying to figure out how to use a mysql database with PHP. I ran the following code: <?php // defines database connection data define('DB_HOST', 'localhost'); define('DB_USER', 'ajaxuser');...
0
by: ojorus | last post by:
Hi; I am using the mysqli-extension on all my database queries. Everything worked just fine when I used MySQL 4, but when the database was upgraded to MySQL 5 (5.0.22), I got a strange error....
1
by: soft_devjava | last post by:
my environment: =========================== -php ver 5.2.0 -mysql 5 -windows xp -apache 2 -all of these are on the same machine my code: ==========================
13
by: Schmidty | last post by:
If you do a page reload with $_SERVER will your program lose a mysqli connection upon the reload of the page? Would this code work? I need to know how to carry over a connection between methods as...
4
by: chris | last post by:
Hello all, I am having problems getting Apache 2.2.4 to read the php_mysqli.dll file some my C:\php\ext\ directory. The following is the error that Apache displays in the error log: PHP...
2
by: Michael | last post by:
Hi, I try to use mysqli object instead of standard mysql functions. Is it ok to create mysqli object within my class or schould I pass mysqli object to my object. The problem is, with code...
0
by: anonymous | last post by:
I had a tough time getting PHP to connect to MySQL using mysqli on XP. The following code from the php documentation on mysqli failed to work on xp. $mysqli = new mysqli( "localhost", "user",...
2
by: Taras_96 | last post by:
Hi everyone, I'm trying to run a number of commands stored within a sql file from within php using mysqli::query. The syntax I'm using is: source C:\data\projects\forum...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.