Jump to content

Recommended Posts

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<br>Your date of birth is ".$b;

}

 

else

{

print "$x<br>Your name is not listed";

}

 

  mysql_query("DROP DATABASE myDatabase") or die(mysql_error());    

  mysql_close();                      

?>

Link to comment
https://forums.phpfreaks.com/topic/185001-why-isnt-this-php-code-working/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.