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 Like 35 Dislike
Previous forums Next forums
Other forums

Unable to display contents in Second Drop Down Box
Hi All,

What I am trying to do is 2 dependent drop down boxes and when user selects su

Show specific day of the week
I have been racking my brain trying to get this function to work properly and it is doing so for eve

asp authentication problem
Hello all, I want to use the asp authentication (from asp.net configuration) in my web site. there

dinamic "textboxes"?
Ey all, my first post here, i hope its not a hard one

I display mysql results in a table

To change the name of label on SAP screen XK02.
Hi All,

Can one suggest me how to change the label of an input field of a sap standard s

please help me in this update statment
hi every one

if I have table and this data in it

id name
10

Text file to .Dat file Conversion in PHP
Hi All,
Could anybody provide code for Text file to .Dat file Conversion in PHP.

Tha

question about header() security
is is safe to just use the header() function to redirect someone if they are, say, not logged in? or

Just a white page
Okay so, my website, when I click SignUp on it it takes me to /join.php but its a complete white pag

Email logic not working
I would like to send an email using the php email() function then if it does execute i.e sends i wou

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash