Jump to content

PHP Search for friends problem


chrisC

Recommended Posts

Im so confused with this PHP script now and I dont know what to do! Im learning it currently and I am not amazing at PHP

 

The problem is when I search for people who have signed up to my website i get no information

 

why is this?

 

<?php

session_start();

 

$b = $_SESSION["gatekeeper"];

 

$a = $_POST["name"];

 

$conn = mysql_connect("localhost", "ccheckley", "4aPRaJew");

mysql_select_db("ccheckley");

 

$result = mysql_query ("SELECT * FROM users WHERE name = '$a'");

 

($row = mysql_fetch_array($result));

 

{

echo " name: $row[name] <br/>";

echo " username: $row[username] <br/>";

echo " birthday: $row[birthday] <br/>";

echo " interests: $row[interests] <br/>";

echo " <a href='addfriend.php?username=$row[username]'>Make this user your friend</a>";

 

}

 

mysql_close($conn);

?>

 

 

Link to comment
Share on other sites

  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Your code inside code tags

<?php
session_start();

$b = $_SESSION["gatekeeper"];

$a = $_POST["name"];

$conn = mysql_connect("localhost", "ccheckley", "4aPRaJew");
mysql_select_db("ccheckley");

$result = mysql_query ("SELECT * FROM users WHERE name = '$a'");

($row = mysql_fetch_array($result));

{
   echo " name: $row[name] <br/>";
   echo " username: $row[username] <br/>";
   echo " birthday: $row[birthday] <br/>";
   echo " interests: $row[interests] <br/>";
   echo " <a href='addfriend.php?username=$row[username]'>Make this user your friend</a>";

}

mysql_close($conn);
?>

Any ways, use

$result = mysql_query ("SELECT * FROM users WHERE name = '$a'") or die(mysql_error());

or die(mysql_error()); will let you if and what the mysql problem is...

if you have an error you don't understand, post it back here.

Link to comment
Share on other sites

OK no error appeared?

 

<?php
session_start();

$b = $_SESSION["gatekeeper"];

$a = $_POST["name"];

$conn = mysql_connect("localhost", "", "");
mysql_select_db("");

$result = mysql_query ("SELECT * FROM users WHERE name = '$a'") or die(mysql_error());

($row = mysql_fetch_array($result));

{
   echo " name: $row[name] <br/>";
   echo " username: $row[username] <br/>";
   echo " birthday: $row[birthday] <br/>";
   echo " interests: $row[interests] <br/>";
   echo " <a href='addfriend.php?username=$row[username]'>Make this user your friend</a>";

}

mysql_close($conn);
?>

 

Link to comment
Share on other sites

your search box is <input type="text" name="name" /> ?

 

 

try this

 

<?php

session_start();

 

$b = $_SESSION["gatekeeper"];

 

$a = $_POST["name"];

 

$conn = mysql_connect("localhost", "ccheckley", "4aPRaJew");

mysql_select_db("ccheckley");

 

 

$sql  = "select * from users where name='$a'";

$temps  = $DB_site->query($sql);

if($row=$DB_site->fetch_array($temps))

 

{

$name = $row[name];

$username = $row[username];

$birthday =$row[birthday];

$interests = $row[interests];

 

 

 

echo '

name: '.$name.' <br />

username: '.$username.' <br />

birthday: '.$birthday.' <br />

interests: '.$interests.' <br />

<a href='addfriend.php?username='.$username.''>Make this user your friend</a>';

 

}

mysql_close($conn);

?>

Link to comment
Share on other sites

Ok ttried that and got an error on line 29

 

[head] <a href='addfriend.php?username='.$username.''>Make this user your friend</a>'; [/head]

 

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/CheckleyChristopher/public_html/Topherbox/search.php on line 29

 

so i got rid this line  becuase its currently not needed in the scipt

 

and then i got an error on line 33

 

[head] ?> [/head]

 

Parse error: parse error, unexpected $ in /home/CheckleyChristopher/public_html/Topherbox/search.php on line 33

 

 

