Pablo Emilio Esc
Pablo Emilio Esc

Reputation: 23

How to send text with space from Android to MySQL database

Hello I'm new in Android and I wanna send a text from Android with space (" My Name is Oliver Queen ") to MySQL database. I use this script in PHP:

<?php
$servername = " ";
$username = " ";
$password = " ";
$dbname = " ";

$id=$_GET['id'];
$project=$_GET["a"];

// Create connection..

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn->connect_error) {

 die("Connection failed: " . $conn->connect_error);

} 
//echo "$project";

$sql= $sql= "UPDATE user SET project = \"$project\" WHERE id= '$id'";  

$result = $conn->query($sql);

$conn->close();

?>

In MySQL I found only ("My") The first word before space! Plzz someone Help Mee !!!!!!

Upvotes: 2

Views: 256

Answers (2)

Carmageddon
Carmageddon

Reputation: 2849

Check the value of $project variable; My bet is that you send values over a GET request, and not properly encoding them.

If your $project value is indeed "My" like I guess, then look up on you Android part, and look up on how to do url encoding (should be very simple in Java) - look for the equivalent of http://php.net/manual/en/function.urlencode.php - this should resolve your problem.

Also after you get it working, modify the code to deal with SQL Injections, switch to using PDO for DB access, and prepared statements, this would increase the security of your code.

Upvotes: 1

Mohammad
Mohammad

Reputation: 3547

first of all, you should fix your query by using single quotes around the varchar attribute not the numeric, also pay attention to $sql = $sql = you declared it twice:

$sql= "UPDATE user SET project = '$project' WHERE id= $id";

then, you are trying to receive a string by GET method $project=$_GET["a"];, so your URL should be well encoded.

Upvotes: 1

Related Questions