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
Help with Hyperlink
Hi,
What I am trying to do may be simple, I just can't get it to work. Ok...
I am usin
Allowing ' and "
Hello everyone,
I am creating a form where users submit information to go into a database. I
Problem with passing variables
I'm not really a php programmer so I'm really struggling with this issue.
I have a banner s
Simple Variable Question
Hi everyone.... again,
I am really getting into php still. Learning more every day. I love it
upload image name with extension using php
hi frds..
<input id="file1" type="file" name="file[]" &a
that old Malformed Headers problem again!!!!! HELP!!!!!!
I've read the http://www.phpfreaks.com/forums/index.php/topic,37442.0.html
I don't think my c
Variable passed to each() is not an array or object
Hi,
This is a email a friend type of form, and it isn't working anymore.
<?
Final year project, please point me in the right direction
hi there for my final year project I'm aiming to build a php script shell to use as an expert system
Why is my row count 0?
Here's the MySQL query i'm running. It basically pulls data from 2 tables based on some data passed.
Guixt issue
Hello all,
We are experiencing the following problem with Guixt:
Some transact