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

Is there a quick way to do this?
Hi all,

I need to create a mysql table from php that goes a little something like this

Paypal
Hi all,

I have an advanced basic knowledge of php

I want to try something new for a s

help with calculations on a flat text file
hello,
I have this code below that is attached to a flat file like this:
Email:LastName:FirstN

Using real time in php
I'm very average at PHP and im looking to introduce time to something on my site.
Its a sports si

quick question about System Change Number(SCN) in FlashBack Query topic
i know tht we can get the SCN of the database using flashback concept as follows

SQL>

Files in current folder. Should be an easy fix.
Never mind. I've asked about this before and just found my answer. Anyway to delete this?

SQL Injection
In my attempts to protect my database from mySQL injection I have created another problem for myself

Need help PLEASE
ok i have this warning showing up

Warning: in_array() [function.in-array]: Wrong datatype for

How to replace search button with link?
hi to everbody.
i have a search submit form and button like this :

<form id="f

update post issues
I am trying to create an update to a post function, while the update does occur, the page routing an

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