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

Creating XML with php
I need to creat an XML with php and have successfully produced a valid output.
The problem I hav

Email Form Syntax Issue
I need the TO: in email to display To: CEO instead of To: abc@mail.com

How to alter the scri

how do I show what a user have selected from a checkbox?
From my code below, how would i show which check boxes have been checked and which radio buttons sel

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

Warning: session_start() [function.session-start]: Cann.....
hi, can someone help me with this? I keep getting this error....

Warning: session_start() [fu

multipart emiail forms
Hi All,

I am new to the boards and I've been working on a form (which is rather massive, imo

Code working in IE but not FireFox
I created a dynamic navigation list for my website based off of a table in my database. The code is

My query is being run with no results.
I have this.

Code: function DropUser($duser_id, $user_email, $user_username) {

generating all possible random letters
hi'

how can i randomize the letters a,b,c,d,e all possible ways, and i want to print the res

Problem with HTTP Caching...?
Hi there, im trying to implement caching. But it doesn't always work.
I post it here because ther

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