why isn't this PHP code working ???
Posted on
16th Feb 2014 07:03 pm by
admin
it's suppose to find a name on the database.
<?php
$s = $_POST["lname"];
$x = trim($s);
$exists = false;
$selectedRow = 0;
mysql_connect (localhost,testuser,testuser);
mysql_select_db (testuser);
mysql_query("DROP TABLE myTable");
mysql_query("CREATE DATABASE myDatabase");
mysql_query("USE myDatabase");
mysql_query("CREATE TABLE myTable (firstname VARCHAR(20), " .
"lastname VARCHAR(20), birthdate DATE, dependents INT, ss VARCHAR(11))");
mysql_query("LOAD DATA LOCAL INFILE 'names.txt' INTO TABLE myTable")
or die(mysql_error());
$s = mysql_query("SELECT * FROM myTable ORDER BY lastname");
$rows=mysql_numrows($s);
for($i = 0; $i < $rows; $i++){
$result = trim(mysql_result($s,$i,"lastname"));
if ( strcmp($x, $result) == 0 )
{
$exists = true;
$selectedRow = $i;
}
}
if ($exists == true)
{
$f = mysql_result($s,$selectedRow,"firstname");
$l = mysql_result($s,$selectedRow,"lastname");
$b = mysql_result($s,$selectedRow,"birthdate");
//$d=str_pad(mysql_result($s,$selectedRow,"dependents"), 18, " ");
//$ss=mysql_result($s,$selectedRow,"ss");
print "$f "."$l
Your date of birth is ".$b;
}
else
{
print "$x
Your name is not listed";
}
mysql_query("DROP DATABASE myDatabase") or die(mysql_error());
mysql_close();
?>
No comments posted yet
Your Answer:
Login to answer
139
35
Other forums
Add_Months not Easy to Understand
Oracle is number 1, very fast and very easy. But....
OK, I think but have a problem, only 1 pro
Members Only
Hi all, for my website i have a members area only which on members can veiw, but at the moment anyon
help retrieiving results and doing pagination
Having some trouble trying to get the results to show on more than just one page.
What is ha
Help to integrate whois Domain Details to website
Hi,
can i know is their any php script r methods to add domain details to my website.
Recognising Revenue daily
Hello.
Has anyone come across daily recognition of deferred income?
We want to implement R
Text file to .Dat file Conversion in PHP
Hi All,
Could anybody provide code for Text file to .Dat file Conversion in PHP.
Tha
date("now") prints out wrong date ?
Hi Guys
Anyone know why and how I can fix it ?
Ajax not working on IE 6 for Windows CE
I've created a webpage which uses the classis Ajax in following format:view plaincopy to clipboardpr
php slowing my site?
Hi all,
I think that one of the reasons that my site doesn't work fast is that the code is ve
COde for a Cc
I'm not receiving $ft as a Cc. Why is that??
$to = "$email";
$headers = "Fr