PHP - For Each Loop For Echoing Column Data
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 Similar TutorialsI want to echo the contents of column 4 for my username only, and it doesn't show anything. I can do if ($memberQuery->fetchColumn(4) < 2)() though. Code: [Select] $host = 'localhost'; $database = ''; $db_username = ''; $db_password = ''; if (($db = new PDO("mysql:host=$host;dbname=$database", $db_username, $db_password)) == NULL) { echo $db->getMessage(); } $memberQuery = $db->prepare("SELECT * FROM members WHERE username=:username"); $memberQuery->execute(array(':username' => $_SESSION['username'])); $result = $memberQuery->fetchColumn(4); echo "$result"; I 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 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 phpsaneHi, 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. For the section of code below, is there a way to say, "first time through the query print on A2, B2,etc, then each query following add increase the number besides column name to be A3, B3, etc, then A4, B4, etc"...? $result = mysqli_query($connection,"SELECT * FROM table") or die(mysqli_error($connection)); while($row = mysqli_fetch_array($result)) { //get all rows you want from the table $var1 = $row['var1']; $var2 = $row['var2']; $var3 = $row['var3']; $var4 = $row['var4']; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A2', $var1) ->setCellValue('B2', $var2) ->setCellValue('C2', $var3) ->setCellValue('D2', $var4); } This is for an excel spreadsheet. The code is currently printing/exporting one row only from the table. Thanks Code: [Select] $db_connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql_get = "SELECT DISTINCT category FROM con"; $sql_run = mysqli_query($db_connect, $sql_get) or mysqli_error($db_connect); $sql_assoc = mysqli_fetch_assoc($sql_run); while($sql_assoc = mysqli_fetch_assoc($sql_run)){ echo $sql_assoc['category']; } From the column "category" I get printed 5 distinct entries, though the SQL statement itself does print out 6 distinct entries in MySQL, which is the right one. Just wondering why does the while loop leave out one entry? Also in the array is the "category" identifier necessary since it is identified in the SQL statement already? How would it look differently? I am trying to create 3 columns of data from a query. I have used this code before for 2 columns but and now wanting to use for three columns.
There are 5 records from a join query. The first two columns display the results, 2 results in the left column and 3 results in the center column. The right column displayw empyt text used in displaying the results, there is no data to populate and it seems to mimic the the number from the center, 3.
Here is the URL to see the problem
http://specialslocat...ignID=1IBu3992p
Here is the Code for the query and the 3 column results.
<?php $UN_URL = $_GET['un']; $mS_MGMTcampaignID_URL = $_GET['mS_MGMTcampaignID']; ?> <table width="944" border="1" align="center" cellpadding="0" cellspacing="0"> <?php $result = mysql_query( "SELECT * FROM manager_Specials_company_mgmt MSCM LEFT JOIN b2c_coupons B2CC ON (MSCM.mS_MGMT_id = B2CC.m_primeID )WHERE mS_MGMTcampaignID = '$mS_MGMTcampaignID_URL' ORDER BY mS_MGMT_m_company ASC" ); $num_results = mysql_num_rows($result); $numb_tb_rows= ceil($num_results/3) ?> <? if ( $numb_tb_rows > 0 ) { ?> <tr > <td colspan="4" valign="top" class="body_text_10_Center"><strong><?=$mS_campaignName_mS?> is proud to sponsor <?=$num_results?> <? if ( $num_results == 1 ) { ?> company:</strong> <? } elseif ( $num_results > 1 ) { ?> companies:</strong> <? } ?> </td> </tr> <tr class="body_text_10_Center"> <!-- Column 1 --> <td width="320" class="body_text_10_Center" valign="top"> <? // column #1 if($num_results>=1) { for($i=0; $i<$numb_tb_rows; $i++) { $row= mysql_fetch_array($result); ?> <?php if(!empty ($row["m_logo"])) { ?> <div align="center"> <img src="http://marketingteammates.com/_ZABP_merchants/_zcnsLogos/gick.php/<?=stripslashes($row["m_logo"])?>?resize(220)" border="0"></a><br /> </div> <?php } else { } ?> <h6><?=stripslashes($row["mS_MGMT_m_company"])?></h6> <?=stripslashes($row["b2c_m_address1"])?> <?=stripslashes($row["b2c_m_address2"])?><br /> <?=stripslashes($row["b2c_m_city"])?> <?=stripslashes($row["b2c_m_state"])?>, <?=stripslashes($row["b2c_m_zip"])?><br /> Phone: <?=stripslashes($row["b2c_m_phone"])?><br /> Fax: <?=stripslashes($row["b2c_m_fax"])?><br /> <a href="mailto:<?=stripslashes($row["b2c_email"])?>"><?=stripslashes($row["b2c_email"])?></a><br /><br /> Hours of Operation: <?=stripslashes($row["m_coupon_title"])?><br /> <?=stripslashes($row["m_coupon_desc"])?><br /><br /> <div align="center"> <img src="../images/print_image.gif" width="29" height="31" /><br /><br /> <hr width="80%" size="1" /> </div><br /><br /> <? // END column #1 } } ?> </td> <!-- Column 2 --> <td width="320" class="body_text_10_Center" valign="top"> <? // column #2 if($num_results>=2) { for($i=($numb_tb_rows); $i<$num_results; $i++) { $row= mysql_fetch_array($result); ?> <?php if(!empty ($row["m_logo"])) { ?> <div align="center"> <img src="http://marketingteammates.com/_ZABP_merchants/_zcnsLogos/gick.php/<?=stripslashes($row["m_logo"])?>?resize(220)" border="0"></a><br /> </div> <?php } else { } ?> <h6><?=stripslashes($row["mS_MGMT_m_company"])?></h6> <?=stripslashes($row["b2c_m_address1"])?> <?=stripslashes($row["b2c_m_address2"])?><br /> <?=stripslashes($row["b2c_m_city"])?> <?=stripslashes($row["b2c_m_state"])?>, <?=stripslashes($row["b2c_m_zip"])?><br /> Phone: <?=stripslashes($row["b2c_m_phone"])?><br /> Fax: <?=stripslashes($row["b2c_m_fax"])?><br /> <a href="mailto:<?=stripslashes($row["b2c_email"])?>"><?=stripslashes($row["b2c_email"])?></a><br /><br /> Hours of Operation: <?=stripslashes($row["m_coupon_title"])?><br /> <?=stripslashes($row["m_coupon_desc"])?><br /><br /> <div align="center"> <img src="../images/print_image.gif" width="29" height="31" /><br /><br /> <hr width="80%" size="1" /> </div><br /><br /> <? // END column #2 } } ?> </td> <!-- Column 3 --> <td width="320" class="body_text_10_Center" valign="top"> <? // column #3 if($num_results>=3) { for($i=($numb_tb_rows); $i<$num_results; $i++) { $row= mysql_fetch_array($result); ?> <?php if(!empty ($row["m_logo"])) { ?> <div align="center"> <img src="http://marketingteammates.com/_ZABP_merchants/_zcnsLogos/gick.php/<?=stripslashes($row["m_logo"])?>?resize(220)" border="0"></a><br /> </div> <?php } else { } ?> <h6><?=stripslashes($row["mS_MGMT_m_company"])?></h6> <?=stripslashes($row["b2c_m_address1"])?> <?=stripslashes($row["b2c_m_address2"])?><br /> <?=stripslashes($row["b2c_m_city"])?> <?=stripslashes($row["b2c_m_state"])?>, <?=stripslashes($row["b2c_m_zip"])?><br /> Phone: <?=stripslashes($row["b2c_m_phone"])?><br /> Fax: <?=stripslashes($row["b2c_m_fax"])?><br /> <a href="mailto:<?=stripslashes($row["b2c_email"])?>"><?=stripslashes($row["b2c_email"])?></a><br /><br /> Hours of Operation: <?=stripslashes($row["m_coupon_title"])?><br /> <?=stripslashes($row["m_coupon_desc"])?><br /><br /> <div align="center"> <img src="../images/print_image.gif" width="29" height="31" /><br /><br /> <hr width="80%" size="1" /> </div><br /><br /> <? // END column #3 } } ?> </td> </tr> <? } else { echo ""; } ?> </table>Thanks for any help in advance. Mike Hi.. Sorry, if I need to repost my problem in while loop. cause until now I can't resolve my problem in saving all data from while loop. I have this code StockRequisition.php where FORM was displayed. <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date =date('Y-m-d H:i:s'); $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } else { //------------------------------------------------------------------------------------------------------------------ // Stock Number iteration.... $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['sr_number'],0,3)); $currentSRYear = (int)(substr($row['sr_number'],2,2)); $currentSRMonth = (int)(substr($row['sr_number'],0,2)); $currentSRNum = (int)(substr($row['sr_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } //------------------------------------------------------------------------------------------------------------------ $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%04d", $currentSRNum); ?> <html> <title>Stock Requisition</title> <head> <link rel="stylesheet" type="text/css" href="kanban.css"> <script type="text/javascript"> function save_sr(){ var sr_date = document.getElementById("sr_date").value; var sr_number = document.getElementById("sr_number").value; var Items1 = document.getElementById("Items1").value; var SubItems = document.getElementById("SubItems").value; var ItemCode = document.getElementById("ItemCode").value; var DemandedQty = document.getElementById("DemandedQty").value; var UoM = document.getElementById("UoM").value; var Class = document.getElementById("Class").value; var Description = document.getElementById("Description").value; var BINLocation = document.getElementById("BINLocation").value; var RequestedBy = document.getElementById("RequestedBy").value; var ApprovedBy = document.getElementById("ApprovedBy").value; var ReceivedBy = document.getElementById("ReceivedBy").value; var IssuedBy = document.getElementById("IssuedBy").value; document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items1="+Items1+ "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+ Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+ "&IssuedBy="+IssuedBy; document.stock_requisition.submit(); alert("Stock Requisition data save."); window.location = "StockRequisition.php"; } </script> </head> <body> <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div id="ddcolortabs"> <ul> <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li> <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li> <li><a href="fsn.php" title="Finished Stock Note"><span>WMS FG</span></a></li> <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li> </ul> </div> <div id="ddcolortabs1"> <ul> <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li> <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li> <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li> </ul> </div> <div id="SR_date"> <label>Date :</label> <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="SR_number"> <label>SR# :</label> <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;"> <br/> </div> <div> <table> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items"; $res_bom = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_bom)){ $Items = $row['Items']; echo "<tr> <td style='border: none;font-weight: bold;'> <input type='name' value='$Items' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td> </tr>"; $sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ $Items1 = $row_sub['Items']; $SubItems = $row_sub['SubItems']; $ItemCode = $row_sub['ItemCode']; $UoM = $row_sub['UoM']; $Class = $row_sub['Class']; $Description = $row_sub['Description']; $BINLocation = $row_sub['BINLocation']; echo "<tr> <td style='border: none;'> <input type='hidden' value='$Items1' id='Items1' name='Items1'></td> <td style='border: none;'> <input type='text' name='SubItems' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='ItemCode' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td> <td style='border: none;' size='3'> <input type='text' name='UoM' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td> <td style='border: none;'> <input type='text' name='Class' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='Description' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='BINLocation' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> </tr>"; } } ?> </table> </div> <?php $RequestedBy = array('AAA', 'BBB', 'CCC', 'DDD'); $ApprovedBy = array('EEE', 'FFF', 'GGG', 'HHH'); $ReceivedBy = array('III', 'JJJ', 'KKK', 'LLL'); $IssuedBy = array('MMM', 'NNN', 'OOO', 'PPP'); ?> <div id='Requested_By'> <label>Requested By:</label> <select name="RequestedBy"> <option value="Select">Select</option> <option value="AAA" <?php if($_POST['RequestedBy'] == 'AAA') echo "selected='selected'"; ?>>AAA</option> <option value="BBB" <?php if($_POST['RequestedBy'] == 'BBB') echo "selected='selected'"; ?>>BBB</option> <option value="CCC" <?php if($_POST['RequestedBy'] == 'CCC') echo "selected='selected'"; ?>>CCC</option> <option value="DDD" <?php if($_POST['RequestedBy'] == 'DDD') echo "selected='selected'"; ?>>DDD</option> </select> </div> <div id='Approved_By'> <label>Approved By:</label> <select name="ApprovedBy"> <option name='Select'>Select</option> <option value="EEE" <?php if($_POST['ApprovedBy'] == 'EEE') echo "selected='selected'"; ?>>EEE</option> <option value="FFF" <?php if($_POST['ApprovedBy'] == 'FFF') echo "selected='selected'"; ?>>FFF</option> <option value="GGG" <?php if($_POST['ApprovedBy'] == 'GGG') echo "selected='selected'"; ?>>GGG</option> <option value="HHH" <?php if($_POST['ApprovedBy'] == 'HHH') echo "selected='selected'"; ?>>HHH</option> </select> </div> <div id='Received_By'> <label>Issued By:</label> <select name="IssuedBy"> <option name='Select'>Select</option> <option value="III" <?php if($_POST['ReceivedBy'] == 'III') echo "selected='selected'"; ?>>III</option> <option value="JJJ" <?php if($_POST['ReceivedBy'] == 'JJJ') echo "selected='selected'"; ?>>JJJ</option> <option value="KKK" <?php if($_POST['ReceivedBy'] == 'KKK') echo "selected='selected'"; ?>>KKK</option> <option value="LLL" <?php if($_POST['ReceivedBy'] == 'LLL') echo "selected='selected'"; ?>>LLL</option> </select> </div> <div id='Issued_By'> <label>Received By:</label> <select name="ReceivedBy"> <option name='Select'>Select</option> <option value="MMM" <?php if($_POST['IssuedBy'] == 'MMM') echo "selected='selected'"; ?>>MMM</option> <option value="NNN" <?php if($_POST['IssuedBy'] == 'NNN') echo "selected='selected'"; ?>>NNN</option> <option value="OOO" <?php if($_POST['IssuedBy'] == 'OOO') echo "selected='selected'"; ?>>OOO</option> <option value="PPP" <?php if($_POST['IssuedBy'] == 'PPP') echo "selected='selected'"; ?>>PPP</option> </select> </div> <div id="save_btn"> <input type="button" name="button" value="save" onClick="save_sr()"> </div> </form> </body> </html> and here is StockRequisitionSave.php code for saving data to database : <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date = $_POST['sr_date']; $sr_number = $_POST['sr_number']; $Items1 = $_POST['Items1']; $SubItems = $_POST['SubItems']; $ItemCode = $_POST['ItemCode']; $DemandedQty = $_POST['DemandedQty']; $UoM = $_POST['UoM']; $Class = $_POST['Class']; $Description = $_POST['Description']; $BINLocation = $_POST['BINLocation']; $RequestedBy = $_POST['RequestedBy']; $ApprovedBy = $_POST['ApprovedBy']; $ReceivedBy = $_POST['ReceivedBy']; $IssuedBy = $_POST['IssuedBy']; $sql = "INSERT INTO stock_requisition (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy, ApprovedBy, ReceivedBy, IssuedBy) VALUES ('$sr_date', '$sr_number', '$Items1', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description', '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy') "; $result = mysql_query($sql, $con); ?> the problem is only the last data was save. I will attach my form. I hope somebody can help me.. I really don't know how can I save all data from form into my database. Thank you so much for your understanding and help. How can i get the last row data from a certain column? I have some php code on view invoice and it's getting all the data I need to from three database tables but for some reason it's not getting the data for one specific column and unsure why I have done a echo sql and it is echoing the sql query ok and have ran the sql query in phpmyadmin and is displaying the column in phpmyadmin that is not displaying on the php page so am bit confused, below is the coding I have. I took out a lot of it and tried to keep to the relevant parts <?php $sql = "SELECT t1.id, t1.invoice_number, DATE_FORMAT(t1.invoice_date,'%d/%m/%Y') AS invoice_date, t1.user_id, t2.invoice_number, t2.service_name, t2.service_price, t3.user_id, t3.customer_name, t3.customer_phone, t3.customer_email, t2.service_name, t2.service_price, t1.invoice_total, t1.balance, t1.notes, DATE_FORMAT(t1.payment_date,'%d/%m/%Y') AS payment_date, t1.payment_method FROM invoices as t1 LEFT JOIN invoice_products as t2 ON t1.id = t2.invoice_id LEFT JOIN users as t3 ON t1.user_id = t3.user_id WHERE t1.user_id = '".$_SESSION['user_id']."' and t1.id = '".$_GET['id']."'"; $result = mysqli_query($connect, $sql); if(mysqli_num_rows($result) > 0) { if($row = mysqli_fetch_array($result)) { ?> Notes: <?php echo $row['notes'];?> <?php } } ?>
<html> <title>Micro Elite Brigade - Participated Events</title><LINK REL="SHORTCUT ICON" HREF="images/favicon.png"><?php require_once('upper.php'); if($_COOKIE['LoginIdCookie']){ require_once('database.php'); require_once('LoginStatement.php'); $LoginId=$_COOKIE['LoginIdCookie']; $query="select * from participation where LoginId='$LoginId'"; $result=mysqli_query($dbc,$query) or die ('Not Connected'); //echo "<div class='search_output_data'> echo "<table border='0' cellspacing='0' cellpadding='0'>"; echo "<tr><th align='left' valign='top' width='100' height='20'>Event Title</th> <th align='right' valign='top' width='250' height='30'>Date of Participation</th> </tr>"; while($row=mysqli_fetch_array($result)) { echo " <tr><td colspan='4' align='left' valign='top' ><table align='left' border='0' cellspacing='0' cellpadding='0'><tr><td align='left' valign='top' width='200' height='20'>".$row['Title']."</td> <td width='50'> </td> <td align='left' valign='top' width='130'>".$row['Date']."</td> </tr></table> </td></tr>"; } echo "</table>";} else{ echo 'Sorry, You must have to login.';} require_once('lower.php'); ?> HI friends..... I have a table named events in which I have a "Title" column. When I print the value of Title column, it not displayed not more than 40 characters.... Where is the problem ??? Anyone?????? Hi, I have this script that returns the entire table including column names and the row data. However I only want certain column names and the corresponding data to be returned. Code: [Select] <?php include_once("data/mysql.php"); $mysqlPassword = (base64_decode($mysqlpword)); $db = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die ("Error connecting to database"); mysql_select_db("$dbname", $db) or die ("An error occured when connecting to database"); // sending query $result = mysql_query("SELECT * FROM members"); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<h1>Table: members</h1>"; echo "<table border='1'><tr>"; for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; while($row = mysql_fetch_row($result)) { echo "<tr>"; foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_query($result); ?> Any help is always appreciated I have data similar to below. I am doing a MySQL query and doing a JOIN based on instructor name. I am echoing classes and linking the instructor name to another page with their BIO. All is working great, however I want to use the ID's for something else. How do I differentiate the ID between the Instructors table and the Classes Table without changing the column name in the database?
For instance, I want to echo the Instructor ID and then echo the Classes ID, but they are both the same column name in the database and since they are joined, how will that work?
Instructors:
ID | Instructor | Title | Bio |
1 | Bob Smith | Chef | bob smith is a chef with... |
2 | Jane Doe | Professor | Jane doe is an instructor that... |
Classes:
ID | Instructor | Class Title | Class Description |
4 | Bob Smith | Baking | this is a baking class where you learn.... |
5 | Jane Doe | Food Safety | Food safety is very important... |
Here is the while loop: Code: [Select] <?php require_once("../includes/initialize.php"); $sql="SELECT * FROM product WHERE product_id IN ("; foreach($_SESSION['cart'] as $id => $value) { $sql.=$id.","; } $sql=substr($sql, 0, -1).") ORDER BY model ASC"; $query=mysql_query($sql); $totalprice=0; while($row=mysql_fetch_array($query)){ $subtotal=$_SESSION['cart'][$row['product_id']]['quantity']*$row['price']; $totalprice+=$subtotal; ?> <tr> <td><?php echo $row['model'] ?></td> <td><?php echo $_SESSION['cart'][$row['product_id']]['quantity'] ?></td> <td><?php echo number_format($row['price'], 2, ',', '.'); ?>din</td> <td><?php $cena = $_SESSION['cart'][$row['product_id']]['quantity']*$row['price']; echo number_format($cena, 2, ',', '.'); ?>din</td> </tr> <?php } ?> How to get data out of the loop? I need it to be same as data echoed (this is the echo result: BFG 225/30 ZR 20 4 21.667,00din 86.668,00din). Hi Guys, Theres probably a really simple way to do this, but i haven't touched php in a wee while lol this code: foreach ($menu as $elem) { $selected1 = ''; $selected2 = ''; if ($elem['system_name'] == $this->system_name) { $selected1 = '<b>'; $selected2 = '</b>'; } if ($elem['system_name'] != 'home-content') { $elem['system_name'] = $elem['system_name'] . '.html'; } else { $elem['system_name'] = ''; } printf('<li class="%s">%s<a href="%s/%s">%s</a>%s</li>', $elem['li_class'], $selected1, ROOT, $elem['system_name'], $elem['title'], $selected2); } ?> Prints out the navigation on one of my sites, when the code loops through the menu i want to change one of the href targets for example: if (loop through menu) { if (page returned for example users page) { <a href="[b]CHANGE THIS TO SOMETHING.html[/b]"> } } So i only need to change one of the hrefs not all of them any help would be appreciated thanks guys Graham Hi all, This has just been bugging me forever, I actually just hardcoded the line it in years ago to just be done with it. But when I use the while loop to pull up the data for this table, it prints out every row but the last one. I've wracked my brain for years trying to fix it, and just cannot find the solution. Below is the entire page code I'm using and you can see at the bottom what I have sadly hardcoded in to make the last row display. That's the row that will not show up. If you want to see the actual live page it's he https://www.lakerstats.com/numerical-roster/ The UNK line at the end if the one that never prints out that I hardcoded. Page code as mentioned above. Appreciate any help! [php] $db = mysql_connect("localhost", "xxxx", "xxxx"); mysql_select_db("lakerstats",$db); echo "<table class=numeric WIDTH=100% cellpadding=0 cellspacing=0 border=0> <tr><td class=left colspan=\"2\" height=10><font size=\"2\" color=#000000>Current players are listed in ALL CAPS.<br />Retired uniforms are listed in <b><font color=\"#FF0000\">red</font></b>.<br /></font></td></tr><tr>"; $uniforms = "SELECT p.fname, p.lname, p.playerid, u.number, p.current_roster, u.retired, u.retired_player, p.profile_name, p.uniform_1, p.uniform_2 FROM player p, uniforms u WHERE u.number = p.uniform_1 or u.number = p.uniform_2 or u.number = p.uniform_3 or u.number = p.uniform_4 ORDER BY u.number+0, p.years, p.lname, p.fname"; $uniresult = mysql_query($uniforms) or die ("Query failed"); $numofrows = mysql_num_rows($uniresult); //let's get the number of rows in our result so we can use it in a for loop $temp = "0"; $sHTMLTemp = ""; while ($unirow = mysql_fetch_array($uniresult)) // Where $result is your result set { if ($temp != $unirow['number']) { $temp = $unirow['number']; if ($unirow['number'] == "100") { $unirow['number'] = "0"; } else if ($unirow['number'] == "101") { $unirow['number'] = sprintf("%02d", 0); } else if ($unirow['number'] == "102") { $unirow['number'] = "UNK"; } else { $unirow['number'] = $unirow['number']; } $sHTMLTemp = preg_replace("/(.+),/","\\1",$sHTMLTemp); print $sHTMLTemp ; print "</tr>"; $sHTMLTemp = ""; if ($unirow[retired] == "yes") { echo "<tr><td class=left height=10><font size=\"2\" color=\"#FF0000\"><b>#" . $unirow[number] . "</b></font><font size=\"2\"> - "; } else { echo "<tr><td class=left height=10><font size=\"2\" color=\"#000000\">#" . $unirow[number] . "</font><font size=\"2\"> - "; } } if ($unirow[current_roster] == "yes") { $unirow[fname] = strtoupper($unirow[fname]); $unirow[lname] = strtoupper($unirow[lname]); } else { $unirow[fname] = $unirow[fname]; $unirow[lname] = $unirow[lname]; } if ($unirow[retired_player] == $unirow[playerid]) { $sHTMLTemp .= "<b><a href=\"/player-stats-bio/?pname=".$unirow['profile_name']."\"><font color=\"#FF0000\">" . $unirow['fname'] . " " . $unirow['lname'] . "</font></a></b>, "; } else { $sHTMLTemp .= "<a href=\"/player-stats-bio/?pname=".$unirow['profile_name']."\">" . $unirow['fname'] . " " . $unirow['lname'] . "</a>, "; } } echo "<a href=\"/player-stats-bio/?pname=jim_fritsche\">Jim Fritsche</a>, <a href=\"/player-stats-bio/?pname=bobby_watson\">Bobby Watson</a>"; echo "</font></td></tr>"; echo "</font></td></tr></table>"; mysql_close($db); [/php] Edited September 14, 2020 by ban5150 i am trying to fit this php code to so when ever i upload a video link to the database it prints in the divs from left to right. ( i have made blank boxes for where the videos should be, so you guys can see what i mean. i will give you the code here. Code: [Select] <?php $query = mysql_query("SELECT * FROM `G4V_Videos` ORDER BY `id` DESC") or die(mysql_error()); while ($data = mysql_fetch_array($query)) { ?> ID-nummer: <?php print $data['id']; ?> - Name: <?php print $data['navn']; ?> - <a href="/Video.php?id=<?php print $data['id']; ?>"><img src="http://i.ytimg.com/vi/<?php print $data['link'];?>/hqdefault.jpg" width="200" height="160" /></a><br /> <a href="/Video.php?=<?php print $data['id']; ?>"> <?php } ?> and the website is here, http://www.game4vids.com/index.php and i also want it so once i have used up all the boxes it posts the new video in box one and overwrites the old one if you get what i mean. This website is a great example of what i mean. http://www.retardo.dk Hi.. I need help in using for loop in saving data from while loop. Now, I encountered that the Demanded Qty was get only is the last Demanded Qty and save it to all Items. I want to happen is per Items will save the Demanded Qty. for example: Items Demanded Qty P28 ---1 P28 ---1 P28 ---1 P30 ---2 P30 ---2 P30 ---2 and so on.. here is my code: <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date =date('Y-m-d H:i:s'); $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } else { $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['sr_number'],0,3)); $currentSRYear = (int)(substr($row['sr_number'],2,2)); $currentSRMonth = (int)(substr($row['sr_number'],0,2)); $currentSRNum = (int)(substr($row['sr_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%04d", $currentSRNum); ?> <html> <title>Stock Requisition</title> <head> <link rel="stylesheet" type="text/css" href="kanban.css"> <script type="text/javascript"> function save_sr(){ var sr_date = document.getElementById("sr_date").value; var sr_number = document.getElementById("sr_number").value; var Items1 = document.getElementById("Items1").value; var SubItems = document.getElementById("SubItems").value; var ItemCode = document.getElementById("ItemCode").value; var DemandedQty = document.getElementById("DemandedQty").value; var UoM = document.getElementById("UoM").value; var Class = document.getElementById("Class").value; var Description = document.getElementById("Description").value; var BINLocation = document.getElementById("BINLocation").value; var RequestedBy = document.getElementById("RequestedBy").value; var ApprovedBy = document.getElementById("ApprovedBy").value; var ReceivedBy = document.getElementById("ReceivedBy").value; var IssuedBy = document.getElementById("IssuedBy").value; var Items = document.getElementById("Items").value; document.stock_requisition.action="StockRequisitionSave1.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items1="+Items1+ "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+ Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+ "&IssuedBy="+IssuedBy+"&Items="+Items; document.stock_requisition.submit(); alert("Stock Requisition data save."); window.location = "StockRequisition1.php"; } function disp(){ document.stock_requisition.action="StockRequisitionDisplay.php"; document.stock_requisition.submit(); } </script> </head> <body> <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div id="SR_date"> <label>Date :</label> <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly"> </div> <div id="SR_number"> <label>SR# :</label> <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly"> <br/> </div> <div> <table> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items"; $res_bom = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_bom)){ $Items = $row['Items']; echo "<tr> <td> <input type='name' value='$Items' name='Items[]' id='Items' readonly = 'readonly' size='5'></td> <td> </td> <td> </td> <td><center><input type='text' name='DemandedQty' id='DemandedQty[]' value='' size='7'></center></td> </tr>"; $sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ $Items1 = $row_sub['Items']; $SubItems = $row_sub['SubItems']; $ItemCode = $row_sub['ItemCode']; $UoM = $row_sub['UoM']; $Class = $row_sub['Class']; $Description = $row_sub['Description']; $BINLocation = $row_sub['BINLocation']; echo "<tr> <td> <input type='hidden' value='$Items1' id='Items1' name='Items1[]'></td> <td> <input type='text' name='SubItems[]' value='$SubItems' id='SubItems' readonly='readonly' size='10'></td> <td> <input type='text' name='ItemCode[]' value='$ItemCode' id='ItemCode' readonly='readonly' size='10'></td> <td> </td> <td> <input type='text' name='UoM[]' value='$UoM' id='UoM' readonly='readonly' size='3'></td> <td> <input type='text' name='Class[]' value='$Class' id='Class' readonly='readonly' size='10'></td> <td> <input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' size='10'></td> <td> <input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' size='10'></td> </tr>"; } } ?> </table> </div> <?php $RequestedBy = array('AAA', 'BBB'); $ApprovedBy = array('EEE', 'FFF'); $ReceivedBy = array('III', 'JJJ'); $IssuedBy = array('MMM', 'NNN'); ?> <div id='Requested_By'> <label>Requested By:</label> <select name="RequestedBy"> <option value="Select">Select</option> <option value="AAA" <?php if($_POST['RequestedBy'] == 'AAA') echo "selected='selected'"; ?>>AAA</option> <option value="BBB" <?php if($_POST['RequestedBy'] == 'BBB') echo "selected='selected'"; ?>>BBB</option> </select> </div> <div id='Approved_By'> <label>Approved By:</label> <select name="ApprovedBy"> <option name='Select'>Select</option> <option value="EEE" <?php if($_POST['ApprovedBy'] == 'EEE') echo "selected='selected'"; ?>>EEE</option> <option value="FFF" <?php if($_POST['ApprovedBy'] == 'FFF') echo "selected='selected'"; ?>>FFF</option> </select> </div> <div id='Received_By'> <label>Issued By:</label> <select name="IssuedBy"> <option name='Select'>Select</option> <option value="III" <?php if($_POST['ReceivedBy'] == 'III') echo "selected='selected'"; ?>>III</option> <option value="JJJ" <?php if($_POST['ReceivedBy'] == 'JJJ') echo "selected='selected'"; ?>>JJJ</option> </select> </div> <div id='Issued_By'> <label>Received By:</label> <select name="ReceivedBy"> <option name='Select'>Select</option> <option value="MMM" <?php if($_POST['IssuedBy'] == 'MMM') echo "selected='selected'"; ?>>MMM</option> <option value="NNN" <?php if($_POST['IssuedBy'] == 'NNN') echo "selected='selected'"; ?>>NNN</option> </select> </div> <div id="save_btn"> <input type="button" name="button" value="save" onClick="save_sr()" style="width: 5em;"> <input type="button" name="button" value="display" onclick="disp()"> </div> </form> </body> </html> and here is the save code: <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date = $_POST['sr_date']; $sr_number = $_POST['sr_number']; $Items1 = $_POST['Items1']; $SubItems = $_POST['SubItems']; $ItemCode = $_POST['ItemCode']; $DemandedQty = $_POST['DemandedQty']; $UoM = $_POST['UoM']; $Class = $_POST['Class']; $Description = $_POST['Description']; $BINLocation = $_POST['BINLocation']; $RequestedBy = $_POST['RequestedBy']; $ApprovedBy = $_POST['ApprovedBy']; $ReceivedBy = $_POST['ReceivedBy']; $IssuedBy = $_POST['IssuedBy']; $Items = $_POST['Items']; for($i = 0; $i < count($Items1); $i++) { if ( $DemandedQty != "" ) { $sql = "INSERT INTO stock_requisition (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy, ApprovedBy, ReceivedBy, IssuedBy) VALUES ('$sr_date', '$sr_number', '$Items1[$i]', '$SubItems[$i]', '$ItemCode[$i]', '$DemandedQty', '$UoM[$i]', '$Class[$i]', '$Description[$i]', '$BINLocation[$i]', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy') "; $result = mysql_query($sql, $con); } } ?> I attach my sample form and the data save in database. Thank you so much I have a loop that writes out data for franchises. It works the first time through, but not the 2nd. Here is the page where the data is written out: http://184.172.137.97/~royl21st/1.php Here is the code that spits out the wrong data after the first successful loop. Any ideas? Code: [Select] $areaCodeData = getData($sSql, $con, $dbName); $areaCodeRowCount = mySQL_num_rows($areaCodeData); $areaCodeRowCur = mysql_fetch_assoc($areaCodeData); if ($areaCodeRowCount != 0) { echo "<div class='box left'>"; // list all Area Codes for this Franchise echo "<div class='details'>"; $areaCodes = ""; for ( $ctrAreaCode = 0; $ctrAreaCode <= $areaCodeRowCount - 1; $ctrAreaCode += 1) { // grab AreaCodes $areaCodes = "<b>".$areaCodes.$areaCodeRowCur['AreaCode']."</b>, "; // fetch next AreaCode row $areaCodeRowCur = mysql_fetch_assoc($areaCodeData); } // end ctrAreaCode for loop $areaCodes = substr($areaCodes, 0, strlen($areaCodes)-2)."<br />"; echo "<em>-- Area Codes Supported:</em><br/>"; echo $areaCodes; echo "</div>"; echo "</div><br />"; } //end Area Code loop // reset AreaCode loop pointers (is this a PHP bug?) mysql_data_seek($areaCodeData,0); At this point I'm desperate and I have to get this working ASAP. The Grand Rapids, Kalamazoo, Holland area codes are 616, 269, 616 and their area codes are 49xxx Thanks in advance for the help... |