PHP - Why Echoing Row Data From Mysql Tbls Fail ?
Php Folks, Below is a membership php script I am building. config.php functions_list.php eror_reporting.php site_details.php conn.php login_check.php account_header.php login_v1.php sessions.php home_v1.php
Now, when you login, you are taken to home_v1.php that displays your details from tbls: users, personal_details, home_contact_details, business_contact_details. Problem is last 2 tables' data do not show-up on the homepage. Get no mysql error either! What a nuisancical mystery! Been going round in circles for nearly a wk now! I give-up! Only bothering you guys as a last resort! What do you reckon the problem is ? Maybe a bug perhaps with php ? The concerned tables do have data! See for yourselves. The 2 tbls data is below as attachment is failing to upload. Do not want to be burdening you guys with all files and so only provided relevant ones for you to easily check in your wamp/xamp.
test.sql -- phpMyAdmin SQL Dump -- version 4.8.3 -- https://www.phpmyadmin.net/ -- -- Host: 127.0.0.1 -- Generation Time: Nov 20, 2018 at 08:38 PM -- Server version: 10.1.36-MariaDB -- PHP Version: 7.2.11 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `test` -- -- -------------------------------------------------------- -- -- Table structure for table `business_contact_details` -- CREATE TABLE `business_contact_details` ( `id` int(11) NOT NULL, `username` varchar(255) NOT NULL, `date_&_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `business_blog` varchar(255) NOT NULL, `business_name` varchar(50) NOT NULL, `business_email` varchar(50) NOT NULL, `business_mobile` int(50) DEFAULT NULL, `business_land_line_phone` int(50) DEFAULT NULL, `business_fax` int(50) DEFAULT NULL, `business_zip` varchar(50) NOT NULL, `business_town` varchar(50) DEFAULT NULL, `business_neighbourhood` varchar(50) DEFAULT NULL, `business_borough` varchar(50) DEFAULT NULL, `business_city` varchar(50) DEFAULT NULL, `business_county` varchar(50) DEFAULT NULL, `business_district` varchar(50) DEFAULT NULL, `business_region` varchar(50) DEFAULT NULL, `business_state` varchar(50) DEFAULT NULL, `business_country` varchar(50) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `business_contact_details` -- INSERT INTO `business_contact_details` (`id`, `username`, `date_&_time`, `business_blog`, `business_name`, `business_email`, `business_mobile`, `business_land_line_phone`, `business_fax`, `business_zip`, `business_town`, `business_neighbourhood`, `business_borough`, `business_city`, `business_county`, `business_district`, `business_region`, `business_state`, `business_country`) VALUES (1, 'admin123', '2018-11-20 19:16:40', 'blogs.yahoo.com', 'loudwoman', 'loudwoman@gmail.com', 1789504580, 286980665, 286980665, 'nq1', 'Surrey', 'Surrey', 'Surrey', 'Surrey', 'Surrey', 'Surrey', 'Surrey', 'England', 'UK'), (3, 'spaceman', '2018-11-20 19:16:40', 'spaceman.gmail.com', 'spacey', 'spaceman@gmail.com', 234567, 12345667, 4353555, 'fv5', 'redmond', 'redmond', 'redmond', 'newland', 'newland', 'newland', 'newland', 'Uttah', 'USA'); -- -------------------------------------------------------- -- -- Table structure for table `home_contact_details` -- CREATE TABLE `home_contact_details` ( `id` int(11) NOT NULL, `username` varchar(255) NOT NULL, `date_&_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `personal_blog` varchar(255) DEFAULT NULL, `personal_email` varchar(50) NOT NULL, `personal_mobile` int(50) DEFAULT NULL, `home_land_line_phone` int(50) DEFAULT NULL, `home_fax` int(11) DEFAULT NULL, `home_zip` varchar(50) DEFAULT NULL, `home_town` varchar(50) DEFAULT NULL, `home_neighbourhood` varchar(50) DEFAULT NULL, `home_borough` varchar(50) DEFAULT NULL, `home_city` varchar(50) DEFAULT NULL, `home_county` varchar(50) DEFAULT NULL, `home_district` varchar(50) DEFAULT NULL, `home_region` varchar(50) DEFAULT NULL, `home_state` varchar(50) DEFAULT NULL, `home_country` varchar(50) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `home_contact_details` -- INSERT INTO `home_contact_details` (`id`, `username`, `date_&_time`, `personal_blog`, `personal_email`, `personal_mobile`, `home_land_line_phone`, `home_fax`, `home_zip`, `home_town`, `home_neighbourhood`, `home_borough`, `home_city`, `home_county`, `home_district`, `home_region`, `home_state`, `home_country`) VALUES (1, 'admin123', '2018-11-20 19:13:23', 'blogs.yahoo.com', 'santa_clause@gmail.com', 123456, 123456, 123456, 'Wc1', 'Birmingham', NULL, 'Birmingham', 'Birmingham', 'Birmingham', NULL, 'Birmingham', 'Carolina', 'United States'), (3, 'wonderwoman', '2018-11-20 19:13:23', 'blogs.gmail.com', 'wonderwoman@gmail.com', 0, NULL, 0, NULL, 'California', NULL, 'California', 'California', 'California', NULL, 'California', 'N/A', 'USA'); -- -------------------------------------------------------- -- -- Table structure for table `users` -- CREATE TABLE `users` ( `id` int(11) NOT NULL, `date_&_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `account_activation_code` varchar(255) NOT NULL, `account_activation_status` int(2) NOT NULL, `id_video_verification_status` int(2) NOT NULL, `id_verification_video_file_url` varchar(255) DEFAULT NULL, `username` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, `primary_domain` varchar(255) NOT NULL, `primary_website_email` varchar(255) NOT NULL, `sponsor_username` varchar(255) NOT NULL, `recruits_number` int(10) NOT NULL, `registering_country` varchar(255) NOT NULL, `registering_ip` varchar(255) DEFAULT NULL, `registering_browser` varchar(255) DEFAULT NULL, `registering_os` varchar(255) DEFAULT NULL, `registering_isp` varchar(255) DEFAULT NULL, `age_range` varchar(5) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `users` -- INSERT INTO `users` (`id`, `date_&_time`, `account_activation_code`, `account_activation_status`, `id_video_verification_status`, `id_verification_video_file_url`, `username`, `password`, `primary_domain`, `primary_website_email`, `sponsor_username`, `recruits_number`, `registering_country`, `registering_ip`, `registering_browser`, `registering_os`, `registering_isp`, `age_range`) VALUES (0, '2018-11-20 19:22:36', '0300bf1542f6e6261f606542c2320bbb9efaf359', 1, 1, NULL, 'admin123', '$2y$10$tM9gMGQ6Z6wNxJ/t8neIKOtQcRk1WwQIEBqxo55SgUwv710nfj0m2', 'gmail.com', 'admin@gmail.com', 'admin123', 1, '', NULL, NULL, '', '', ''), (1, '2018-11-20 19:21:34', '1300bf1542f6e6261f606542c2320bbb9efaf360', 1, 1, NULL, 'admin1234', '$2y$10$tM9gMGQ6Z6wNxJ/t8neIKOtQcRk1WwQIEBqxo55SgUwv710nfj0m2', 'yahooinvader.co.uk', 'gobot@yahoo.co.uk', 'wonderman', 0, 'USA', NULL, NULL, '', '', '41-50'), (7, '2018-11-20 19:21:35', 'b06d8f2dbdc9c99e032fdffb44a3e7e49766c267', 0, 0, NULL, 'loudmouth', '$2y$10$MIcXW3Vx6HHSEzr.bsNN.eL336VT32un6RhiIFfVhDB8BfGJrT2vu', 'fnulll.com', 'admin1234@fnulll.com', 'admin123', 1, 'Germany', NULL, NULL, '', '', '71-75'); -- -- Indexes for dumped tables -- -- -- Indexes for table `business_contact_details` -- ALTER TABLE `business_contact_details` ADD PRIMARY KEY (`id`); -- -- Indexes for table `home_contact_details` -- ALTER TABLE `home_contact_details` ADD PRIMARY KEY (`id`); -- -- Indexes for table `users` -- ALTER TABLE `users` ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `usernames` (`username`), ADD UNIQUE KEY `emails` (`primary_website_email`), ADD UNIQUE KEY `primary_website_domain` (`primary_domain`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `business_contact_details` -- ALTER TABLE `business_contact_details` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; -- -- AUTO_INCREMENT for table `home_contact_details` -- ALTER TABLE `home_contact_details` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; -- -- AUTO_INCREMENT for table `users` -- ALTER TABLE `users` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8; COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 1. config.php <?php //Include both FUNCTIONS and PHP Files. //Required PHP Files. include 'error_reporting.php'; include 'site_details.php'; include 'conn.php'; //Required FUNCTIONS Files. include 'functions_list.php'; ?>
2. functions_list.php <?php //All FUNCTIONS List File. include 'login_check.php'; ?>
3. error_reporting.php <?php //ERROR REPORTING CODES. declare(strict_types=1); ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); ?>
4. site_details.php <?php $site_name = "Idea Experimenter"; $social_network_name = "Idea Experimenter"; $site_domain = "test.com"; $social_network_domain = "test.com"; $site_admin_username = "admin123"; $site_admin_email = "admin@test.com"; $social_network_admin_username = "admin123"; $social_network_admin_email = "admin@test.com"; $server_time = "California,USA"; ?>
5. conn.php <?php //Connect to Mysql Database in this input format: "Server", "MySql User", "Mysql User Password", "MySql Database Name". $conn = mysqli_connect("localhost","root","","test"); if (!$conn) { //Error Message to show user in technical/development mode to see errors. die("Database Error : " . mysqli_error($conn)); //Error Message to show User in Layman's mode to see errors. die("Database error."); exit(); } ?>
6. login_check.php <?php //login_check() FUNCTION File. /* Check if User is logged-in or not by checking if the session names "user" is set (isset) or not. Return "TRUE" if it is; Else "FALSE". */ //Have to initiate the "session_start" global variable, regardless of whether User is logged-in or not, in order to deal with session stuffs in php. /* Replacing following chunk: if(!session_start()) { session_start(); } */ //Replacing to this instead: if( session_status() != PHP_SESSION_ACTIVE ) session_start(); //Function for checking if User is logged-in or not. function login_check() { if(isset($_SESSION["user"]) && !empty($_SESSION["user"])) { //If Session "user" is set and not empty then return TRUE. return TRUE; } else { //If Session "User" is NOT set or if session is empty then return FALSE. return FALSE; } } ?>
7. account_header.php <?php //Check if User is already logged-in or not. Get the login_check() FUNCTION to check. if (login_check() === FALSE) { //Redirect User to Log-in Page immediately. //header("refresh:0 url=login.php"); header("location:login_v1.php"); exit(); } else { include 'account_header_ad.php'; //Will display on all webpages inside the account. } ?>
8. login_v1.php <?php //Required PHP Files. include 'config.php'; //Do not include 'account_header.php' here or login.php would go in a redirection loop. /* //Check if User is already logged-in or not. Get the login_check() FUNCTION to check. if (login_check() === TRUE) { //Redirect User to Log-in Page immediately. //header("refresh:0; url=home.php"); header("location:home_v1.php?user=$user"); exit(); } */ if (isset($_POST["login_username_or_email_or_domain"]) && isset($_POST["login_password"])) { $login_username_or_email_or_domain = trim($_POST["login_username_or_email_or_domain"]); $login_password = $_POST["login_password"]; //Check if User inputted Username/Email exist in db. Registered or not. //Select Username or Email to check against Mysql DB if they are already registered or not. if(strpos("login_username_or_email_or_domain","@")) { $querying_column = "website_email"; } elseif(strpos("login_username_or_email_or_domain",".")) { $querying_column = "domain"; } else { $querying_column = "username"; } //Make sure the users table has atleast these 3 columns: username,primary_domain and website_email due to the $querying_column variable which could hold any of these 3 values. $query_1 = "SELECT id,recruits_number,sponsor_username,account_activation_status,id_video_verification_status,id_verification_video_file_url,username,password,primary_domain,primary_website_email,registering_country,registering_ip,registering_browser,registering_os,registering_isp,age_range FROM users WHERE $querying_column = ?"; $stmt_1 = mysqli_prepare($conn,$query_1); mysqli_stmt_bind_param($stmt_1,'s',$login_username_or_email_or_domain); mysqli_stmt_execute($stmt_1); $result_1 = mysqli_stmt_bind_result($stmt_1,$db_id,$db_recruits_number,$db_sponsor_username,$db_account_activation_status,$db_id_video_verification_status,$db_id_verification_video_file_url,$db_username,$db_password,$db_primary_domain,$db_website_email,$db_registering_country,$registering_ip,$registering_browser,$registering_os,$registering_isp,$db_age_range); mysqli_stmt_fetch($stmt_1); mysqli_stmt_close($stmt_1); //Free Result_1 Set mysqli_stmt_free_result($stmt_1); $query_2 = "SELECT title,first_name,middle_name,surname,gender,date_of_birth,skin_complexion,height,weight,sexual_orientation,religion,education,profession,marital_status,working_status,country_of_birth,bio FROM personal_details WHERE id = ?"; $stmt_2 = mysqli_prepare($conn,$query_2); mysqli_stmt_bind_param($stmt_2,'s',$db_id); mysqli_stmt_execute($stmt_2); $result_1 = mysqli_stmt_bind_result($stmt_2,$db_title,$db_first_name,$db_middle_name,$db_surname,$db_gender,$db_date_of_birth,$db_skin_complexion,$db_height,$db_weight,$db_sexual_orientation,$db_religion,$db_education,$db_profession,$db_marital_status,$db_working_status,$db_country_of_birth,$db_bio); mysqli_stmt_fetch($stmt_2); mysqli_stmt_close($stmt_2); //Free Result_2 Set mysqli_stmt_free_result($stmt_2); $query_3 = "SELECT personal_blog,personal_email,personal_mobile,home_land_line_phone,home_fax,home_zip,home_town,home_neighbourhood,home_borough,home_city,home_district,home_county,home_region,home_state,home_country FROM home_contact_details WHERE id = ?"; $stmt_3 = mysqli_prepare($conn,$query_3); mysqli_stmt_bind_param($stmt_3,'s',$db_id); mysqli_stmt_execute($stmt_3); $result_3 = mysqli_stmt_bind_result($stmt_3,$db_persona_blog,$db_personal_email,$db_personal_mobile,$db_home_land_line_phone,$db_home_fax,$db_home_zip,$db_home_town,$db_home_neighbourhood,$db_home_borough,$db_home_city,$db_home_district,$db_home_county,$db_home_region,$db_home_state,$db_home_country); mysqli_stmt_fetch($stmt_3); mysqli_stmt_close($stmt_3); //Free Result_3 Set //mysqli_stmt_free_result($stmt_3); $query_4 = "SELECT business_blog,business_name,business_email,business_mobile,business_land_line_phone,business_fax,business_zip,business_town,business_neighbourhood,business_borough,business_city,business_district,business_county,business_region,business_state,business_country FROM business_contact_details WHERE id = ?"; $stmt_4 = mysqli_prepare($conn,$query_4); mysqli_stmt_bind_param($stmt_4,'s',$db_id); mysqli_stmt_execute($stmt_4); $result_3 = mysqli_stmt_bind_result($stmt_3,$db_business_blog,$db_business_name,$db_business_email,$db_business_mobile,$db_business_land_line_phone,$db_business_fax,$db_business_zip,$db_business_town,$db_business_neighbourhood,$db_business_borough,$db_business_city,$db_business_district,$db_business_county,$db_business_region,$db_business_state,$db_business_country); mysqli_stmt_fetch($stmt_4); mysqli_stmt_close($stmt_4); //Free Result_4 Set //mysqli_stmt_free_result($stmt_4); if (!password_verify($login_password,$db_password)) { echo "Incorrect log-in details3<br>"; exit(); } else { $user = $db_username; //Session Variables associated with 'users' tbl. $_SESSION["user"] = $user; $_SESSION['id'] = $db_id; $_SESSION["recruits_number"] = $db_recruits_number; $_SESSION["sponsor_username"] = $db_sponsor_username; $_SESSION["account_activation_status"] = $db_account_activation_status; $_SESSION["id_video_verification_status"] = $db_id_video_verification_status; $_SESSION["id_verification_video_file_url"] = $db_id_verification_video_file_url; $_SESSION["username"] = $db_username; $_SESSION["primary_domain"] = $db_primary_domain; $_SESSION["primary_website_email"] = $db_primary_website_email; $_SESSION["registering_country"] = $db_registering_country; $_SESSION["registering_ip"] = $db_registering_ip; $_SESSION["registering_browser"] = $db_registering_browser; $_SESSION["registering_os"] = $db_registering_os; $_SESSION["registering_isp"] = $db_registering_isp; $_SESSION["age_range"] = $db_age_range; //Session Variables associated with 'personal_details' tbl. $_SESSION["personal_details_verified_by_recruiter"] = $db_personal_details_verified_by_recruiter; $_SESSION["passport_size_photoh_image"] = $db_passport_size_photoh_image; $_SESSION["title"] = $db_title; $_SESSION["first_name"] = $db_first_name; $_SESSION["middle_name"] = $db_middle_name; $_SESSION["surname"] = $db_surname; $_SESSION["gender"] = $db_gender; $_SESSION["age_range"] = $db_age_range; $_SESSION["date_of_birth"] = $db_date_of_birth; $_SESSION["skin_complexion"] = $db_skin_complexion; $_SESSION["height"] = $db_height; $_SESSION["weight"] = $db_weight; $_SESSION["sexual_orientation"] = $db_sexual_orientation; $_SESSION["religion"] = $db_religion; $_SESSION["education"] = $db_education; $_SESSION["profession"] = $db_profession; $_SESSION["marital_status"] = $db_marital_status; $_SESSION["working_status"] = $db_working_status; $_SESSION["country_of_birth"] = $db_country_of_birth; $_SESSION["bio"] = $db_bio; //Session Variables associated with 'home_contact_details' tbl. $_SESSION["personal_blog"] = $db_personal_blog; $_SESSION["personal_email"] = $db_personal_email; $_SESSION["personal_mobile"] = $db_personal_mobile; $_SESSION["home_land_line_phone"] = $db_home_land_line_phone; $_SESSION["home_fax"] = $db_home_fax; $_SESSION["home_zip"] = $db_home_zip; $_SESSION["home_town"] = $db_home_town; $_SESSION["home_neighbourhood"] = $db_home_neighbourhood; $_SESSION["home_borough"] = $db_home_borough; $_SESSION["home_city"] = $db_home_city; $_SESSION["home_county"] = $db_home_county; $_SESSION["home_district"] = $db_home_district; $_SESSION["home_region"] = $db_home_region; $_SESSION["home_state"] = $db_home_state; $_SESSION["home_country"] = $db_home_country; //Session Variables associated with 'business_contact_details' tbl. $_SESSION["business_blog"] = $db_business_blog; $_SESSION["business_name"] = $db_business_name; $_SESSION["business_email"] = $db_business_email; $_SESSION["business_mobile"] = $db_business_mobile; $_SESSION["business_land_line_phone"] = $db_business_land_line_phone; $_SESSION["business_fax"] = $db_business_fax; $_SESSION["business_zip"] = $db_business_zip; $_SESSION["business_town"] = $db_business_town; $_SESSION["business_neighbourhood"] = $db_business_neighbourhood; $_SESSION["business_borough"] = $db_business_borough; $_SESSION["business_city"] = $db_business_city; $_SESSION["business_county"] = $db_business_county; $_SESSION["business_district"] = $db_business_district; $_SESSION["business_region"] = $db_business_region; $_SESSION["business_state"] = $db_business_state; $_SESSION["business_country"] = $db_business_country; header("location:home_v1.php?user=$user"); } } ?> <!DOCTYPE html> <html> <head> <title><?php $site_name ?> Member Login Page</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <?php /* $_GET and $_POST have two different enctype settings in the form. If we do not specify which one to use, the default is "plain/text". With $_GET you use "application/x-www-form-urlencode" and with $_POST you use "multipart/form-data". */ ?> <form name = "login_form" method = "post" action="" enctype = "multipart/form-data"> <h3><?php echo "$site_name";?> Member Login Form</h3> <fieldset> <label for="login_name">Username/Email:</label> <input type="text" name="login_username_or_email_or_domain" id="login_name" required [A-Za-z0-9] autocorrect=off value=""><br> <label for="login_pass">Password:</label> <input type="password" name="login_password" id="login_pass" required [A-Za-z0-9] autocorrect=off value=""> </fieldset> <div class="SubmitsAndHiddens"> <label for="login_remember">Remember Log-in Details:</label> <input type="checkbox" name="login_remember" id="login_remember" /> <br> <p align="left"><input type="submit" class="btn btn-default" name="submit" value="Log-in!"></p> <br> <a href="login_password_reset.php">Forgot your password ? Reset it here!</a> <br> <a href="register.php">Don't yet have an account ? Register here!</a> </div> </form> </body> </html>
9. sessions.php <?php //$_SESSION Variables associated with 'users' tbl. $user = $_SESSION["user"]; $id = $_SESSION['id']; $sponsor_username = $_SESSION["sponsor_username"]; $recruits_number = $_SESSION["recruits_number"]; $account_activation_status = $_SESSION["account_activation_status"]; $id_video_verification_status = $_SESSION["id_video_verification_status"]; $id_verification_video_file_url = $_SESSION["id_verification_video_file_url"]; $username = $_SESSION["username"]; $primary_domain = $_SESSION["primary_domain"]; $primary_website_email = $_SESSION["primary_website_email"]; $registering_country = $_SESSION["registering_country"]; $registering_ip = $_SESSION["registering_ip"]; $registering_browser = $_SESSION["registering_browser"]; $registering_os = $_SESSION["registering_os"]; $registering_isp = $_SESSION["registering_isp"]; $age_range = $_SESSION["age_range"]; //$_SESSION Variables associated with 'personal_details' tbl. $personal_details_verified_by_recruiter = $_SESSION["personal_details_verified_by_recruiter"]; $passport_size_photoh_image = $_SESSION["passport_size_photoh_image"]; $title = $_SESSION["title"]; $first_name = $_SESSION["first_name"]; $middle_name = $_SESSION["middle_name"]; $surname = $_SESSION["surname"]; $gender = $_SESSION["gender"]; $date_of_birth = $_SESSION["date_of_birth"]; $skin_complexion = $_SESSION["skin_complexion"]; $height = $_SESSION["height"]; $weight = $_SESSION["weight"]; $sexual_orientation = $_SESSION["sexual_orientation"]; $religion = $_SESSION["religion"]; $education = $_SESSION["education"]; $profession = $_SESSION["profession"]; $marital_status = $_SESSION["marital_status"]; $working_status = $_SESSION["working_status"]; $country_of_birth = $_SESSION["country_of_birth"]; $bio = $_SESSION["bio"]; //$_SESSION Variables associated with 'home_contact_details' tbl. $personal_blog = $_SESSION["personal_blog"]; $personal_email = $_SESSION["personal_email"]; $personal_mobile = $_SESSION["personal_mobile"]; $home_land_line_phone = $_SESSION["home_land_line_phone"]; $home_fax = $_SESSION["home_fax"]; $home_zip = $_SESSION["home_zip"]; $home_town = $_SESSION["home_town"]; $home_neighbourhood = $_SESSION["home_neighbourhood"]; $home_borough = $_SESSION["home_borough"]; $home_city = $_SESSION["home_city"]; $home_county = $_SESSION["home_county"]; $home_district = $_SESSION["home_district"]; $home_region = $_SESSION["home_region"]; $home_state = $_SESSION["home_state"]; $home_country = $_SESSION["home_country"]; //$_SESSION Variables associated with 'business_contact_details' tbl. $business_blog = $_SESSION["business_blog"]; $business_name = $_SESSION["business_name"]; $business_email = $_SESSION["business_email"]; $business_mobile = $_SESSION["business_mobile"]; $business_land_line_phone = $_SESSION["business_land_line_phone"]; $business_fax = $_SESSION["business_fax"]; $business_zip = $_SESSION["business_zip"]; $business_town = $_SESSION["business_town"]; $business_neighbourhood = $_SESSION["business_neighbourhood"]; $business_borough = $_SESSION["business_borough"]; $business_city = $_SESSION["business_city"]; $business_county = $_SESSION["business_county"]; $business_district = $_SESSION["business_district"]; $business_region = $_SESSION["business_region"]; $business_state = $_SESSION["business_state"]; $business_country = $_SESSION["business_country"]; ?>
10 home_v1.php <?php //Required PHP Files. include 'config.php'; //Required on all webpages of the site. include 'account_header.php'; //Required on all webpages of the account. include 'sessions.php'; ?> <!DOCTYPE html> <html> <head> <title><?php echo "$user ";?>Home Page</title> <meta charset="utf-8"> </head> <body> <body background="background.png"> <p align="right"><a href="settings.php?user=<?php echo "$user";?>">Settings</a>|<a href='logout_v1.php'>Log Out</a>|</p> <h2><p align="center"><?php echo "$user Home Page";?></p></h2> <?php //Welcome User by name. echo "Welcome $first_name $middle_name $surname";?> <br> <br> <p align = "center"><font color = "red"><b>Latest Follower</b></font><br> <iframe src="https://www.yahoo.com" width="100%" height="500px"> <p>Your browser does not support iframes.</p> </iframe> </p> <br> <br> <p align = "center"><font color = "red"><b>Latest Followee</b></font><br> <iframe src="http://google.com"> <p>Your browser does not support iframes.</p> </iframe> </p> <br> <br> <p align = "center"><font color = "red"><b>Latest Recruit</b></font><br> <iframe src="http://google.com"> <p>Your browser does not support iframes.</p> </iframe> </p> <br> <br> <p align = "center"><font color = "red"><b>Upline 1 Latest Visit</b></font><br> <iframe src="http://google.com"> <p>Your browser does not support iframes.</p> </iframe> </p> <br> <p align = "center"><font color = "red"><b>Upline 2 Latest Visit</b></font><br> <iframe src="http://google.com"> <p>Your browser does not support iframes.</p> </iframe> </p> <br> <p align = "center"><font color = "red"><b>Upline 3 Latest Visit</b></font><br> <iframe src="http://google.com"> <p>Your browser does not support iframes.</p> </iframe> </p> <br> <p align = "center"><font color = "red"><b>Upline 4 Latest Visit</b></font><br> <iframe src="http://google.com"> <p>Your browser does not support iframes.</p> </iframe> </p> <br> <p align = "center"><font color = "red"><b>Upline 5 Latest Visit</b></font><br> <iframe src="http://google.com"> <p>Your browser does not support iframes.</p> </iframe> </p> <br> <p align = "center"><font color = "red"><b>Upline 6 Latest Visit</b></font><br> <iframe src="http://google.com"> <p>Your browser does not support iframes.</p> </iframe> </p> <br> <?php //Display User Account Details echo "<h3>User: <a href=\"user.php?user=$user\">$user</a> Details</h3>";?><br> <?php //CHANGELINK $user_account_details = array("id_video_verification_status","id_verification_video_file_url","recruits_number","sponsor_username","username","primary_domain","primary_website_email","sponsor_username","recruits_number","registering_country","registering_ip","registering_browser","registering_os","registering_isp","age_range"); foreach ($user_account_details as $value) { $value_0 = str_replace("_"," ","$value"); $value_0 = ucwords("$value_0"); echo "<b>$value_0</b>: "; echo "${$value}";?><br><?php } //Display User Personal Details echo "<h3>Personal: <a href=\"user.php?user=$user\">$user</a> Details</h3>";?><br> <?php //CHANGELINK $user_personal_details = array("personal_details_verified_by_recruiter","passport_size_photoh_image","title","first_name","middle_name","surname","gender","date_of_birth","skin_complexion","height","weight","sexual_orientation","marital_status","working_status","country_of_birth","bio"); foreach ($user_personal_details as $value) { $value_0 = str_replace("_"," ","$value"); $value_0 = ucwords("$value_0"); echo "<b>$value_0</b>: "; echo "${$value}";?><br><?php } //Display User Home Contact Details from home_contact_details tbl. echo "<h3>Home <a href=\"user.php?user=$user\">$user</a> Details</h3>";?><br> <?php //CHANGELINK $user_home_contact_details = array("personal_blog","personal_email","personal_mobile","home_land_line_phone","home_fax","home_zip","home_town","home_neighbourhood","home_borough","home_city","home_county","home_district","home_region","home_state","home_country"); foreach ($user_home_contact_details as $value) { $value_0 = str_replace("_"," ","$value"); $value_0 = ucwords("$value_0"); echo "<b>$value_0</b>: "; echo "${$value}";?><br><?php //NOTWORKING } //Display User Business Contact Details from business_contact_details tbl. echo "<h3>Business: <a href=\"user.php?user=$user\">$user</a> Details</h3>";?><br><?php //CHANGELINK $user_business_contact_details = array("business_blog","business_name","business_email","business_mobile","business_land_line_phone","business_fax","business_zip","business_town","business_neighbourhood","business_borough","business_city","business_county","business_district","business_region","business_state","business_country"); foreach ($user_business_contact_details as $value) { $value_0 = str_replace("_"," ","$value"); $value_0 = ucwords("$value_0"); echo "<b>$value_0</b>: "; echo "${$value}";?><br><?php //NOTWORKING } ?> <br> <?php //Link Submitter FRame //Link Submitter iFrame Goes here ?> <br> <br> <?php include 'account_footer.php'; ?>
11. log_out_v1.php <?php session_start(); session_destroy(); echo "You have successfully logged-out of your account!"; ?> <br> <p align="left"><font color="red" size="3"><b>Want to Log-in again ? </b><a href="login_v1.php">Login here!</a></font></p> On the home_v1.php, I should be echoing the row data through htmlentities. Right ? On the comments on home_v1.php, note the "//NOT WORKING". This is where I am having trouble as data from the 2 tbls (home_contact_details, business_contact_details) are not getting grabbed and displayed. Edited November 20, 2018 by phpsaneSimilar TutorialsI have a MySQL table called "products": Quote +------+-------+-------+-------+ | id | sizes | sizem | sizel | +------+-------+-------+-------+ | 1 | 2 | 0 | 1 | | 2 | 3 | 1 | 0 | +------+-------+-------+-------+ What I am wanting to know is if I can make PHP print a value from it, but only if it is not a zero.. something like: $sizeL = (table(products)id1.sizel); if (table(products)id1.sizel == "0") {echo "";} else {echo "$sizeL";} Yeah I know the above code is far from beeing valid, but is the best I could come up with. heh Hi, Im getting this error with my script that im using to try and echo content for my website: Parse error: syntax error, unexpected T_ECHO in /home/a9855336/public_html/test.php on line 16 my php code is <?php $host="mysql12.000webhost.com"; // Host name $username="a9855336_root"; // Mysql username $password="n4th4n%"; // Mysql password $db_name="a9855336_mail"; // Database name // Connect to server and select databse. mysql_connect($host, $username, $password); mysql_select_db($db_name); $query = "SELECT title, content, FROM members where ID = 1"; $result = mysql_query($query); $row = mysql_fetch_array($result) echo $row['title']; ?> html stuff <?php echo $row['content']; ?> If anyone can help me fix this problem or sugguest a dfiferent way to go about this it would be greatly appriciated. Thanks, Blink359 Hey all! In the code in question I echo out individual records of data from MySQL successfully. For each record there is a number which is used as a var in the javascript that does the count-down-timer part. However when I view the resulting page the timer works dynamically only with the first record. With the rest, the timer is static. Code: [Select] <? $result0 = mysql_query("SELECT * FROM table WHERE field='$value'"); while ($riw0 = mysql_fetch_assoc($result0)) { $seconds1 = $riw0['seconds'] ; //// echo out data and set variable for the number of seconds to count down ?> <script language="JavaScript"> var countDownInterval=<?=$seconds1?>; var c_reloadwidth=200 </script> <ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer> <script> var countDownTime=countDownInterval+1; function countDown(){ countDownTime--; if (countDownTime <=0){ countDownTime=countDownInterval; clearTimeout(counter) window.location.href="military3.php" //Redirection URL return } var mins = Math.floor(countDownTime/60) var secs = countDownTime-(mins*60) if (document.all) //if IE 4+ document.all.countDownText.innerText = mins+" minutes "+secs+ " "; else if (document.getElementById) //else if NS6+ document.getElementById("countDownText").innerHTML=mins+" minutes "+secs+ " " else if (document.layers){ document.c_reload.document.c_reload2.document.write('Soldiers will be ready in... <span id="countDownText">'+countDownTime+' </span> seconds') document.c_reload.document.c_reload2.document.close() } counter=setTimeout("countDown()", 1000); } function startit(){ if (document.all||document.getElementById) document.write('Soldiers will be ready in <span id="countDownText">'+countDownTime+' </span> seconds') countDown() } if (document.all||document.getElementById) startit() else window.onload=startit </script> <? } ?> I tried replacing the javascript vars with PHP echoes for unique variables, but then no timer shows up, even static. So could anyone advice me on how I could use this code to apply for all MySQL records? Thanks in advance, Thauwa P.S. If I am unclear with my quandary, do let me know. Thank you. Warning: mysql_fetch_array() expects parameter 1 to be resource, string given... im tryin to put class inside code if $dayNumber and $dan are equal i tried few ways but all are complicated since i have to call some functions this end up as "simple" solution but i dont know where did i get wrong PS that should be possible? Code: [Select] else { echo "<td width='40'"; $moj_id = $_SESSION['id']; $query_event = mysql_query("SELECT * FROM events WHERE id_user='$moj_id' GROUP BY 'event_date'") ; $test = mysql_fetch_array('$query_event'); $date_event = $test['event_date']; sscanf($date_event, "%d-%d-%d", $godina, $mjesec, $dan); if ($dan==$dayNumber && $mjesec==$month && godina==$year) { echo " class='radni'"; } echo"><a href='day_info.php?dan=",$dayNumber,"&mj=",$month,"&gd=",$year,"'>" . $dayNumber . " </a></td>\n"; $dayNumber++; } i'm doing my best to research this stuff guys, but I keep getting stuck. My reporting is almost finished, but I'm stuck at the part of my code that's denoted by "//FOR EACH LOOP HERE?" Can someone help? in addition to this missing code I need, I also get the error "mysqli_num_rows() expects parameter 1 to be mysqli_resul". But all these examples on the web use pretty much the same code like this. <?php $dbHost = "localhost"; $dbName= "rptDatabase"; $dbUsername = "username"; $dbPassword = "password"; $conn = mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql = mysqli_query($conn, "SELECT * FROM tblTraffic ORDER BY ip, date, time"); $report = mysqli_fetch_array($sql); echo "<table border='1'> <tr> <th>IP ADDRESS</th> <th>PAGE VISITED</th> <th>PREVIOUS PAGE</th> <th>DATE</th> <th>TIME</th> </tr>"; if (mysqli_num_rows($report) > 0) { while($row = mysqli_fetch_array($report)) { echo "<tr>"; //FOR EACH LOOP HERE? } } else { echo "0 results"; } $conn->close(); ?> Edited October 14, 2019 by ajetrumpet Hello! I've been stuck with this for a while now. First I want to say that this is a school project and not something illegal bet site. The first MySQL table have results from games and the other table contains users bets on different games.. My problem is that I don't know how to make the two tables compare and then by that change some numbers in MySQL table. So I want the code to look if the team1 and team2 on both tables are the same. Then look if the bets (1,X or 2) are the same. If they are, change (in table "Bets") w to 1 and if now change (in table "Bets") l to w. I think my problem might be that i don't know how to make the while loop... This is my code: $tbl_name="Bets"; $tbl_name2="results"; //connect to MySQL and chose database mysql_connect("$host", "$username", "$password")or die("Connection could not be Established"); mysql_select_db("$db_name")or die("Could not select DB"); $loginusername=$_SESSION['loginusername']; $sql="SELECT * FROM $tbl_name WHERE user='$loginusername'"; $r=mysql_query($sql); $i=0; $betarray=array(array()); while($rows=mysql_fetch_array($r)) { $betarray[$i]=$rows; $i++; } foreach($betarray as $insidearray) foreach($betarray2 as $insidearray1) { while($rows=mysql_fetch_array($r)) { $team1 = $insidearray['team1']; $team2 = $insidearray['team2']; if($team1 == $insidearray1['team1'] && $team2 == $insidearray1['team2']) { $team1 = $insidearray['team1']; $team2 = $insidearray['team2']; $x12 = $insidearray['1x2real'] if($x12 == $insidearray1['1x2']) { $update="UPDATE $tbl_name SET w='1' WHERE user='$loginusername' AND team1='$team1' AND team2='$team2'"; mysql_query($update); } else { $update="UPDATE $tbl_name SET l='1' WHERE user='$loginusername' AND team1='$team1' AND team2='$team2'"; mysql_query($update); } } } } } Thanks in Advance! Hello, I am trying to get a value from a MYSQL table, and echo it. It is a shopping cart, then tells you how much you have spent. Most other scripts have done, but I'm having some trouble getting the value back. Here's the code where I need it inserted: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>RC-Chemicals - <?php echo $title ?></title> <!--css --> <link href="./css/style.css" type="text/css" rel="stylesheet" /> <link rel="stylesheet" type="text/css" href="./fancybox/jquery.fancybox-1.3.4.css" media="screen" /> <!--js --> <script type="text/javascript" src="./js/jquery.js"></script> <script type="text/javascript" src="./js/chili-1.7.pack.js"></script> <script type="text/javascript" src="./js/jquery.cycle.all.2.72.js"></script> <script type="text/javascript" src="./js/cufon-yui.js"></script> <script type="text/javascript" src="./js/sansation.js"></script> <script type="text/javascript" src="./js/carusel.js"></script> <script type="text/javascript" src="./js/script.js"></script> <script type="text/javascript" src="./js/functions.js"></script> <script type="text/javascript" src="./js/jquery.sudoSlider.js"></script> <script type="text/javascript" src="./fancybox/jquery.mousewheel-3.0.4.pack.js"></script> <script type="text/javascript" src="./fancybox/jquery.fancybox-1.3.4.pack.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon"/></head> <body> <div id="wrapper"> <div id="header"> <a href="index.php"><img src="./images/logo.png" alt="" id="logo" /></a> <div class="right_header"> <div class="cart-box"> <div class="cart-left"></div> <?php if (!isset($_SESSION['user'])) { echo "<div class=\"cart-content\"> <ul> <li><a href=\"#\">00 item</a></li> <li><a href=\"#\"><span>50.00</span></a></li> </ul> </div> <div class=\"cart-right\"></div> </div>"; } else { echo "<div class=\"cart-content\"> <ul> <li>Please login to purchase.</li> </ul> </div> <div class=\"cart-right\"></div> </div>"; } ?> <div class="account_login"> <ul> <li><a href="login.php">Login </a></li> </ul> </div> <div class="search_field"> <input type="text" value="Enter keywords to search" onfocus="if(this.value == 'Enter keywords to search') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Enter keywords to search'; }" /> <a href="#">Search</a> </div> </div> <div id="nav"> <ul> <li><a href="#">Methoxetamine</a></li> <li><a href="#" class="active">Products</a> <ul> <li>MDAI</li> <li><a href="#">Methoxetamine</a></li> <li><a href="#">Methiopropamine</a></li> <li><a href="#">NRG-3</a></li> <li><a href="#">AMT</a></li> <li><a href="#">5-APB</a></li> <li><a href="#">Benzo Fury Pellets)</a></li> </ul> </li> <li><a href="#">Contact</a></li> <li><a href="#">Forums</a></li> </div> <br class="clear" /> </div> Code: [Select] <div id="wrapper"> <div id="header"> <a href="index.php"><img src="./images/logo.png" alt="" id="logo" /></a> <div class="right_header"> <div class="cart-box"> <div class="cart-left"></div> <?php if (!isset($_SESSION['user'])) { echo "<div class=\"cart-content\"> <ul> <li><a href=\"#\">00 item</a></li> <li><a href=\"#\"><span>50.00</span></a></li> </ul> </div> <div class=\"cart-right\"></div> </div>"; } else { echo "<div class=\"cart-content\"> <ul> <li>Please login to purchase.</li> </ul> </div> <div class=\"cart-right\"></div> </div>"; } ?> Extra details: Table name: tbl_users Column name: cart WHE email='$_SESSION['user']' Thank you guys very much! I'm trying to echo multiple rows from a MySQL database with no luck. I've tried this code and many other combinations with it, but can't seem to get a result. Quote $query = "select email,mens,womens from newsletters"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) {foreach ($row as .$email. .$mens. .$womens.) {echo "$email - $mens - $womens<BR>";}} What am I doing wrong? It's pretty simple to see what I am trying to do here. For some reason all results in the table are the same exact cityName replacing all existing records. The echoed results are correct. I've include a small dump of my table as well. $query = "SELECT cityName FROM sys_city_dev_2"; $resource = mysqli_query($cxn, $query) or die("MySQL error: " . mysqli_error($cxn) . "<hr>\nQuery: $query"); while($result = mysqli_fetch_assoc($resource)) { $nox = $result['cityName']; $toUpper = ucfirst($nox); echo "$toUpper" . "<br />"; $setString = "UPDATE sys_city_dev_2 SET cityName = '" . $toUpper ."' WHERE cityName != ''"; mysqli_query($cxn,$setString); } 100 Records of table dump (pre running my script above): -- -- Table structure for table `sys_city_dev_2_backup` -- CREATE TABLE IF NOT EXISTS `sys_city_dev_2_backup` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Mid` int(11) NOT NULL DEFAULT '0', `cityName` varchar(30) NOT NULL DEFAULT '', `forder` int(4) NOT NULL DEFAULT '0', `disdplay` int(4) NOT NULL DEFAULT '0', `cid` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=113970 ; -- -- Dumping data for table `sys_city_dev_2_backup` -- INSERT INTO `sys_city_dev_2_backup` (`ID`, `Mid`, `cityName`, `forder`, `disdplay`, `cid`) VALUES (84010, 1, 'dothan', 0, 0, 0), (84011, 1, 'alabaster', 0, 0, 0), (84012, 1, 'birmingham', 0, 0, 0), (84013, 2, 'flagstaff', 0, 0, 0), (84014, 1, 'auburn', 0, 0, 0), (84015, 1, 'florence', 0, 0, 0), (84016, 1, 'gadsden', 0, 0, 0), (84017, 1, 'huntsville', 0, 0, 0), (84018, 1, 'mobile', 0, 0, 0), (84019, 1, 'montgomery', 0, 0, 0), (84020, 1, 'tuscaloosa', 0, 0, 0), (84021, 2, 'mohave valley', 0, 0, 0), (84022, 2, 'phoenix', 0, 0, 0), (84023, 2, 'prescott', 0, 0, 0), (84024, 2, 'sierra vista', 0, 0, 0), (84025, 2, 'tucson', 0, 0, 0), (84026, 2, 'yuma', 0, 0, 0), (84027, 3, 'bakersfield', 0, 0, 0), (84028, 3, 'chico', 0, 0, 0), (84029, 3, 'fresno / madera', 0, 0, 0), (84030, 3, 'gold country', 0, 0, 0), (84031, 3, 'humboldt county', 0, 0, 0), (84032, 3, 'imperial', 0, 0, 0), (84033, 3, 'inland empire', 0, 0, 0), (84034, 3, 'los angeles', 0, 0, 0), (84035, 3, 'alhambra', 0, 0, 0), (84036, 3, 'merced', 0, 0, 0), (84037, 49, 'fayetteville', 0, 0, 0), (84038, 49, 'fort smith', 0, 0, 0), (84039, 49, 'jonesboro', 0, 0, 0), (84040, 49, 'little rock', 0, 0, 0), (84041, 49, 'arkadelphia', 0, 0, 0), (84042, 49, 'texarkana', 0, 0, 0), (84043, 3, 'modesto', 0, 0, 0), (84044, 3, 'alta sierra', 0, 0, 0), (84045, 3, 'alpine', 0, 0, 0), (84046, 3, 'pedley', 0, 0, 0), (84047, 3, 'redding', 0, 0, 0), (84048, 3, 'alondra park', 0, 0, 0), (84049, 3, 'sacramento', 0, 0, 0), (84050, 4, 'canon city', 0, 0, 0), (84051, 3, 'san luis obispo', 0, 0, 0), (84052, 3, 'santa barbara', 0, 0, 0), (84053, 3, 'stockton', 0, 0, 0), (84054, 3, 'aliso viejo', 0, 0, 0), (84055, 3, 'visalia', 0, 0, 0), (84056, 3, 'yuba city', 0, 0, 0), (84057, 4, 'boulder', 0, 0, 0), (84058, 4, 'colorado springs', 0, 0, 0), (84059, 4, 'denver', 0, 0, 0), (84060, 4, 'applewood', 0, 0, 0), (84061, 4, 'pueblo', 0, 0, 0), (84062, 4, 'air force academy', 0, 0, 0), (84063, 5, 'avon', 0, 0, 0), (84064, 5, 'hartford', 0, 0, 0), (84065, 5, 'new haven', 0, 0, 0), (84066, 5, 'ansonia', 0, 0, 0), (84067, 5, 'fairfield', 0, 0, 0), (84068, 7, 'daytona beach', 0, 0, 0), (84069, 7, 'sebastian', 0, 0, 0), (84070, 5, 'wallingford center', 0, 0, 0), (84071, 8, 'belvedere park', 0, 0, 0), (84072, 7, 'sarasota springs', 0, 0, 0), (84073, 7, 'sandalfoot cove', 0, 0, 0), (84074, 7, 'san carlos park', 0, 0, 0), (84075, 7, 'st. augustine', 0, 0, 0), (84076, 7, 'tallahassee', 0, 0, 0), (84077, 7, 'safety harbor', 0, 0, 0), (84078, 7, 'ruskin', 0, 0, 0), (84079, 8, 'athens-clarke county', 0, 0, 0), (84080, 8, 'atlanta', 0, 0, 0), (84081, 8, 'augusta-richmond county', 0, 0, 0), (84082, 8, 'brunswick', 0, 0, 0), (84083, 8, 'columbus', 0, 0, 0), (84084, 8, 'americus', 0, 0, 0), (84085, 8, 'acworth', 0, 0, 0), (84086, 8, 'valdosta', 0, 0, 0), (84087, 10, 'boise', 0, 0, 0), (84088, 10, 'ammon', 0, 0, 0), (84089, 10, 'moscow', 0, 0, 0), (84090, 10, 'blackfoot', 0, 0, 0), (84091, 10, 'twin falls', 0, 0, 0), (84092, 10, 'meridian', 0, 0, 0), (84093, 10, 'jerome', 0, 0, 0), (84094, 10, 'idaho falls', 0, 0, 0), (84095, 11, 'addison', 0, 0, 0), (84096, 10, 'garden city', 0, 0, 0), (84097, 10, 'eagle', 0, 0, 0), (84098, 10, 'chubbuck', 0, 0, 0), (84099, 10, 'caldwell', 0, 0, 0), (84100, 12, 'bloomington', 0, 0, 0), (84101, 12, 'evansville', 0, 0, 0), (84102, 12, 'fort wayne', 0, 0, 0), (84103, 12, 'indianapolis', 0, 0, 0), (84104, 12, 'muncie / anderson', 0, 0, 0), (84105, 12, 'lafayette / west lafayette', 0, 0, 0), (84106, 12, 'south bend / michiana', 0, 0, 0), (84107, 12, 'terre haute', 0, 0, 0), (84108, 12, 'northwest indiana', 0, 0, 0), (84109, 13, 'ames', 0, 0, 0); Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. This could be PHP or MySql so putting it in PHP forum for now... I have code below (last code listed) which processes a dynamically created Form which could have anywhere from 0 to 6 fields. So I clean all fields whether they were posted or not and then I update the mySQL table. The problem with this code below is that if, say, $cextra was not posted (i.e. it wasnt on the dynamically created form), then this code would enter a blank into the table for $cextra (i.e. if there was already a value in the table for $cextra, it gets overwritten, which is bad). What is the best way to handle this? I'm thinking i have to break my SQL query into a bunch of if/else statements like this... Code: [Select] $sql = "UPDATE cluesanswers SET "; if (isset($_POST['ctext'])){ echo "ctext='$ctext',"; } else { //do nothing } and so on 5 more times.... That seems horribly hackish/inefficient. Is there a better way? Code: [Select] if (isset($_POST['hidden']) && $_POST['hidden'] == "edit") { $cimage=trim(mysql_prep($_POST['cimage'])); $ctext=trim(mysql_prep($_POST['ctext'])); $cextra=trim(mysql_prep($_POST['cextra'])); $atext=trim(mysql_prep($_POST['atext'])); $aextra=trim(mysql_prep($_POST['aextra'])); $aimage=trim(mysql_prep($_POST['aimage'])); //update the answer edits $sql = "UPDATE cluesanswers SET ctext='$ctext', cextra='$cextra', cimage='$cimage', atext='$atext', aextra='$aextra', aimage='$aimage'"; $result = mysql_query($sql, $connection); if (!$result) { die("Database query failed: " . mysql_error()); } else { } hi guys, im new to this forum I'm new also to php, I need help from you guys: I want to display personal information from a certain person (the data is on the mysql database) using his name as a link: example: (index.php) names 1. Bill Gates 2. Mr. nice Guy i want to click Bill Gates (output.php) Name: Bill Gates Country:xxxx Age: xx etc. How can i make this or how to learn this? Hi I am trying to select and order data/numbers from a colum in a mysql data base however i run the code and it returns no value just a blank page no errors or any thing so i think the code is working right but then it returns no result? Please help thanks Here is the code: <?php $host= "XXXXXX"; $mysql_user = "XXXXXX"; $mysql_password = "XXXXXX"; $mysql_database = "XXXXXXX"; $connection = mysql_connect("$host","$mysql_user","$mysql_password") or die ("Unable to connect to MySQL server."); mysql_select_db($mysql_database) or die ("Unable to select requested database."); $row = mysql_fetch_assoc( mysql_query( "SELECT XP FROM Game ORDER BY number DESC LIMIT 1" ) ); $number = mysql_result(mysql_query("SELECT XP FROM Game ORDER BY number DESC LIMIT 1"), 0); echo "The the highest XP is $number"; ?> Say I have the following text stored in a MySQL database... Code: [Select] <b>Classic Quote from movie</b> and I retrieve it into a variable called $text, how do I properly echo that so that it keeps the bold tags and actually display the text "Classic quote from movie" in BOLD? I'm doing something wrong somewhere along the line (simply doing "echo $text;") because it displays on the page as... Code: [Select] <b>Classic Quote from movie</b> Instead of... Classic Quote from movie Any info on properly storing and echoing back HTML would be very appreciated. I have a form on our website that a user can fill out for custom product. I want the form data to be 1) stored into a mysql database AND after storing said data, 2) email the same data to our sales department. 1) The form data DOES get stored into mysql database (except for the first two fields, for some weird reason) 2) I added a "mail" section to the php file that stores the data into the database, but it is not working correctly. I have stripped the email portion down to sending just one of the fields in the "message" to make it easier for troubleshooting I have included here, both the form section of the html file, and the formdata.php file that processes the data for your analysis. I am relatively new to php so there are going to be some issues with security, but I can work on those after I get the store & email process to work correctly. Please review my code and see if anyone can be of assistance. I looked through the forums and couldn't find another issue that was the same as mine. If I just overlooked, please tell me the thread post #. Thanks THE FORM WHICH COLLECTS THE DATA ******************************* <form method=POST action=formdata.php> <table width="640" border=0 align="center"> <tr> <td align=right><b>First Name</b></td> <td><input type=text name=FName size=25></td> <td><div align="right"><b>Telephone</b></div></td> <td><input type=text name=Tel size=25></td> </tr> <tr> <td align=right><b>Last Name</b></td> <td><input type=text name=LName size=25></td> <td><div align="right"><b>Fax</b></div></td> <td><input type=text name=Fax size=25></td> </tr> <tr> <td align=right><b>Title</b></td> <td><input type=text name=Title size=25></td> <td><div align="right"><b>Email</b></div></td> <td><input type=text name=Email size=50></td> </tr> <tr> <td align=right><b>Company</b></td> <td><input type=text name=Comp size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Address</b></td> <td><input type=text name=Addr size=25></td> <td><div align="right"><b>Estimated Annual Volume</b></div></td> <td><input type=text name=EAV size=25></td> </tr> <tr> <td align=right><b>City</b></td> <td><input type=text name=City size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>State/Province</b></td> <td><input type=text name=SProv size=25></td> <td><div align="right"><b>Application</b></div></td> <td><input type=text name=Appl size=25></td> </tr> <tr> <td align=right><b>Country</b></td> <td><input type=text name=Ctry size=25></td> <td><div align="right"><b>Type of System</b></div></td> <td><input type=text name=Syst size=25></td> </tr> <tr> <td align=right><b>Zip/Postal Code</b></td> <td><input type=text name=ZPC size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td><div align="right"><strong><font color="#FFFF00" face="Arial, Helvetica, sans-serif">COIL DESIGN</font></strong></div></td> <td><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PARAMETERS</strong></font></td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Primary Resistance (ohms)</b></td> <td><input type=text name=Pres size=25></td> <td><div align="right"><b>Primary Inductance (mH)</b></div></td> <td><input type=text name=Pind size=25></td> </tr> <tr> <td align=right><b>Secondary Resistance (ohms)</b></td> <td><input type=text name=Sres size=25></td> <td><div align="right"><b>Secondary Inductance (H)</b></div></td> <td><input type=text name=Sind size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Peak Operating Current (Amps)</b></td> <td><input type=text name=POC size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Output Energy (mJ)</b></td> <td><input type=text name=Egy size=25></td> <td><div align="right"><b>Output Voltage (kV)</b></div></td> <td><input type=text name=Volt size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b># HV Towers per Coil</b></td> <td><input type=text name=TPC size=25></td> <td><div align="right"><b># of Coils per Package</b></div></td> <td><input type=text name=CPP size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <th colspan=4><b>Please enter any additional information he </b></th> </tr> <tr> <th colspan=4><textarea name=Mess cols=50 rows=10 id="Message"></textarea></th> </tr> </table> </dl> <div align="center"> <p> <input type=hidden name=BodyTag value="<body bgcolor="#484589" text="#FFFFFF" link="#FFFF00" alink="#FFFFFF" vlink="#FF7F00">"> <input type=hidden name=FA value=SendMail> </p> <p><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PLEASE MAKE SURE ALL INFORMATION<br> IS CORRECT BEFORE SUBMITTING</strong></font></p> <p> <input type=submit value="Submit Form"> </p> </div> </form> THE FILE THAT PROCESSES THE FORM DATA (formdata.php) *********************************************** <?php $con = mysql_connect("localhost","XXX","XXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("customform", $con); $sql="INSERT INTO formdata (Fname, Lname, Title, Comp, Addr, City, SProv, Ctry, ZPC, Tel, Fax, Email, EAV, Appl, Syst, Pres, Pind, Sres, Sind, POC, Egy, Volt, TPC, CPP, Mess) VALUES ('$_POST[Fname]','$_POST[Lname]','$_POST[Title]','$_POST[Comp]','$_POST[Addr]','$_POST[City]','$_POST[SProv]','$_POST[Ctry]','$_POST[ZPC]','$_POST[Tel]','$_POST[Fax]','$_POST[Email]','$_POST[EAV]','$_POST[Appl]','$_POST[Syst]','$_POST[Pres]','$_POST[Pind]','$_POST[Sres]','$_POST[Sind]','$_POST[POC]','$_POST[Egy]','$_POST[Volt]','$_POST[TPC]','$_POST[CPP]','$_POST[Mess]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Your Information Was Successfully Posted"; mysql_close($con); $to = "recipient email address here"; $subject = "Custom Form"; $email = $_POST['Email'] ; $message = $_POST['Comp'] ; $headers = "From: $Email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> Good day: Is there a way to create a proxy or coding in php that it is constantly getting the data from a sql database and inserting it into a mysql database? Any help will be appreciated. I have a script that is supposed to allow a user to add their details to a members table in the database. It acts as if the user has been added to the database by stating the thank you message, but there is no entry into the database. I can connect to the database and have another script running OK that allows me to view all of the information in the members table with a loop (this data was entered using php my admin's GUI). Here is the script that is supposed to add the member. Any help would be greatly appreciated. <?php error_reporting(-1); $user_name = "root"; $password = ""; $database = "test"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "INSERT INTO members (fname, sname, email, password, gender) VALUES ('$_POST[fname]','$_POST[sname]','$_POST[email]','$_POST[password]','$_POST[gender]')"; $result = mysql_query($SQL); mysql_close($db_handle); print "Thanks for joining us ".$_POST['fname']."."; } else { print "Database NOT Found"; mysql_close($db_handle); } ?> hey everyone! in new to the whole php and mysql thing and i am stuck with one part, i have got a login script, once loged in it takes them to there account page, on there account page they can added data into there file, to mysql, so what I'm looking for is how to add the username they logged in with to be added into the database with the rest of the information they just submitted, so when they go to retrieve there information into a table they will only get the information that has there username with it. as much help as possible would be great! thank-you Hello im new to php and i cant seems to view my database in my php
<?php include('../connect.php'); $sds=$_SESSION['SESS_FIRST_NAME']; $result = mysql_query("SELECT * FROM paymentdetails WHERE idnumber='$sds'"); while($row = mysql_fetch_array($result)) { echo '<tr class="record">'; echo '<td style="border-left: 1px solid #C1DAD7"><div align="left">'.$row['date'].'</div></td>'; echo '<td><div align="left">'.$row['amount'].'</div></td>'; echo '</tr>'; } ?> </tbody> </table>Here my database im really confuse on what to do CREATE TABLE IF NOT EXISTS `paymentdetails` ( `id` int(11) NOT NULL AUTO_INCREMENT, `idnumber` varchar(30) NOT NULL, `date` varchar(30) NOT NULL, `amount` varchar(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `paymentdetails` -- INSERT INTO `paymentdetails` (`id`, `idnumber`, `date`, `amount`) VALUES (1, 'SID-YWU49JU', '2014-08-07', '50000'); I am in the process of writing code for a dynamic form. I have the part of the form written for information to be entered. I am now trying to write code for the modification of the information in the table. I know that I want to get the table data my doing a MySql Select and putting that information into an array. I am not very familiar with arrays and have spent some time looking for a solution online with no solution. When I print_r the results I get what I want but when I do anything else I get Array. What I am actually looking to do is make it so that the table data is in another variable this is the section of code that I am working with. Code: [Select] $mod_form = "<form name='insert_table' id='insert_table' action='ad_add.php' method='post' enctype='multipart/form-data'> <fieldset> <legend>table information</legend> <input name='table' TYPE='hidden' VALUE='" . $table . "' />"; $mod_sql = "SELECT * FROM $table WHERE id = '$id'"; $mod_sql_result = mysql_query($mod_sql); $allowed_ext = array('jpg', 'jpeg', 'png', 'gif'); $input_array = array(); while ($row = mysql_fetch_array($mod_sql_result, MYSQL_NUM)) { $input_array[] = $row; } foreach ($input_array as $input => $data) { print_r($data); } while ($i < mysql_num_fields($mod_sql_result)) { $header = str_replace("_", " ", (mysql_field_name($mod_sql_result, $i))); $name = mysql_field_name($mod_sql_result, $i); (mysql_field_name($mod_sql_result, $i) == 'image' ? $mod_form .= "<p>" . $header . ": <input name='" . $name . "' id='" . $name . "' type='file' /></p>" : $mod_form .= "<p>" . $header . ": <input name='" . $name . "' id='" . $name . "' type='text' value='" . $input . "'/></p>"); $i++; } $mod_form .= " <p> <input type='submit' name='submit_mod' id='submit_mod' /> </p> </fieldset> </form> "; echo $mod_form; |