If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

php code help?? urgent - eror in result

hello friends i want to show record on firstname condition..i create a html form to get firstname input from user and a submit button...and the result.phph file including code given below...but it give me error on highlighted line..please tell me what i do..please correct this code....
<?php
$con=mysqli_connect("abc.com","college","College","college");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

If that's the case, then my best guess is that either:
[*]There is no exact match in the database for the first name you are supplying (remembering it is case-sensitive and white-space matters), or[*]There is some flaw elsewhere that is corrupting the value in $_POST['firstname'] (which maybe you could var_dump() right before you use it, to verify what is in it).

Simplest way to debug might be to just echo out $sql after you define it, and then copy and paste it into a MySQL command line session or phpMyAdmin SQL window and see what it returns.

If that's the case, then my best guess is that either:
[*]There is no exact match in the database for the first name you are supplying (remembering it is case-sensitive and white-space matters), or[*]There is some flaw elsewhere that is corrupting the value in $_POST['firstname'] (which maybe you could var_dump() right before you use it, to verify what is in it).

Simplest way to debug might be to just echo out $sql after you define it, and then copy and paste it into a MySQL command line session or phpMyAdmin SQL window and see what it returns.

thanks bro..i got it and fixed the error.....it is case sensitive.....i have another question....i want to show text massage if there is no matched record found in the database....give me code for that bro...also tell me in each .php page in which i enter queries..i have to connect database???

thanks bro..i got it and fixed the error.....it is case sensitive.....i have another question....i want to show text massage if there is no matched record found in the database....give me code for that bro...also tell me in each .php page in which i enter queries..i have to connect database???

For your first part, you can simply print it to the screen with an echo or be fancier and have an alert created through JavaScript or jQuery. For example:

PHP Code:

#if there is no match
echo("Found no match for $record");

#putting the result in a HTML element to control its position:
echo("<h4 id = 'noMatch' >Found no match for $record</h4>");

# or being fancier and use JS (bit sloppy in this example):
echo("<script type = 'text/javascript'>");
echo("alert('No match was found for $record');");
echo("</script>");

For your second question, it depends whether you use a global variable to store your database connection, have a singleton class, etc... . You can certainly connect to your database in each file if you don't have any of those in place.