Forum » Programiranje » [MySql]Sintaksa poizvedbe
[MySql]Sintaksa poizvedbe
KernelPanic ::
Spostovani!
Zgubljam zivce z sledecim enostavnim stavkom:
Lp,
M.
Zgubljam zivce z sledecim enostavnim stavkom:
SELECT id_customer, lastname, firstname FROM 'ps_customer' WHERE 'email=user@gmail.com' AND 'passwd=geslo'Namrec, na server strani imam skripto za logiranje uporabnika v bazo. Uporabnisko ime in geslo pa dobim iz Android aplikacije iz telefona. Debugiral sem in php skripta vrne namesto resource boolean vrednost (false), kar pomeni, da se stavek ni izvedel. Identicen stavek sem probal pognati direktno na mysql serverju in mi javi sledeco napako:
#1064 - 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 ''ps_customer' WHERE 'email=user@gmail.com' AND 'geslo' at line 1Kaj je narobe z sintakso? Vem, da je ena enostavna stvar, ampak enostavno ne najdem.
Lp,
M.
darkolord ::
SELECT id_customer, lastname, firstname FROM 'ps_customer' WHERE email='user@gmail.com' AND passwd='geslo'
KernelPanic ::
Ista napaka v /var/log/apache2/error.log. Tukaj je skripta:SELECT id_customer, lastname, firstname FROM 'ps_customer' WHERE email='user@gmail.com' AND passwd='geslo'
<?php session_start(); if($_SERVER["REQUEST_METHOD"]=="POST") { $hostname_localhost ="localhost"; $database_localhost ="test"; $username_localhost ="test"; $password_localhost ="test"; $localhost=mysql_connect($hostname_localhost, $username_localhost, $password_localhost) or die(mysql_error()); echo "Connected to Server.<br/>"; mysql_select_db($database_localhost) or die(mysql_error()); echo "Connected to Database.<br/>"; $username=mysql_real_escape_string($_POST['username']); $password=mysql_real_escape_string($_POST['password']); $query_user=mysql_query("SELECT id_customer, lastname, firstname FROM 'ps_customer' WHERE email='$username' AND passwd='$password'"); $number_of_users=mysql_num_rows($query_user); if($number_of_users==1) { echo "User found.<br/>"; $output=mysql_fetch_assoc($query_user); print(json_encode($output)); mysql_close(); } else { echo "User not found.<br/>"; } // if } // if ?>Tukaj je Android koda:
private void loginToDatabase(final String strUsername, final String strPassword) { HttpClient client=new DefaultHttpClient(); HttpPost post=new HttpPost("http://moja-domena.com/php/login.php"); HttpResponse response=null; HttpEntity entity=null; InputStream is=null; String result=null; try { List<NameValuePair> loginInfo=new ArrayList<NameValuePair>(2); loginInfo.add(new BasicNameValuePair("username", strUsername)); loginInfo.add (new BasicNameValuePair("password", strPassword)); post.setEntity(new UrlEncodedFormEntity(loginInfo)); response=client.execute(post); entity=response.getEntity(); is=entity.getContent(); try { BufferedReader reader=new BufferedReader(new InputStreamReader(is, ("iso-8859-1")), 8); StringBuilder sb=new StringBuilder(); String line=null; while((line = reader.readLine())!=null) { sb.append(line).append("\n"); } is.close(); result=sb.toString(); int i=0; // test breakpoint code } catch(Exception e) { } finally { } // try-catch-finally } catch(Exception e) { } finally { } // try-catch-finally } // loginToDatabaseSpremenljivka result vsebuje poleg ostalih echo-jev iz php skripte tudi "User not found", kar pomeni, da uporabnika preko tega sql stavka ne najde. Zakaj?
KernelPanic ::
KernelPanic ::
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | Rabim pomoč pri PHP-ju.Oddelek: Šola | 693 (530) | Stari89 |
» | [SQL] Unikatni izpisiOddelek: Programiranje | 2236 (1623) | 111111111111 |
» | [PHP]Zajem podatkov iz bazeOddelek: Programiranje | 4067 (3704) | cobrica |
» | MySQL Query VprašanjeOddelek: Izdelava spletišč | 3228 (2993) | overlord_tm |
» | SQL problemOddelek: Programiranje | 1535 (1372) | Bossek |