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
Auto fill in input value based on User_ID
Hello,
I'm looking form some input on the following problem.
User loads page ->
PHP Array quick help
I need
$_SESSION{'username'} to be like this:
if $_SESSION['username'] = "gay
Chat Box in PHP
I was thinking in doing a Chat Box in PHP. For that I would use a form with two fields, Nick and Mes
simple script won't work. Please help
I'm new to php, and I am having trouble displaying a simple script in my web browser. My php code ex
Required to login help
I'm trying to set up my site so users have to be logged into the forum to access the site.I've been
Checking if variable is 0 as opposed to NULL/Empty...
I'm trying to write some code that will retrieve a user's access level from my database and if it do
Return X values where an ID number doesnt matter
Well as for subject heading, thats the best i could think of.
Currently im having a problem w
Help building / using array
First - this is a cross-posting, if this is wrong I apologise! What started out as a MySQL query que
DateObject and Nulls
Hi all,
I have an array mapped to a value object. One of the items in the array is a PHP Date
Day of week
I am using PHP version 5.0.5
I have a varaible ($DATE (date format yyyy-mm-dd)) that is being inc