Link to comment
Share on other sites

error now on line 13

 

$temps  = $DB_site->query($sql);

 

Fatal error: Call to a member function on a non-object in /home/CheckleyChristopher/public_html/Topherbox/search.php on line 13

 

Also my html is on a single page, my form (search form is on a page called home) which is linked to the search.php page

Link to comment
Share on other sites

mm that helps a bit  i hope lol your input name that is being sent to the php page is friendsearch not name

 

<?php
session_start();

$b = $_SESSION["gatekeeper"];

$a = $_POST["friendsearch"];

$conn = mysql_connect("localhost", "ccheckley", "4aPRaJew");
mysql_select_db("ccheckley");


$sql  = "select * from users where name='$a'";
$temps  = $DB_site->query($sql);
if($row=$DB_site->fetch_array($temps))

{
$name = $row[name];
$username = $row[username]; 
$birthday =$row[birthday]; 
$interests = $row[interests]; 



echo '
name: '.$name.' <br />
username: '.$username.' <br />
birthday: '.$birthday.' <br />
interests: '.$interests.' <br />
<a href='addfriend.php?username='.$username.''>Make this user your friend</a>';

}
mysql_close($conn);
?>

 

 

Link to comment
Share on other sites

haha, right well i got the same error again as we had earlier

 

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/CheckleyChristopher/public_html/Topherbox/search.php on line 29

 

 

line 29 is

 

<a href='addfriend.php?username='.$username.''>Make this user your friend</a>';

Link to comment
Share on other sites

try this

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
session_start();

$b = $_SESSION["gatekeeper"];

$a = $_POST["friendsearch"];

$conn = mysql_connect("localhost", "ccheckley", "4aPRaJew");
mysql_select_db("ccheckley");


$sql  = "select * from users where name='$a'";
$temps  = $DB_site->query($sql);
if($row=$DB_site->fetch_array($temps))

{
$name = $row[name];
$username = $row[username]; 
$birthday =$row[birthday]; 
$interests = $row[interests]; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Page</title>

</head>
<body>

<?
echo '
name: '.$name.' <br />
username: '.$username.' <br />
birthday: '.$birthday.' <br />
interests: '.$interests.' <br />
<a href="addfriend.php?username='.$username.'">Make this user your friend</a>';

}
mysql_close($conn);
?>
</body>
</html>

Link to comment
Share on other sites

ok try this sorry for making this more difficult

make this file change the 3 needed items username password datbasename save it as

 

config.php

<?php

//local server
error_reporting(7);
session_start();
@header("Cache-control: private"); 

$servername="localhost";
$dbusername="databaseusername";
$dbpassword="databasepassword";
$dbname="databasename";

?>

 

make this file too just change the appname to your website name

 

save this one as connection.php

 

<?
require("config.php");
// ###################### start database connections###########################
$dbclassname="mysql.class.php";
require($dbclassname);
global $DB_site;
$DB_site=new DB_Sql_vb;
$DB_site->appname="website.com";
$DB_site->appshortname="apa";
$DB_site->database=$dbname;
$DB_site->server=$servername;
$DB_site->user=$dbusername;
$DB_site->password=$dbpassword;
$DB_site->connect();

?>

 

make a new directory on your website called secure and put the above two files in it

 

in a minute i willl post the new code for your script

Link to comment
Share on other sites

this will connect securely to your database automatically

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
session_start();

include("secure/connection.php");

$a = $_POST["friendsearch"];




$sql  = "select * from users where name='$a'";
$temps  = $DB_site->query($sql);
if($row=$DB_site->fetch_array($temps))

{
$name = $row[name];
$username = $row[username]; 
$birthday =$row[birthday]; 
$interests = $row[interests]; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Page</title>

</head>
<body>

<?
echo '
name: '.$name.' <br />
username: '.$username.' <br />
birthday: '.$birthday.' <br />
interests: '.$interests.' <br />
<a href="addfriend.php?username='.$username.'">Make this user your friend</a>';

}

?>
</body>
</html>

Link to comment
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.