chrisC Posted February 18, 2009 Share Posted February 18, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/ Share on other sites More sharing options...
Brian W Posted February 18, 2009 Share Posted February 18, 2009 Please use code tags! [ code ]Like this but without the spaces in the tags[ /code ] would be Like this but without the spaces in the tags Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765244 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 :S already confused, sorry for my pure basic knowledge Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765246 Share on other sites More sharing options...
Brian W Posted February 18, 2009 Share Posted February 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765250 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765258 Share on other sites More sharing options...
shadiadiph Posted February 18, 2009 Share Posted February 18, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765263 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765269 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 any thoughts on why this is? sorry Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765275 Share on other sites More sharing options...
shadiadiph Posted February 18, 2009 Share Posted February 18, 2009 try this sorry not sure if it is right <a href="addfriend.php?username='.$username.'">Make this user your friend</a>'; are you using any html on this page? Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765282 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765284 Share on other sites More sharing options...
shadiadiph Posted February 18, 2009 Share Posted February 18, 2009 whats the input field for your search code? Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765289 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 <form action="search.php" method="post"> <br /> Enter Search:<br /> <input name="friendsearch" type=""text" size="40"/> <br /> <input type="submit" name="submit" value="search"/> </form> Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765293 Share on other sites More sharing options...
shadiadiph Posted February 18, 2009 Share Posted February 18, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765298 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765301 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 ok i changed it to this becuase i though i had to make sure that i highlight whats php and whats html but still the same error <a href='addfriend.php?username=<?php'.$username.'?>'>Make this user your friend</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765310 Share on other sites More sharing options...
shadiadiph Posted February 18, 2009 Share Posted February 18, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765315 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 sorry about this lol ... im being a right issue line 6 and 15 now have errors line 6 $b = $_SESSION["gatekeeper"]; and line 15 $temps = $DB_site->query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765320 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 Notice: Undefined index: gatekeeper in /home/CheckleyChristopher/public_html/Topherbox/search.php on line 6 Fatal error: Call to a member function on a non-object in /home/CheckleyChristopher/public_html/Topherbox/search.php on line 15 Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765323 Share on other sites More sharing options...
shadiadiph Posted February 18, 2009 Share Posted February 18, 2009 try removing $b = $_SESSION["gatekeeper"]; i don't see it is being asked for on this page then go from your search page to this page I only say this because the script i posted i removed gatekeeper bit and tried it with one of my databases and it worked fine Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765327 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 when removed i only get 1 error Fatal error: Call to a member function on a non-object in /home/CheckleyChristopher/public_html/Topherbox/search.php on line 13 $temps = $DB_site->query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765330 Share on other sites More sharing options...
shadiadiph Posted February 18, 2009 Share Posted February 18, 2009 in your database table you do have a row that is called name?? the one where the names are stored ist not called username or something like that is it? Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765333 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 yep inside my database I have row called name Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765338 Share on other sites More sharing options...
shadiadiph Posted February 18, 2009 Share Posted February 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765348 Share on other sites More sharing options...
shadiadiph Posted February 18, 2009 Share Posted February 18, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765352 Share on other sites More sharing options...
chrisC Posted February 18, 2009 Author Share Posted February 18, 2009 im lost on the second part Quote Link to comment https://forums.phpfreaks.com/topic/145756-php-search-for-friends-problem/#findComment-765354 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.