
WebGuyRI
Members-
Posts
17 -
Joined
-
Last visited
Never
Everything posted by WebGuyRI
-
Great help and thanks for being patient, worked fine.
-
Using new code picked up here from a previous problem I was having. This code is really working fine and gives me what I need. The issue is I need to limit the number of rows returned. Thanks in advance $query = "SELECT CONCAT('',name,name2,name3,name4,name5,name6,name7,name8,name9,name10) as n FROM $usertable HAVING n LIKE '%$name%'"; $result = mysql_query($query) or DIE("Could not Execute Query on table $usertable"); if ($result) { print "Query successful on table $usertable<br><br>"; print "Your Query returned:<br>"; while ($row = mysql_fetch_array($result)) { print $row['n'] . "<br/>";
-
The text I wanted to put in is not a problem. I will add it to the database. Thanks again
-
Thank you very much that print code worked great. One small issue with that code is will I be able to add text in between the results? with the old code for one field I was putting text like Volume Number . Death etc. Also if I can not add text this at lease is a major step forward. Thanks again this is a great site for help.
-
Tried it and got this Your Query returned: , , , , ,, , , , , , , , ,, , , , , , , , ,, , , , , , , , ,, , , , , , , , ,, , , , Thanks for jumping in.. Would it help if I post the link to see the results and is this allowed?
-
Sorry for the delay but tried so many versions did not remember what actually happened. I used this code $name = mysql_real_escape_string($_POST['name']); $query = "SELECT * FROM $usertable WHERE name='$name'"; (this works for the first field) Tried this $query = "SELECT * FROM $usertable WHERE name='$name' OR name2='$name'"; which gave me a blank screen $result = mysql_query($query) or DIE("Could not Execute Query on table $usertable"); if ($result) { print "Query successful on table $usertable<br><br>"; print "Your Query returned:<br>"; while ($row = mysql_fetch_array($result)) { print $row['name'].", ".$row['name2'].", ".$row['name3'].", ".$row['name4'].", ".$row['name5'].",".$row['name6'].", ".$row['name7'].", ".$row['name8'].", ".$row['name9'].", ".$row['name10']."<br>"; } Very sorry but not really up on PHP Mysql but like it. Thanks for your patience.
-
Tried the new code and variations of it but still nothing. I get the data line with the search name in the first place but it is not finding the name in the list of names.
-
Thanks for the reply will give it a try. As for why I have the names all those fields. This is a database of Cemetery headstones and the names are on the headstones. Which is why they are in different places on each line. The persons who created the database put it the way they found it on the stones. Looking at about 55,000 lines of info. Will let yo know after I try..thanks
-
Newbee making progress but really stuck on this. Looked all over and could not get anything to work. The database contains a list of names and a little info, each name could be in any one of 6 fields. Looking to have the user type one name in the query and it would give them the full line of info no mater which field the name is in. Now when the person types the search name it only returns the line that has that name in the first place. Have tried a number of combinations using name1 name2 etc but can not get it working. $yourfield = "name"; $name = "name"; if ($_POST['name'] == "" ) { echo 'There was an error in the data you submitted. Please go back and fill in all the required fields.'; die(); } mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname"); " Connected to MySQL server<br>"; $selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname"); print "Connected to database $dbname<br>"; $name = mysql_real_escape_string($_POST['name']); $query = "SELECT * FROM $usertable WHERE name='$name'"; $result = mysql_query($query) or DIE("Could not Execute Query on table $usertable"); if ($result) { print "Query successful on table $usertable<br><br>"; print "Your Query returned:<br>"; while ($row = mysql_fetch_array($result)) { print $row['name'].", ".$row['name2'].", ".$row['name3'].", ".$row['name4'].", ".$row['name5'].",".$row['name6'].", ".$row['Misc'].", ".$row['volumn'].", ".$row['city'].", ".$row['state']."<br>"; } } mysql_close; ?> Any help would be appreciated Thanks
-
Added this and it resolved mu problem if ($_POST['maiden'] == "" ) { echo 'There was an error in the data you submitted. Please go back and fill in all the required fields.'; die(); }
-
Thanks for the reply. The code worked for one search box but not the other. Looking for 2 different items "Name" and "Maiden"from one form but not at the same time. I am going to 2 different database screens. One database screen for the name and a second database screen if its maiden Added the code suggested but not sure I have it right. Now I am getting the error message with the first query displaying on the "Name" database screen. The second query box "maiden" gives me the error message with each database listing of the return. So when the person is looking for "name" and the box is blank it displays one line of the error code. If the person is looking for "maiden" then it displays the error code with each listing of the database. This is the database page for Maiden $yourfield = "name"; $yourfield2 = "given"; $maiden = "maiden"; ini_set ("display_errors", "1"); error_reporting(E_ALL); mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname"); " Connected to MySQL server<br>"; $selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname"); print "Connected to database $dbname<br>"; $maiden = mysql_real_escape_string($_POST['maiden']); $query = "SELECT * FROM $usertable WHERE maiden='$maiden'"; $result = mysql_query($query) or DIE("Could not Execute Query on table $usertable"); if ($result) { print "Query successful on table $usertable<br><br>"; print "Your Query returned:<br>"; while ($row = mysql_fetch_array($result)) { print $row['name'].", ".$row['f_name'].", (Maiden Name) ".$row['maiden'].", (Birth) ".$row['birth_d']."-".$row['birth_m']."-".$row['birth_y'].", (Death) ".$row['d_day']."-".$row['d_month']."-".$row['d_year'].",".$row['d_loc'].", (Age) ".$row['age'].", (Relationship) ".$row['r_ship'].", (Cemetery) ".$row['cemetery'].", ".$row['town'].", ".$row['state'].", (Section) ".$row['c_section'].", (Lot) ".$row['c_lot'].", (Military) ".$row['war'].", (Relationship) ".$row['relation'].", (Misc) ".$row['misc']."<br>"; } } mysql_close; ?> Thanks
-
Newbee question Please help I have a number of forms and if the person does not put anything in the search box I need to have it stay on that screen and not go to the database. Currently its dumping the database. Thanks in advance Bill <form action="data_blackstone.php" method="post"> <center> <font size="4" face="Arial, Helvetica, sans-serif">Surname:</font> <input type="text" name="name"/> <input type="Submit"/> </center> </form>
-
Newbee question, tried looking on line and here but nothing was clear. On the hosting site the file import says, max: 2,048 KB, is this the max table size or just max import? Could I add more to the table by importing more or do I create more tables? Thanks in advance Bill
-
[SOLVED] Passing variable to SQL query and getting full database
WebGuyRI replied to WebGuyRI's topic in PHP Coding Help
Your are all great thanks for all the help, it works. Take Care Bill -
[SOLVED] Passing variable to SQL query and getting full database
WebGuyRI replied to WebGuyRI's topic in PHP Coding Help
Hi Larry, Thanks for the feedback. You are correct in you comment as I am trying to only get out of the database only the names that match my search string. Made the changes you mentioned one at a time and the first one displayed as before and when I added this $query = "SELECT * FROM $usertable WHERE name = '$_POST['name']'"; Received a blank screen, went back to the original query and the page displayed again but still not with the name I am trying to show. PS How do I edit my original message? Thanks -
[SOLVED] Passing variable to SQL query and getting full database
WebGuyRI replied to WebGuyRI's topic in PHP Coding Help
Modified as suggested and now the database shows this but not the info on LAJ LAJ Connected to MySQL server Connected to database Query successful on table Your Query returned: -
Newbee to mysql and php looking to extract data from a database which I setup on line. Have tried a lot of examples from tutorials and searching the web. Have been able to get it all working but one item which I am really struggling with.. I am trying to extract select data from a mysql database. Using two pages one with the form and the other with the database code. Tried both post and get from form on the form page and $_POST and $_GET on the second page. The data passes from the form page to the code page OK, as I am echoing it on the code page. The issue is the script runs on page the code and shows the full database (only six items in database for testing).but not just the one item I am searching for. Would someone please help as I know its must be a newbee item I am missing, thanks. --------------------------------------------- <?php // posting echo $_POST['name']; // Connect to database $hostname = ""; $username = ""; $password = ""; $dbname = ""; $usertable = "test1"; $yourfield = "name"; $yourfield2 = "Given"; $yourfield3 = "Name 2"; $yourfield4 = "Vol and Page"; mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname"); print " Connected to MySQL server<br>"; $selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname"); print "Connected to database $dbname<br>"; $query = "SELECT * FROM $usertable"; $result = mysql_query($query) or DIE("Could not Execute Query on table $usertable"); if ($result) { print "Query successful on table $usertable<br><br>"; print "Your Query returned:<br>"; while ($row = mysql_fetch_array($result)) { print "".$row{$yourfield}." ".$row{$yourfield2}." ".$row{$yourfield3}." ".$row{$yourfield4}."<br>"; } } mysql_close; ?> ---------------------------------- This is what it returns ("LAJ" was the text I put in the search box on page one) ------- LAJ Connected to MySQL server Connected to database afgs_test Query successful on table test1 Your Query returned: SHEA Ida M. BOURGEOIS 134-1 LAJ Denise H 134-2 REMILLARD Annette L LA Annette L. REMILLARD 134-3 PARENT Lionel R. 13 Bill