I have a login page written in php and I want to pass the query to a jar file ,the java jar file should check the query sent by php for some keywords ,can someone help me please!
thanks.
this is a part of my php code
<?php
$username=$_POST['username'];
$password=$_POST['password'];
if($username&&$password)
{
$connect=mysql_connect("localhost","root","123") or die("Couldnt connect to Database");
mysql_select_db("test") or die("Couldnt find Database");
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
exec("java -jar QuerySignature.jar $query");
$numrows = mysql_num_rows($query);
if($numrows!==0)
{
while($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword=$row['password'];
}
if($username==$dbusername&&$password==$dbpassword )
{
echo "You are logged in!";
I excuted the jar file and sent the $query as an argument I want the java program to read the query it self NOT the return value
exec("java -jar QuerySignature.jar $query");
Am I doing right here?
and this is my java program
QuerySignature.java
public static void main (String a[])
{ QuerySignature q1= new QuerySignature();
String s = "select * from employee where id=20 and name='Angel' or age=20";
String QueryKey = q1.Msg_Init(s);
try {
q1.Msg_Md5(QueryKey);
} catch (Exception e) {}
I want to know, how to execute the passed argument from php instead of this line in my java program:
"select * from employee where id=20 and name='Angel' or age=20";
Sorry ,I know I am being annoying here ..but help me out and thank u.
Related
Is there a way to dynamically specify a file name in the LOAD DATA INFILE? Can it be parameterized like for instance (syntax may be incorrect) LOAD DATA INFILE '$filename'?
A citation from MySQL documentation:
The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. The file name must be given as a literal string.
That means that it can not be a parameter of a prepared statement. But no one forbids to make the string interpolation while the statement is just a string in your PHP code.
Unfortunately, this feature is not yet supported in MySQL and is currently listed as bug/feature request #39115 http://bugs.mysql.com/bug.php?id=39115
Or you can make a temporary copy of the file (BATCH example):
LOAD_DATA.bat
COPY %1 TempFileToLoad.csv
mysql --user=myuser --password=mypass MyDatabase < ScriptLoadMyDatabase.sql
DEL TempFileToLoad.csv
the SQL (for info) :
ScriptLoadMyDatabase.sql
load data infile 'TempFileToLoad.csv' IGNORE
into table tLoad
FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"'
lines terminated by '\r\n'
IGNORE 1 LINES
(#DateCrea, NomClient, PrenomClient, TypeMvt, #Montant, NumeroClient)
set DateCrea = str_to_date(#DateCrea, '%Y-%m-%d'), Montant = (round(#Montant / 1000)*2) ;
And finished to put a link to the BAT file in SendTo windows folder.
If you're asking if it can be used in a script; you can do some thing like this with php:
<?php
$mysqli = new mysqli("host", "user", "pwd", "db");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sql = "CREATE TABLE number1 (id INT PRIMARY KEY auto_increment,data TEXT)";
if ($result = $mysqli->query($sql)) {
} else {
printf("<br>%s",$mysqli->error);
}
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$filename = "data.csv";
$sql = "LOAD DATA LOCAL INFILE '$host$uri$filename' INTO TABLE number1";
if ($result = $mysqli->query($sql)) {
} else {
printf("<br>%s",$mysqli->error);
}
// Close the DB connection
$mysqli->close();
exit;
%>
If the file is in the same folder as the script just use $filename a instead of $host$uri$filename. I put this together quick from a couple scripts I'm using, sorry if it doesn't work without debug, but it should be pretty close. It requires mysqli.
Like the question states, I would like to create a new directory in the "Users" folder on the server when a user registers their account.
PHP:
$username = $_POST['username'];//STRING
$username = strip_tags($_POST['username']);
$username = stripslashes($_POST['username']);
$username = mysqli_real_escape_string($conn,$_POST['username']);
etc.
etc.
$sql = "INSERT INTO tbl_users
VALUES ('$username', '$password', '$countryCode','$mobileNumber','$email','$profilePicture','$fname','$mname','$lname','$gender','$birthday','$occupation','$signupdate',0)";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully in tbl_users";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
I'm quite new to php and I don't really understand how most of the commands work.
I am making an app in java and I want the onClick to add data to a database as well as create the following file hierarchy:
Users(Already there)
Username(Of user registering)
Media
Pictures
Videos
Audio
To add a directory in "Users" folder,You can add this code:
mkdir("Users/new_folder",0755);
I'm attempting to retrieve multiple values from a database through php to my android java in eclipse.
I'm managing to get all variations of json arrays except the one i need.
My database is:
**Aircraft** **Status**
A870_870 1
A870_871 1
A870_872 1
A870_873 1
A870_874 1
A870_875 1
A870_876 2
A870_877 1
A870_878 2
A870_879 2
A870_880 2
A870_881 0
A870_882 0
A870_883 0
A870_884 0
A870_885 0
The format I need so that my android app reads it is:
{"A70_870":"1","A70_871":"1","A70_872":"1","A70_873":"1","A70_874":"1",
"A70_875":"1","A70_876":"2","A70_877":"1","A70_879":"2","A70_878":"2",
"A70_880":"2","A70_881":"0","A70_882":"0","A70_883":"0","A70_884":"0",
"A70_885":"0"}
I've been attempting different 'while' loops all sorts of other variations and manage to get all sorts of combinations except the one i need. Surely there is a way...?
My closest PHP attemp is below:
<?php
$con = mysqli_connect("localhost","root","", "mytestdatabase");
if (mysqli_connect_errno()) {
echo 'Database connection error: ' . mysqli_connect_error();
exit();
}
$userdetails = mysqli_query($con, "SELECT *FROM aircraft_status");
$row = mysqli_fetch_row($userdetails) ;
$result_data = array(
'A70_870'=>$row[1],
'A70_871'=>$row[1],
'A70_872'=>$row[1],
'A70_873'=>$row[1],
'A70_874'=>$row[1],
'A70_875'=>$row[1],
'A70_876'=>$row[1],
'A70_877'=>$row[1],
'A70_879'=>$row[1],
'A70_878'=>$row[1],
'A70_880'=>$row[1],
'A70_881'=>$row[1],
'A70_882'=>$row[1],
'A70_883'=>$row[1],
'A70_884'=>$row[1],
'A70_885'=>$row[1],);
echo json_encode($result_data);
?>
It gives the correct format, but obviously only reads row 1. I can't access 3,5,7 etc..
If anyone can assist me in this it would be great!! :) I'm sure its something simple I'm not doing right....
I might be missing something but is it not just wrapping result extraction in a while loop:
$userdetails = mysqli_query($con, "SELECT *FROM aircraft_status");
$result_data = array();
if ($userdetails) {
while($row = mysql_fetch_array($userdetails)) {
// $row[0] being aircraft and $row[1] being status
array_push($result_data , $row[0], $row[1]);
}
}
else {
echo mysql_error();
}
echo json_encode($result_data);
My PHP is very rusty, so might need adjustments. Hope this gets you on the way.
I'm trying to call a bash script within a oracle database through a java script. To test it I just tried a basic script :
#!/bin/bash
echo "It works !"
And the java script that I use is :
import java.lang.*;
import java.io.*;
public class UAM_TOOLS{
public static String Toto () throws IOException {
String[] unixCommand = {"/home/oz380/toto.sh"};
String pwd;
Process p = Runtime.getRuntime().exec(unixCommand);
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
pwd = input.readLine();
input.close();
return pwd;
}
};
I granted all the permissions that had to be granted and I created the function in my database :
SQL> CREATE OR REPLACE FUNCTION TOPI RETURN VARCHAR2
2 as language java
3 name 'UAM_TOOLS.Toto() return java.lang.String';
4 /
But then when I call the function :
select TOPI from dual;
or :
SQL> set serveroutput on;
SQL> DECLARE
2 G VARCHAR2(50);
3 BEGIN
4 G := UAM.TOPI;
5 DBMS_OUTPUT.PUT_LINE(G);
6 END;
7 /
It doesn't work and prints the error :
ORA-29541: class UAM.UAM_TOOLS could not be resolved
I don't really understand what the problem can be. If anyone does I would be really thankful.
Before the
CREATE FUNCTION
step you need to compile your class at command line
$>javac UAM_TOOLS.java
or using an IDE sth like Eclipse
that will generate compiled class with .class extension. For your case it will be UAM_TOOLS.class
And you still need to upload it to database on command line where the host which db runs on it
$>loadjava -user yourUserName/youPass#Yourdb UAM_TOOLS.class
after that 2 step you can resume with create function step.
Spaces not changing to underscored when sent from Java-->PHP-->SQL
Java code:
String urlString = "http://www.mysite.com/auth/verifyuser.php?name="+name.toLowerCase().replace(" ","_");
PHP code:
$name = mysql_real_escape_string($_GET['name']);
$name = str_replace(' ', '_', $name);
$query = "select * from authinfo where name LIKE '$name'";
mysql_query($query);
$num = mysql_affected_rows();
if ($num > 0) {
echo '1';
} else {
echo '0';
}
when I implement a test log on the SQL database, it somehow still seems to show up with spaces instead of underscores(even though I replace it in Java and PHP) and the PHP file returns '0' rather than '1'. I've heard the issue might be whitespaces? It seems to happen to only certain users, mostly mac users.
If your php file is returning a 0, that means your query is not getting executed. Where are you establishing a connection with the database before executing the query?
Remark: where name = '$name'
mysql_affected_rows concerns INSERT, UPDATE and DELETE.
$r = mysql_query($query);
$num = mysql_num_rows($r);
It's unsafe to pass raw name into URL without encoding it.
String urlString = "http://www.example.com/auth/verifyuser.php?name=" + URLEncoder.encode(name.toLowerCase(), "UTF-8");
In PHP you can obtain data:
$name = urldecode($_GET['name']);