Posts

Showing posts with the label mysql

SQL-EX.ru Exercise #36

SQL-EX.ru Exercise #36 I am trying to solve exercise #36 which is List the names of head ships in the database (taking into account Outcomes table) . Head ships are the names of ships that were first in line for that class (i.e. 2 ships but 1 build before another so the first ship is the "head ship"). My result says I did says the following: Your query returned the correct dataset on the first (available) database, but it returned incorrect dataset on the second checking database. * Wrong number of records (less by 1) My query is as follows: SELECT A.name FROM Ships A WHERE A.name = A.class AND A.launched = (SELECT MIN(B.launched) FROM Ships B WHERE A.name = B.name AND A.class = B.class) UNION ALL SELECT A.ship FROM Outcomes A WHERE A.ship IN (SELECT C.ship FROM Outcomes C, Classes D WHERE C.ship IN (SELECT ship FROM Outcomes) AND C.ship NOT IN (SELECT name FROM Ships) AND C.ship = D.class ...

Traversal tree - repair

Traversal tree - repair please, do you have any tips, where to find code or solution, how to repair traversal tree? I have table with cols lft, rgt, parent_ID and lvl and when I was moving nodes in this tree, I had fail in code so it broke lft and rgt indexes and I need to recount it. One solution, which I think is applicable is getting all nodes from table, store in array for example, clear table and recreate it, but this solution is not so efficient I think. Do you have any tips, how to solve it better? Thank you very much :) Please read: How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question? – Magnus Eriksson Jul 1 at 9:14 By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, p...

| have added MySQL Connector to libraries , but still getting error 'java.lang.ClassNotFoundException: com.mysql.jdbc.driver' [duplicate]

| have added MySQL Connector to libraries , but still getting error 'java.lang.ClassNotFoundException: com.mysql.jdbc.driver' [duplicate] This question already has an answer here: import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; /** * Servlet implementation class LoginChek */ @WebServlet("/LoginChek") public class LoginChek extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public LoginChek() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequ...

I want to restrict job seeker update/view his mysql data until admin panel approve his profile

I want to restrict job seeker update/view his mysql data until admin panel approve his profile This is the code I used but its for admins in the mysql not for a user(job seeker) in my website. REVOKE SELECT ON contacts FROM '*'@'localhost'; Where is the code and what do you want to achieve? – Nico Haase Jul 1 at 7:51 this makes very little sense – smith Jul 1 at 8:03 You have to restrict this feature on application level, not on database level, since I doubt that you create a separate mysql user acvount for each of your users. – Shadow Jul 1 at 8:23 ...

Display the name instead of the ID

Display the name instead of the ID Database setup: Table: customers id | name | address | zipcode | city | phone | email | active Table: todo id | customerid | description | information | active $sql = " SELECT * FROM todo ORDER BY `customerid` ASC , `description` ASC "; show results: echo $row['customerid'] $row['description'] $row['information']; output: customerid description information desired output: customername (from table customers) description information I have been reading this forum and i find that i should use INNER JOIN but i can't get it to work. Could anyone assist me? 2 Answers 2 First,you need use join to get the customername value join SELECT t.description,t.information,c.name FROM todo t JOIN customers c ON c.id=t.customerid ORDER BY `t.customerid` ASC, `description` ASC Then try with below: echo $row['name'] $row[...

Updating a database with a loop

Updating a database with a loop I have added a new column to a database and want to insert random values as temporary accesskeys into all rows. This is what I have (yes, I know there is no error reporting - can add that later): require ('./connect.php'); $length = 10; $db = mysqli_connect($db_hostname,$db_username,$db_password,"paratb_members"); $result = mysqli_query($db,"SELECT * FROM membervote where accesskey = ''"); while ($row = mysqli_fetch_array($result)) { $randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length); mysqli_query($db,"UPDATE membervote SET accesskey = '$randomString' WHERE accesskey = ''"); echo $row['fname']. " - $randomString<br>"; } While the echo gives me a unique value for each row, the database rows are all the same first value. Have tried using diffetrent WHERE values but then I get nothing written to the d...

How to access db in phpmyadmin in xampp [on hold]

