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
PHP MySQL and DATE
Hi everyone
I have a databse and in one of the columns I have date values such as 2009-March-
Change image filetype on upload?
Hi,
I've got a form which uploads an image to the server.
Is it possible to change the image t
Help If user voted, block them
On my Prayer request site, i let users Click a button to Pray for somone that has posted a pray, i g
Easy administration on MySQL databases
My website is database driven and I am very tired of manually making queries to my tables in order t
search query in mysql in php problem
my search query wont work, i know, that my codes are correct.please help
Code: [Select]&l
LOOPing Problem
Hello All!
The following code loops through the data and displays the data accordingly. My p
SOAP Issue
Hi,
I am facing some understanding problem with SOAP basic.kindly recommend some SOAP expert.
small inaccuracies
I have this code to convert fractional base 10 into base 2:
while($num > 0)
Problem displaying "scraped" XML data
I'm basicly having trouble displaying XML data scraped from an URL using cURL.
What the code
Basic Question Regarding PHP Includes
Hi
Just starting out with PHP.
Working on a site that uses some basic includes, these