CodeLobster IDE

Free cross-platform PHP IDE (HTML, PHP, CSS, JavaScript, Python code editor) with support Drupal, Joomla, Twig, JQuery, BackboneJS, LaravelJS, Node.js, CodeIgniter, CakePHP, Laravel, Magento, MeteorJS, Phalcon, Symfony, VueJS, WordPress, Yii
It is currently Thu Mar 28, 2024 9:39 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How would I search for a record in a database?
PostPosted: Thu Nov 10, 2016 4:23 am 
Offline

Joined: Thu Aug 18, 2016 7:34 am
Posts: 3
Hello.

Could anyone please advise me to where I'm going wrong, as I've been working on this problem for the last few weeks, and can't work out where I'm going wrong.
I'm trying to create an edit page, where by I search for an entry (either by email or username) in the database, then display the results.
I'm able to display results, however I can't search the database.

The problem I've got is, that the entry I want to locate is 2nd entry in the database table, but It will only display the results of the last entry in the database table only.
Could anyone please take a brief look, and let me know where I'm going wrong, and how to get it to work? [I've included all fields as I've not decided on what to keep]


<?php
$search_function = $_POST["searchbox"]; // Get username or email from pervious php file.

$db_host = "localhost"; // $db_host
$db_user = "myusername"; // $db_user
$db_pass = "mypassword"; // $db_pass
$db_databasename = "mydatabase"; // $db_databasename

$conn = new mysqli($db_host, $db_user, $db_pass, $db_databasename);
if(! $conn)
{
die('Connection Failed'.mysql_error());
}
$sql = "SELECT Member_id, Fullname, Username, Email, Password, Location, Country, DOB, Gender, Relationship, Photo, Tzone, WebsiteURL, MembershipType, AccountStatus, BusinessAddress, SignupDate, LastVisitDate, is_online, AccountPrivacy, UserContactPrivacy, AutoRenewPass, AutoRenewDate, IP_Address, AccountClosedDate, AccountDeleteDate, Remarks FROM phpbear_registration";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
if ( $row["Username"] == $search_function or $row["Email"] == $search_function ) {
$user_accountname = $row["Fullname"];
$user_username = $row["Username"];
$user_email = $row["Email"];
$user_password = $row["Password"];
$user_location = $row["Location"];
$user_country = $row["Country"];
$user_dob = $row["DOB"];
$user_gender = $row["Gender"];
$user_relationship = $row["Relationship"];
$user_photo = $row["Photo"];
$user_tzone = $row["Tzone"];
$user_websiteurl = $row["WebsiteURL"];
$user_membershiptype = $row["MembershipType"];
$user_accountstatus = $row["AccountStatus"];
$user_businessaddress = $row["BusinessAddress"];
$user_signupdate = $row["SignupDate"];
$user_lastvisitDate = $row["LastVisitDate"];
$user_isonline = $row["is_online"];
$user_privacy = $row["AccountPrivacy"];
$user_contact_privacy = $row["UserContactPrivacy"];
$user_autorenewpassword = $row["AutoRenewPass"];
$user_autorenewpassworddate = $row["AutoRenewDate"];
$conn->close();
}
}
}
$conn->close();
?>

Thank you very much.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 42 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2016 phpBB Group