gingercrock Posted March 22, 2006 Share Posted March 22, 2006 Hey guys, i am having problems while searching for members on my website.. i have a form that users fill in before being able to click on a 'search' button.. which works and the code is:[i]<form method = "POST" action="searchName.php" onSubmit="returnverifyform(this)"><br>First name: <input type ="text" name = "first"><font color = "black"></font><br>Last name: <input type = "text" name = "second"><font color="black"></font></select><input type="submit" value = "Search">[/i]it then opens 'searchName.php' which is meant to search through a database that i have created online.. the code is below:[i]<?php$connection = mysql_connect("sentinel.cs.cf.ac.uk","user_name","password");$first=$_POST['first'];$second=$_POST['second'];mysql_select_db("sjcdb",$connection) or die("failed!");echo $first;echo $last;$query = "SELECT * FROM info WHERE first='".$first."' AND last ='".$second."'";echo $query;$result = mysql_query($query, $connection);while($row = mysql_fetch_row($result)) { $title = $row[2]; $first = $row[3]; $last = $row[4]; echo "$title." ".$first." ".$last.";}mysql_close($connection);?>[/i]However, the screen simply is left blank.. any ideas where im going wrong? i am a newbie im afraid so i apologise for any schoolboy errors!!thanks for your timesteven Quote Link to comment https://forums.phpfreaks.com/topic/5499-searching-using-php-and-mysql-newbie/ Share on other sites More sharing options...
wisewood Posted March 22, 2006 Share Posted March 22, 2006 remove your server, username and password from your example of the code you use... otherwise you leave yourself wide open to attack from someone not so nice as me.Try this:[code]$query = "SELECT * FROM info WHERE first='$first' AND last ='$second'";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5499-searching-using-php-and-mysql-newbie/#findComment-19655 Share on other sites More sharing options...
gingercrock Posted March 22, 2006 Author Share Posted March 22, 2006 thanks, the first post has been edited. the new code still leaves the screen blank unfortuantly. i have entered some more code so now we have : <?php$connection = mysql_connect("sentinel.cs.cf.ac.uk","User_Name","PASSWORD");$first=$_POST['first'];$second=$_POST['second'];mysql_select_db("sjcdb",$connection) or die("failed!");echo $first;echo $last;$query = "SELECT * FROM info WHERE first='$first' AND last ='$second'";echo $query;$result = mysql_query($query, $connection);while($row = mysql_fetch_row($result)) { $title = $row[2]; $first = $row[3]; $last = $row[4]; echo $title." ".$first." ".$last.;}mysql_close($connection);?>If it helps, MySQL database has field names 'title', 'first' and 'last' and there is a field before this which is an increment 'ID'. title,first and last are in rows 1,2 and 3 respectively.. i had it working a day or two ago but tryed to changed around abit of code, got it wrong and the back up has been wiped!! so frustration is at its highest! thanks for your help, i hope this information is of some use! Steven Quote Link to comment https://forums.phpfreaks.com/topic/5499-searching-using-php-and-mysql-newbie/#findComment-19663 Share on other sites More sharing options...
snackiesmores Posted March 22, 2006 Share Posted March 22, 2006 In your first page that calls the search page i see this:[!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--][b]</select>[/b]<input type="submit" value = "Search">[!--colorc--][/span][!--/colorc--]I'm still learning PHP myself, but what is that [b]</select>[/b] tag for?Also, you changed[!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--][b]echo "$title." ".$first." ".$last.";[/b][!--colorc--][/span][!--/colorc--]to[!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--][b]echo $title." ".$first." ".$last.;[/b][!--colorc--][/span][!--/colorc--]What is the intended style of this statement?Mr. John.DoeMr. John DoeMr.John.Doe...? Quote Link to comment https://forums.phpfreaks.com/topic/5499-searching-using-php-and-mysql-newbie/#findComment-19682 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.