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();
?>

139 Like 35 Dislike
Previous php-forum Next php-forum
Other php-forum

Mastering Regular Expressions, Third Edition, is available.
The Third Edition of Mastering Regular Expressions is available.

QuoteThis third edition is 5

Read from forum
Haven't written anything forever and I would like to get back.
What I'm trying to do is getting t

Last character removed
I have created a string from an array. I have inserted commas from my form values. I am trying to re

Question about GD library
I am trying to make an image that shows a random quote from my database.


However I want t

Searching keywords from array
Hello everyone, Im just wondering if someone could help me with another issue im having. Im still le

How to set pass login name from htaccess to php
When the user logs into my members page via htaccess, I'd like to retain the username so that I can

help with this code please?
Hello,

I am trying to build a remote upload script for my image hosting site.

I am usi

PHP Thumbnail Creation
Ok so i use this function to create thumbnails:

Code: [Select]function createthumb($name,$fil

How to show more than 1 users with this code...
Hello,
i have a table that shows users only if I, as Administrator, want to be shown. But its sho

values not being entered into table
hi. I;ve created a form, so that when a user enters data into it, it gets added to a table in a data

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