How to access db in phpmyadmin in xampp [on hold] I downloaded the madrasa management software from Google. And I extracted this file and copied it in htdocs in xampp. Then I imported the madrasa management software backup file in phpmyadmin in xampp. Import has successfully completed. But I can't access the database in localhost. So please guide me on how to access this software. This question appears to be off-topic. The users who voted to close gave these specific reasons: Please read stackoverflow.com/help/how-to-ask – Franck Gamess Jul 1 at 6:52 Try to elaborate more and show which error you're facing. stackoverflow.com/questions/30255567/… – Drashti Pandya Jul 1 at 6:56 ...

PHP/MySQL time date variable calculations

PHP/MySQL time date variable calculations I have 2 variables, one a date like 06/02/2018 and a day interval that changes. I need to add the two together, then find the difference from the current date. I've read carbon can help with this but I'm stuck. say the vending machine was last filled on 6/20/2018 and it needs to be refilled every 30 days. I need to find out how many days from today it needs to be serviced. Please help Question is a bit unclear. Please explain more... – Roshana Pitigala Jul 1 at 5:35 This API was deprecated a very long time ago, so this is surely of archaeological interest only? – Strawberry Jul 1 at 6:24 ...

How to check if the entered fields already exists or not, during Updating data using mysql

How to check if the entered fields already exists or not, during Updating data using mysql Update.php <?php include_once("connection.php"); $name=$_REQUEST['name']; $email=$_REQUEST['email']; $mobno=$_REQUEST['mobno']; $id=$_REQUEST['id']; $checkemail="SELECT * FROM dhruv_users WHERE email= '$_REQUEST[email] AND id='$id'"; $checkmob="SELECT * FROM dhruv_users WHERE mobno= '$_REQUEST[mobno]' AND id='$id'"; $rsemail = mysqli_query($conn,$checkemail); $rsmob = mysqli_query($conn,$checkmob); $dataemail = mysqli_num_rows($rsemail); $datamob = mysqli_num_rows($rsmob); if($dataemail >= 1 && $datamob >= 1) { echo "data_exists"; } else{ $query=mysqli_query($conn,"update dhruv_users set name='$name',email='$email',mobno='$mobno' where id='$id'"); if($query){ ...

How can I communicate with other client connections on a MySQL server using python?

How can I communicate with other client connections on a MySQL server using python? I have multiple computers running python applications, each using the same MySQL server. Each of the applications contains a tkinter GUI that allows editing of a set of data (corresponding to data in a table in the MySQL server). Whenever the data is updated one machine (and in turn updated on the MySQL server), I would like the other machines to be prompted to update there displayed data by pulling from the server. I know I could simply have the applications self-update after a given interval, but I would prefer to only update when there is new data to pull. How should I go about this? sounds like you need to dig into MySql Triggers, maybe this answer would help stackoverflow.com/questions/17336804/… – kztd Jul 1 at 2:37 2 An...

MySQL Syntax error from INSERT INTO email address [duplicate]

MySQL Syntax error from INSERT INTO email address [duplicate] This question already has an answer here: I'm having trouble inserting an email address into a MySQL database. I'm getting the dreaded 1064 error like so.. Error creating new user You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '@email.com, password, 20)' at line 1 -- 1064 So I'm guessing I need to escape the @ in the email variable? But nothing i do seems to please Maria. Generating the query in PHPMyAdmin was no help either. Any advice gratefully accepted. // update SQL $sql2 = "INSERT INTO members (username, email, password, balance) VALUES ($new_player, $new_email, $new_password, 20)"; if ($db->query($sql2) == TRUE) { echo "** New User Created **<BR>"; } else { echo "Error creating new user " . $db->error." -- ...

ajax pagination - Can't get last table row

ajax pagination - Can't get last table row This code works perfectlly. But I can't get last row of the table. ex: My table had 9 rows but this displying only 8 rows, 1 row missing. Missing row is the last row when I use ASC or DESC. here's my code.. sorry my English not good. thank you! index.php <?php $db_username = 'root'; $db_password = ''; $db_name = 'ad_man'; $db_host = 'localhost'; $item_per_page = 2; $connecDB = mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('could not connect to database'); if($check_ad = mysqli_query($connecDB,"SELECT ad_uid FROM fullbanner WHERE ad_uid='501'")){ $countr=mysqli_num_rows($check_ad); if($countr>=1){ $pages = $countr/$item_per_page; //create pagination if($pages > 1) { $pagination = ''; $pagination .= '<ul class="paginate">'; for($i = 1; $i<$pages; $i++) ...

MySQL dynamic where clause with security focus

MySQL dynamic where clause with security focus I want to make a fully dynamic where clause as viewset. The where clause is fully implemented by the user and stored in a table. To get this working is easy but if have alook at security with this solution it's a big problem. This should be implemented as a stored procedure I have 2 tables: Table: Viewset (where clause stored): ID | Viewset<br> 1 | (a > 5) OR REGEX(...) etc. And a datatable. In the stored procedure it's working like this: This is ofc, fully vulnerable for SQL injections etc. Now I want to get this secure. I had 2 ideas. First: Just try to get any possible 'AND' and 'OR' connection and using a prepared statement at the end => Problem: I have around 100 possible combinations. Second idea: where clause through a whitelist of words and the values through prepared statements. Problem again: MySQL doesn't allow arrays and string splits etc. that makes this very hard to implement. Maybe th...

trying to display mysql data in an html text field

trying to display mysql data in an html text field I would like to be able to view and edit information contained within a table from my web browser however I can't for the life in me get the current values to pull though to an html text field. Can anyone shed any light as im quite new to php? Table name: request_details Column Names: id, name, email_address My PHP code is: <? $order = "SELECT * FROM request_details WHERE id='$id'"; $result = mysql_query($order); $row = mysql_fetch_array($result); ?> HTML Code <form method="post" action="edit_data.php"> <input type="hidden" name="id" value="<?php echo "$row[id]"?>"> <tr> <td>Name</td> <td> <input type="text" name="name" size="20" value="<?php echo "$row[name]"?>"> </td> </tr> <tr> ...

Laravel Eloquent how to join on a query rather than a table?

Laravel Eloquent how to join on a query rather than a table? I want to achieve this in Laravel: SELECT * FROM products JOIN (SELECT product_id, MIN(price) AS lowest FROM prices GROUP BY product_id) AS q1 ON products.id = q1.product_id ORDER BY q1.lowest; I wrote this, but clearly there is something wrong: $products = new Product(); $products = $products->join( Price::whereNotNull('price')->select('product_id', DB::raw('min(price) as lowest'))->groupBy('product_id'), 'products.id', '=', 'product_id' )->orderBy('lowest')->get(); The error I got: ErrorException in Grammar.php line 39: Object of class IlluminateDatabaseEloquentBuilder could not be converted to string. I'm currently using join(DB::raw('(SELECT product_id, MIN(price) AS lowest FROM prices WHERE price IS NOT NULL GROUP BY product_id) AS q1'), 'products.id', '=', 'q1.product_id') as a workaround. Just won...

PHP query using an association from another query

PHP query using an association from another query I am trying to INSERT into my SQL table in PHP using an association I already returned from a previous SELECT query. But the compiler is giving me a syntax error 'unexpected $EOF'. Essentially, this is what I am doing: $query2 = "SELECT * FROM users WHERE user_name='$user.username'"; $result2 = mysqli_query($db, $query2); $new_user = mysqli_fetch_assoc($result2); $query3 = "INSERT INTO new_table (new_user_id) VALUES('$new_user['user_id']');"; mysqli_query($db, $query3); Query 3 is the one giving me the error. I have referenced variables like this before with the fetch association. I'm incredibly new to PHP, but isn't that fetch by association just creating a dictionary? Any ideas? Thanks, Can you post the output of $new_user['user_id']? – Steve Mulvihill Jul 1 at 2:30 ...

Socket.io namespace stops working after 10 connections

Socket.io namespace stops working after 10 connections I'm using node.js, ejs, express, mysql and socket.io. My server looks like this (index.js): module.exports = function(io) { var express = require('express'); var router = express.Router(); var mysql = require('mysql'); var pool = mysql.createPool({ connectionLimit: 10, host: 'localhost', user: 'root', password: '', database: 'chat' }); router.get('/chat/:channel_name', (req, res, next) => { var channel_name = req.params.channel_name; // get the countries from the database so we make sure the users are connecting to the correct channel to chat, else redirect to /chat pool.getConnection((err, connection) => { if(err) return console.log(err); connection.query('SELECT * FROM channel WHERE channel_name = ?', channel_name, (err, rows) => { if(err) return console.log(err) if(!rows.length){ ...