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

Did you know?Explore Trending and Topic pages for more stories like this.
$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

Rss feed question
Hi

My blog and my website are different. Am i able to take my rss feed
from my blog and p

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 form help
Hey,

I use a control file to set my meta tags and titles

Here's an example
Code: &a

whats wrong with my code please help!!!
this is the error


Warning: mysql_close(): supplied argument is not a valid MySQL-Link res

whats wrong with my code please help!!!
this is the error


Warning: mysql_close(): supplied argument is not a valid MySQL-Link res

PHP code for a proxy
I was wondering which function I could use to create an online proxy tool. I was thinking cURL would

Need help with basic sql
Hi,

I am using oracle 10g, and having some small doubts related to sql , here goes the si

Login Functionality Working Different on IE
This is an odd one, I have a site which has an admin section. The admin pages unsurprisingly require

jquery validation in codeIgniter
hai i need to add client side validation to my fiels which are selected in a forloop.the fields are

Cron Job and Output
I have php codes running under a cron job.
But everytime i output (echo) , it comes out as comple

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