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
How to find OS bit version
How can I tell the person browsing my site is running 32, or 64 bit operating system?
Checking if multidimensional array is empty?
I have a for with multiple test input fields. Specifically the user submits multiple names and ages
losing variables between php brackets
Hi
have got this code:
Code: $id=mysql_result($result,0,"itemid");
$title=mys
array_map() probably obvious mistake
The code below is part of a class to escape strings, but should also accept an array, using array_ma
LinkedList help
Ok so I just learned quickly about lists, so I have a not too hard project I think, but am having a
How do I give a developer access to a specific directory and nothing else?
I want to give a develop access to a specific directory and nothing else
I can give them an F
PHP Tab Control
Hi All,
I would like to have PHP tab control with/without Javascript.
But I want to r
rename the file
File.txt
Code: ***DOCUMENT***
..DN:
000044255
..CB:
..SN:
..PY:
2009
..E
Need help PLEASE
ok i have this warning showing up
Warning: in_array() [function.in-array]: Wrong datatype for
Using system() and bringing back the results
I am aware that you can use system() within PHP to execute system commands, but I was wondering if t