PHP - Fail Experiment (mysql Fetch Array...)
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++; } Similar TutorialsHi, I'm wondering if theres a shortcut to a potential problem I have. I'm currently running a query on my website to pull all the fields from a table in my database, for the data to be used on various parts of the page. Usually I would do something as follows Code: [Select] $result = mysql_query("SELECT * FROM table WHERE page='1'"); while ($row=mysql_fetch_array($result)) { $title = $row["title"]; $data = $row["data"]; } And so on and so forth. I would then call the appropriate data by echoing $data for example. However, my table contains a lot more rows than i've mentioned (Around 25 or so). Rather than assigning each to a variable and having a large portion of variable assignments at the top of the page, is there any clever way of putting all of these values inside of an array. So for example, I could call $array_data["title"] or $array_data["data"]?? So it keeps the same key, but puts it inside of an array that I don't have to loop through each time? Hope that makes sense! Thanks, Edd I've been using this code for a long time and realised it's very repetitive, but the id_column I want changes all the time function getRows() { $query = mysql_query($sql); $rows = array(); while($row = mysql_fetch_assoc($query)) { $rows[$row['id_column']] = $row; } return $rows; } So I wrote this function that will automatically create an array with a column I choose if I wish, but I'm not sure if it's very efficient. function getRows($query, $column_id = false) { $rows = array(); while($row = mysql_fetch_assoc($result)) { if($column_id === false) { $rows[] = $row; } else { if(isset($row[$column_id])) { $rows[$row[$column_id]] = $row; } else { $rows[] = $row; } } } return $rows; } I would appreciate some input as to make it better. Thanks. Hi,
Does anyone have a clue how I might solve this little issue:
I have a MySQL query, for example:
<?php // Make a MySQL Connection $query = "SELECT * FROM staff"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ if($row['clock'] < time()) { echo "<b>"$row['name']. " - ". $row['age']"</b>"; echo "<br />"; } else { echo $row['name']. " - ". $row['age']; echo "<br />"; } } ?>Taking data from the following table setup: name - age - clock Timmy Mellowman - 23 - 09:00:00 Sandy Smith - 21 - 12:00:00 Bobby Wallace - 15 - 14:00:00 What im trying to achieve is compare the current time to the time in the clock column and depending if it's earlier or later, change the styling of the results. The above code does appear to work somewhat however it seems to change the styling of all results in one go, rather than individually when it passes the time in the cell, which is what im looking for. Thanks Okay, this is getting on my nerves now, my head is throbbing probably just need a break from it all now. I'm currently getting the following message; Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\duff3\test3.php on line 25 Can anyone figure out and explain why this isn't working for me, I believe I am calling the function correctly and then putting the result into a while loop. Code: [Select] <?php function getPageContent($selectedPage) { $sql = "SELECT * "; $sql .= "FROM tbl_pages "; $sql .= "WHERE tbl_pages.pageCategoryId = ".$selectedPage." "; $sql .= "AND active = 1 "; $sql .= "LIMIT 1"; $result = mysql_query($sql) or die ("Error in page sql query:". $sql); return $pageSet; } ?> Code: [Select] <?php require_once ''.$_SERVER['DOCUMENT_ROOT'].'/duff3/commonResources/dbConnection/dbQueryClass.php'; ?> <?php #FUNCTIONS IS A TEMP FILE UNTIL OO PHP COMES INTO PLAY require_once ("commonResources/includes/functions.php"); # if page isn't set then set it to default. if(isset($_GET["page"])) { $selectedPage = $_GET["page"]; } else { $selectedPage = 1; } #call function to select all page $pageSet = getPageContent($selectedPage); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> <?php while ($row = mysql_fetch_array($pageSet)) { # Start while loop echo $row["pageTitle"]; ?> </title> <link rel="shortcut icon" href="commonResources/images/container/favicon.ico" /> <link rel="stylesheet" type="text/css" href="<?php $_SERVER["DOCUMENT_ROOT"] ?>/duff3/commonResources/css/style.css" /> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /> <!-- PUT COMMON JAVASCRIPT FILES IN AN INCLUDE 05/05/2011 --> <script type="text/javascript" src="commonResources/javaScript/jQuery.js"></script> <script type="text/javascript" src="commonResources/javaScript/jQueryTest/menu.js"></script> <?php require_once ("".$_SERVER["DOCUMENT_ROOT"]."/duff3/commonResources/includes/tinymce.php"); ?> </head> <body> <div id="viewContainer"><!--OPEN DIV FOR VIEW CONTAINER --> <div id="headerContent"><!--OPEN DIV FOR HEADER CONTENT --> <div class="logoContent"><!--OPEN DIV FOR LOGO CONTAINER --> <a href="index.html"><img src="<?php $_SERVER["DOCUMENT_ROOT"] ?>/duff3/commonResources/images/container/logo.png" alt="Hannah Jane Duff" longdesc="Hannah Jane Duff Home Link" /></a> </div><!--CLOSE DIV FOR LOGO CONTAINER --> </div><!--CLOSE DIV FOR HEADER CONTENT --> <!-- TEMP TAKE OUT AND PUT INTO HEADER AREA --> <div id="mainContent"><!--OPEN DIV FOR MAIN CONTENT--> <div class="centreContent"><!--OPEN DIV FOR CENTRE CONTENT--> <div id="menuContent"><!--OPEN DIV FOR MENU CONTENT--> <div id="menu"> <ul class="menu"> <li><a href="index.html" class="main"><span>Home</span></a></li> <li><a href="" class="main"><span>bio</span></a> <div><ul> <li><a href=""><span>violin</span></a></li> <li><a href=""><span>piano</span></a></li> <li><a href=""><span>singing</span></a></li> <li><a href="" class="parent"><span>teaching</span></a> <div><ul> <li><a href="" class="parent"><span>aberdeen</span></a> <div><ul> <li><a href="#"><span>aberdeen 1</span></a></li> </ul></div> </li> <li><a href="" class="parent"><span>bradford</span></a> <div><ul> <li><a href=""><span>bradford 1</span></a></li> </ul></div> </li> <li><a href="" class="parent"><span>leeds</span></a> <div><ul> <li><a href=""><span>leeds 1</span></a></li> </ul></div> </li> </ul></div> </li> <li><a href="" class="parent"><span>influences</span></a> <div><ul> <li><a href=""><span>classical</span></a></li> <li><a href=""><span>folk</span></a></li> </ul></div> </li> <li><a href="" class="parent"><span>other</span></a> <div><ul> <li><a href=""><span>folk′d</span></a></li> <li><a href=""><span>string quaret</span></a></li> </ul></div> </li> </ul></div> </li> <li><a href="" class="main"><span>publicity</span></a> <div><ul> <li><a href="" class="parent"><span>news</span></a> <div><ul> <li><a href=""><span>may 2011</span></a></li> <li><a href=""><span>march 2011</span></a></li> </ul></div> </li> <li><a href=""><span>gallery</span></a></li> <li><a href=""><span>other</span></a></li> </ul></div> </li> <li><a href="" class="main"><span>recordings</span></a> <div><ul> <li><a href=""><span>all</span></a></li> <li><a href=""><span>new york dolls</span></a></li> <li><a href=""><span>classical</span></a></li> </ul></div> </li> <li><a href="" class="main"><span>contact</span></a></li> </ul></div> </div><!--CLOSE DIV FOR MENU CONTENT--> <div class="paraBlock"><!--OPEN DIV FOR PARA BLOCK --> <p><?php echo $row["pageContent"]; ?></p> </div><!--CLOSE DIV FOR PARA BLOCK--> <div class="clearArea"><!--OPEN DIV FOR CLEAR AREA--> </div><!--CLOSE DIV FOR CLEAR AREA--> </div><!-- CLOSE DIV FOR CENTRE CONTENT--> </div><!--CLOSE DIV FOR MAIN CONTENT--> <div id="footerContent"><!--OPEN DIV FOR FOOTER CONTENT--> <div class="leftFooter"><!--OPEN DIV FOR LEFT FOOTER--> © <?php echo date(Y); ?> All Rights Reserved | Design by <a href="http://www.innovationation.co.uk/">Innovationation UK</a> </div><!--CLOSE DIV FOR LEFT FOOTER--> <div class="rightFooter"><!--OPEN DIV FOR RIGHT FOOTER--> <a href="">Copyright | </a> <a href="">Disclaimer | </a> <a href="">Privacy Policy </a> <a href="">Terms of Use | </a> <a href="">Site Map | </a> <a href="loginArea/login.php">Admin</a> </div><!--CLOSE DIV FOR RIGHT FOOTER--> </div><!--CLOSE DIV FOR FOOTER CONTENT--> <?php } ?> </div><!--CLOSE DIV FOR VIEW CONTAINER--> </body> </html> I've tried various sort methods on this array. And seem to be failing. Code: [Select] Array ( [monkey quest] => 8 [monkey] => 2 [monkey sports] => 0 [monkey go happy] => 0 [monkey go happy 3] => 1 [monkey joes] => 0 [monkey games] => 2 [monkey bread recipe] => 1 [monkey go happy 2] => 3 [monkey quest trailer] => 4 [monkey quest guide] => 5 [monkey quest nick] => 6 ) What I want to do or attempt to do rather is sort the array by the => value from highest to lowest (or maybe in reverse as well, but one thing at a time) My last failed attempt I was trying out usort() as my concept.. Code: [Select] function cmp($a, $b) { if ($a == $b) { return 0; } return ($a < $b) ? -1 : 1; } echo "<pre>"; print_r(usort($kw, "cmp")); echo "</pre>"; But the only thing I am left with on the page is just 1 everything else seems to be getting lost, or I dunno whats going on. So I think I've done stumped my self. Now I'm looking for idea's assuming I am tackling this all wrong. 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 phpsaneHaving problem with a bit of code. I am trying to fetch data from the database, I have used mysql_fetch_array before, and even in later bits of code. I want to use this data for an IF statement later on. The IF statement isn't there, because this code is catching somewhere. The fetch array is working fine, and it echos out the correct row in database that it should. The issue, it stops displaying code that follows it. In the code, I have put a comment (// Code kills here ....) where the code is killing. I have identified the few lines of code that is killing the script. You can see the page.. The number 71 is what is supposed to be supplied by the query and array. This is the page as it is with the trouble code. Here is the page without the trouble bit of code, and it displays all that it should. But it doesn't have the functionality I want to build in with the array obviously. Here is the code with highlight bit of trouble: /source/userinfo.php Code: [Select] <?php include ("db.php"); $get_info = mysql_query ("SELECT * FROM registrations WHERE u_id=$uid AND appid=$appid" , $link2); //Begin Trouble Code while ($check = mysql_fetch_array($get_info)) { echo $check['assign_id']; } //End Trouble Code // Code kills here, for some reason.... Proper assign_id displayed, but it kills script. $count = mysql_num_rows($get_info); if ($count >= 1) { $get_jos_info = mysql_query ("SELECT * FROM jos_users WHERE id=$appid" , $link); $get_avatar = mysql_query ("SELECT * FROM jos_comprofiler WHERE user_id=$appid" , $link); while ($avatar_link = mysql_fetch_array($get_avatar)) $avatarurl = $avatar_link['avatar']; echo $avatar_link['avatar']; echo "<table border='0' width='70%' align='center' cellpadding=5>"; while ($rowteam = mysql_fetch_array($get_info)) { while ($rowjos = mysql_fetch_array($get_jos_info)) { $urlbegin = "<img src='http://versionxlegends.com/images/comprofiler/tn"; $urlend = "'>"; echo "<tr><td width=100% align=center colspan=2>".$urlbegin.$avatarurl.$urlend."</td></tr>"; echo $avatar; echo "<tr><td width=40% align=right><strong>Registration #</strong></td><td width=60% align=center>$rowjos[id]</td></tr>"; echo "<tr><td width=40% align=right><strong>User's Username</strong></td><td width=60% align=center>$rowteam[username]</td></tr>"; echo "<tr><td width=40% align=right><strong>User's Name</strong></td><td width=60% align=center>$rowteam[name]</td></tr>"; echo "<tr><td width=40% align=right><strong>Provided Skype Username</strong></td><td width=60% align=center>$rowteam[skype]</td></tr>"; //Add script for lead only view Email Address. Team Member, field is hidden. Lead sees email and a YES/NO if email matches. If not, lead will email user to get email verification, to edit account before assignments occur. echo "<tr><td width=40% align=right><strong>E-Mail Address</strong></td><td width=60% align=center>$rowteam[email]</td></tr>"; echo "<tr><td width=40% align=right><strong>Registration Date</strong></td><td width=60% align=center>$rowjos[registerDate]</td></tr>"; // Add script for lead only view age. Team Member, field is hidden. Lead sees birthdate and/or age and a YES/NO if age matches. If not, lead will email user with ID verification e-mail, to verify age before assignments occur. echo "<tr><td width=40% align=right><strong>Age</strong></td><td width=60% align=center>$rowteam[age]</td></tr>"; }} echo "</table>"; } else { echo "Invalid URL. Registration does not exist"; } ?> This code is included within this page: viewregistration.php Code: [Select] <?php session_start(); $user_id = $_SESSION['user_id']; $uid = $_GET['u_id']; $appid= $_GET['appid']; include ("db.php"); $get = mysql_query ("SELECT * FROM registrations WHERE u_id = $uid AND appid=$appid", $link2); echo $get; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /> <title>Nuke Ice By ThemeKings</title> <link rel="stylesheet" type="text/css" href="nuke-ice.css" /> </head> <body> <div id="wrapper"> <div id="banner"> <div id="banner-edit"></div> </div> <div id="container"> <?php include ("sidebar.php"); ?> <div id="col-2"> <?php $uid = $_GET['uid']; $appid= $_GET['appid']; ?> <div class="CntBox"> <div class="CntHead"> <div class="CntHeadInfo">User Information</div> </div> <div class="CntFill"> <div class="CntInfo"> <?php include ("./source/userinfo.php"); ?> </div> </div> <div class="CntFooter"></div> </div> I included this bit of code so you can see some of the variables that were assigned in another file. Hi all, I'm new to PHP have written some code to extract data from mysql. here it is <!DOCTYPE html> <html lang="en"> result 1.png 18.34KB 0 downloads result 2.png 24.62KB 0 downloads Table.png 4.61KB 0 downloads <head> <meta charset="utf-8" /> <title></title> </head> <body> <?php echo "Testing Database....<br>"; $con = mysqli_connect('localhost', 'db_id', 'my_pw', 'mysql_db'); $result = $con->query("SELECT user_id FROM users"); echo "Number of users : ".$result->num_rows."<br><br>"; $row = mysqli_fetch_row($result); echo $row[0]."<br>"; echo $row[1]."<br>"; echo $row[2]."<br>"; ?> </body> </html> in result number of rows its giving right, but when i fetch the result in row, its giving only first row. rest all are empty. then further i have tested few more things like, i change the query as below 'SELECT * FROM users' now this is giving another strange result. It selected first row of the table and making array for all available columns. i have attached herewith image of my table, and result of both of my queries. Could someone guide me on this issue... <?php require("connection.php"); $query = 'SELECT * FROM job_post WHERE id_jobpost= :Id'; $start = $bdd->prepare($query); $start->execute(array(':Id' => $_GET['id_jobpost'])); $result = $start->fetch(); foreach ($result as $results) { $jobtitle = $result['jobtitle']; $id_jobpost = $result['id_jobpost']; $description = $result['description']; } ?> https://prnt.sc/uk3913 Whats wrong with this code Hi, I am trying to fetch all data from database. but any data show twice. like this: Ali Ali 30 30 Osman Osman 20 20 Omer Omer 40 40 Salim Salim 10 10 Suzan Suzan 25 25 $mem_qry = "SELECT * FROM tbl_name"; $res = mysql_query($mem_qry); function mysql_fetch_all($res) { $return = array(); while($row=mysql_fetch_array($res)) { $return[] = $row; } return $return; } $all = mysql_fetch_all($res); foreach($all as $k=>$v) { foreach($v as $k2=>$v2){ echo $v2.'<br />'; } } Im not sure where to post this but since it includes php il post it here instead of in the mysql forum. ok so, i have a table and i get the values using while($row = mysql_fetch_array($result)){ and then echo them in rows. that works fine but i need to add a class to the last row of my table. I would need somehow to fetch the last row of the array and make it echo something different. Any help is appreciated Thank you Basically, I have the following code ($c2 is my connection variable): Code: [Select] $rid = $_GET['id']; $q = mysql_query("SELECT * FROM reports WHERE id = $rid", $c2) or die(mysql_error()); $report = mysql_fetch_array($q); $report is used later on to gather more information that is outputted to the user. However, if in the URL, someone were to put id=1', they would have an error message spit out to them (something along the lines of: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'' at line 1), indicating a SQL Injection exploit. How would I go about fixing this, and also preventing SQL Injection? Thanks a bunch, Mark Hello i want to fetch the content from my MySQL db for one table and show it on a page, i'm using this code: Code: [Select] <?php include("inc/connect.php"); ?> <?php $result = $_REQUEST['result']; ?> Code: [Select] <?php $query = mysql_query("select * from listtest order by id asc"); while($result = mysql_fetch_array($query)) { ?> <tr> <td><?php echo $result['id']; ?></td> <td><?php echo $result['code']; ?></td> <td align="center"><a href="edit.php?id=<?php echo $result['id']; ?>">View</a></td> <td align="center"> </td> </tr> <?php } ?> it's throwing me this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in 32qgtf.php on line 30 What am i doing wrong ? /Edit: line 29/30 is the mysql query / fetch. Hi guys, Im having problem on how to achieved this one.. I would like to get the all event of this month (April ) Starting todays date.. Code: (php) [Select] $now = gmdate("Y-m-d", mktime(gmdate("H")+8, gmdate("i"), gmdate("s"), gmdate("m"), gmdate("d")+8, gmdate("Y"))); $week = gmdate("Y-m-d", mktime(gmdate("H")+8, gmdate("i"), gmdate("s"), gmdate("m"), gmdate("d")+30, gmdate("Y"))); if ($result = mysql_query("SELECT * FROM fiesta WHERE sta_date BETWEEN '$now' AND '$week' ORDER BY sta_date LIMIT 10")){ if (mysql_num_rows($result)) { $return = ''; while ($row = mysql_fetch_array( $result )) { $date = date("D",strtotime($row["sta_date"])); $return .= "<a href='sta.php' style='font-size:11px;' title='" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "'>" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "</a> ($date), "; } echo rtrim($return, ', '); } } The result of this query will include the events on May.. How can i display only the event on this month(April)? starting todays date. Thank you Hey guys tried to search for this but didn't find anything usefull about the issue. So what i have is mssql_fetch_array in a while loop in the loop i have it assign a specified row as a variable that i can print later on in the page. Code: [Select] while($row = mssql_fetch_array($query) { $tables = "<tr>"; $tables .= "<td> {$row['specifiedrow']} </td>"; $tables .= "</tr>"; }Then i call it in the html table as Code: [Select] <? php echo $tables; ?> I have done this with mysql_fetch_array before and it would print the entire database row associated with that row in the table. But as it is now it only returns the last row from the database. Is there something i am missing. Thanks for any help Hi, I've used this code before, but have had to make some modifications and am now getting a mysql fetch array error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/tesolcla/public_html/test/results10k201010.php on line 134 If anyone can help, it would be much appreciated. Code: [Select] <?php $dbcnx = @mysql_connect('localhost', 'MYUSERNAME', 'MYPASSWORD'); //$dbcnx = @mysql_connect('localhost', 'root', 'mysql'); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('MYDATABASE')) { //if (!@mysql_select_db('rac')) { exit('<p>Unable to locate the results ' . 'database at this time.</p>'); } $asc_on = '<img src="images/results_sorting/Asc.gif" border="0" />'; $asc_off= '<img src="images/results_sorting/AscOff.gif" border="0" />'; $desc_on = '<img src="images/results_sorting/Desc.gif" border="0" />'; $desc_off= '<img src="images/results_sorting/DescOff.gif" border="0" />'; $sortfield = isset($_GET['sort']) ? $_GET['sort'] : '4'; $sorttype = isset($_GET['type']) ? $_GET['type'] : '1'; for($i=1; $i<5; $i++) { if($i==$sortfield) { if ($sorttype==1) $srt[$i] = $asc_on.'<a href="?sort='.$i.'&type=2">'.$desc_off.'</a>'; else $srt[$i] = '<a href="?sort='.$i.'&type=1">'.$asc_off.'</a>'.$desc_on; } else { $srt[$i] = '<a href="?sort='.$i.'&type=1">'.$asc_off.'</a><a href="?sort='.$i.'&type=2">'.$desc_off.'</a>'; } } $fields = array("firstname", "lastname", "time", "position"); $sorts = array("ASC", "DESC"); $field = $fields[$sortfield-1]; $sort = $sorts[$sorttype-1]; $field = $field=="" ? $fields[4] : $field; $sort = $sort=="" ? $sorts[0] : $sort; $sql = mysql_query("SELECT firstname, lastname, time, position FROM 10k_results ORDER BY $field $sort"); echo "<table border='1' align='center' bordercolor='#000000' CELLPADDING=5 cellspacing='0' STYLE='font-size:13px'>"; echo "<tr bgcolor='#008000' STYLE='color:white'> <td>*</td><td><H3>First name $srt[1]</h3></td> <td><H3>Lastname $srt[2]</H3></td> <td><H3>Time $srt[3]</H3></td> <td><H3>Position $srt[4]</H3></td></tr>"; // keeps getting the next row until there are no more to get $row_counter = 1; //create row counter with default value 0 // Print out the contents of each row into a table while ($row = mysql_fetch_array($sql)) { // Print out the contents of each row into a table echo "<tr>\n"; echo "</td><td>"; echo $row_counter++; echo "</td>"; echo "<td>{$row['firstname']}</td>\n"; echo "<td>{$row['lastname']}</td>\n"; echo "<td>{$row['time']}</td>\n"; echo "<td>{$row['position']}</td>\n"; echo "</tr>\n"; } echo "</table>"; ?> //my controller <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use DB; class homeController extends Controller { public function index() { $employee = DB::table('employee')->orderBy('id','desc')->get(); $department = DB::table('department')->orderBy('id','desc')->get(); return view('index', ['employee' => $employee , 'department' => $department]); } } //my routes Route::get('index','homeController@index'); //my view using blade temmplating engine @foreach($employee as $emp) <div class="employee"> <b>{{ $emp->name }} </b> <a href="employee/{{ $emp->id }}"> <p class="intro">{{ substr($emp->intro ,0, 50) }}...</p> </a> </div> @endforeach @foreach($department as $dep) <div class="department"> <b>{{ $dep->name }} </b> <a href="department/{{ $dep->id }}"> <p class="desc">{{ substr($dep->description ,0, 100) }}...</p> </a> </div> @endforeach I want to fetch using ajax, how can i do it, teach/help me I am trying to create a simple calendar where a user can add/remove their availability date. This part works so far. Now what I am having trouble with is highlighting the already selected dates that are fetched from a MySQL database.
Here's my code. // HTML <div id="datetimepicker1"></div> // Jquery/Ajax <script> $(document).ready(function () { $('#datetimepicker1').datepicker({ dateFormat: "yy-mm-dd", multidate: true, onSelect: function () { var getDate = $("#datetimepicker1").val(); $.ajax({ type: "POST", //or GET. Whichever floats your boat. url: "snippets/adapter-set.php", data: { date: getDate }, success: function(data) { // alert(data); }, error: function() { alert("Error."); } }); } }); }); </script> // PHP // adapter-set.php $post_date = $_POST['date']; $find_query = $db->prepare("SELECT user_id FROM user_dates WHERE date_available = :date_available"); $find_query->bindParam(':date_available', $post_date); $find_query->execute(); $result_find = $find_query->fetchAll(PDO::FETCH_ASSOC); if(count($result_find) > 0) { foreach($result_find as $row) { $user_id = $row['user_id']; } $delete_query = $db->prepare("DELETE FROM user_dates WHERE user_id = :user_id"); $delete_query->bindParam(':user_id', $user_id); $delete_query->execute(); $result_delete = $delete_query->execute(); if($result_delete == false) { echo 'delete false'; } else { echo 'delete success'; } } else { $insert_query = $db->prepare("INSERT INTO user_dates(date_available) VALUES(:date_available)"); $insert_query->bindParam(':date_available', $post_date); $result_insert = $insert_query->execute(); if($result_insert == false) { echo 'insert false'; } else { echo 'insert success'; } }
The above code works fine. It inserts and deletes a date row in MySQL database table based on a click. Now what I would like to do is to highlight all the "available" dates that are already inserted into the database; so that the user knows which dates he has already selected. This is my code for that. But it doesn't seem to be working. No errors. It's just not highlighting the inserted dates. Can you tell me what I'm doing wrong? // JQUERY <script> $(document).ready(function() { $.post('snippets/adapter-fetch.php', {}, function(data){ $("#datetimepicker1").datepicker({ datesEnabled : data.datesEnabled }); }, 'json'); }); </script> // PHP // adapter-fetch.php $global_user_id = 5; $find_query = $db->prepare("SELECT date_available FROM user_dates WHERE user_id = :user_id"); $find_query->bindParam(':user_id', $global_user_id); $find_query->execute(); $result_find = $find_query->fetchAll(PDO::FETCH_ASSOC); if(count($result_find) > 0) { foreach($result_find as $row) { $date_available = $row['date_available']; echo $date_available; } } else { echo 'not dates available'; }
Hello, I have this simple php form that updates the table, and also shows what the information in it is. Here it is: <strong>Update multiple rows in mysql</strong><br> <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="test_mysql"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center"><strong>Month</strong> <strong>Date</strong> </td> <td align="center"><strong>Lastname</strong></td> <td align="center"><strong>Email</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td> <td align="center"><input name="month[]" MAXLENGTH="3" size="3" type="text" id="month" value="<?php echo $rows['month']; ?>">- <input name="date[]" MAXLENGTH="2" size="2" type="text" id="date" value="<?php echo $rows['date']; ?>"> </td> <td align="center"><input name="lastname[]" type="text" id="lastname" value="<?php echo $rows['lastname']; ?>"></td> <td align="center"><input name="email[]" type="text" id="email" value="<?php echo $rows['email']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if (isset($_POST['Submit'])) { for($i=0;$i<$count;$i++){ $month = $_POST['month']; $date = $_POST['date']; $lastname = $_POST['lastname']; $email = $_POST['email']; $name = $month."<br>".$date; $sql1="UPDATE $tbl_name SET name='$name[$i]', month='$month[$i]', date='$date[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update2.php"); } ?> <?php $result = mysql_query("SELECT * FROM test_mysql") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Age</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['name']; echo "</td><td>"; echo $row['lastname']; echo "</td></tr>"; } echo "</table>"; ?> What it does is this, it gets the row from the database, echos it and I am able to edit it and then save. The thing is, it works with the updating but im trying to combine 2 variables into 1 and update that one also. Im trying to combine month and date textboxes into one variable in the database that is name. It for some reason updates the column name to A instead of what I had in the 2 fields month and date. Here is where I combine both fields into one. $name = $month."<br>".$date; And here is where $month and $date is set. $month = $_POST['month']; $date = $_POST['date']; Here is a picture. Hello, So I have a weird error where if I fetch more than a certain number of rows from a mysql table, it triggers a 500 Internal Server Error. I am using Apache Web Server (through GoDaddy) and the offending code is below: Code: [Select] set_time_limit(0); $this->Connect(); $Output = array(); $search = "SELECT * FROM <table> WHERE user_id = ?"; if($Statement = $this->MySQLi->prepare($search)){ $Statement->bind_param("i", $UserId); $Statement->execute(); $Statement->bind_result(<result variables>); $count = 0; while($Statement->fetch() && $count++ < 70){ ChromePhp::log(<result variables>); } $Statement->close(); } $this->Disconnect(); ChromePhp::log is a way of dumping things to the Javascript Console in your browser from within a PHP script just as a heads-up. So when I set the stop number as 70, everything is fine. If I try to fetch more than that it triggers a 500 internal server error on Apache Server port 443. I have looked through the error logs and can't figure out the cause but this is almost certainly a server configuration issue? I'd appreciate any feedback, especially anyone familiar with GoDaddy's hosting services Thanks |