Jump to content

Recommended Posts

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 time
steven
Link to comment
https://forums.phpfreaks.com/topic/5499-searching-using-php-and-mysql-newbie/
Share on other sites

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]
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
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.Doe
Mr. John Doe
Mr.John.Doe
.
.
.

?
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.