What's wrong with this php code ?

ISSASSD

New member
<?php

$s = $_POST["lname"];
$x = trim($s);

$exists = false;
$selectedRow = 0;

mysql_connect (localhost,testuser,testuser);
mysql_select_db (testuser);


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,$selectedRo… 18, " ");
//$ss=mysql_result($s,$selectedRow,"ss")…
print "$f "."$l<br>Your date of birth is ".$b;
}

else
{
print "$x<br>Your name is not listed";
}

mysql_query("DROP DATABASE myDatabase") or die(mysql_error());
mysql_close();
?>
 
You really need to be more specific...

You create a database, read a file into it, then query the database and read the result record by record to see if it matches a name in a posted value, and display the DOB of the last matching record when it's found. Finally you delete the whole database.

This has 'inefficient' written all over it. What are you trying to accomplish? Why do you do it this way?
 
Back
Top