hr8886 Posted December 13, 2009 Share Posted December 13, 2009 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 More sharing options...
trq Posted December 14, 2009 Share Posted December 14, 2009 Have you tried actually debugging your queries? Simply coming here and stating something doesn't work is useless. Link to comment https://forums.phpfreaks.com/topic/185001-why-isnt-this-php-code-working/#findComment-976704 Share on other sites More sharing options...
Buddski Posted December 14, 2009 Share Posted December 14, 2009 have a look closely at $rows=mysql_numrows($s) perhaps mysql_num_rows is what your looking for.. Link to comment https://forums.phpfreaks.com/topic/185001-why-isnt-this-php-code-working/#findComment-976708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.