android - Why is return registration successful? -
require "finddoctorconnect.php"; $type = $_post["type"]; $yourname = $_post["yourname"]; $regnum = $_post["regnum"]; $fathername = $_post["fathername"]; $gender = $_post["gender"]; $mobilenumber = $_post["mobilenumber"]; $password = $_post["password"]; $sql_query = "select * doctorregistration mobilenumber='$mobilenumber';"; $result = mysqli_query($con, $sql_query); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_assoc($result); $temp = $row["mobilenumber"]; if ($temp == $mobilenumber) { $row = mysqli_fetch_assoc($result); echo "already found"; } } else if (mysqli_query($con, $sql_query)) { $sql_query = "insert doctorregistration values('$type','$yourname','$regnum','$fathername','$gender','$mobilenumber','$password');"; $result = mysqli_query($con, $sql_query); echo "successfull"; } when send data application database, first time it's saved in database , returns registration successfully, when again same data primary key mobile number when send data database again said me registration successful not save data time. want return registration unsuccessful that?
here code:
public class backgroundtask extends asynctask<string, void, string> { context ctx; alertdialog alertdialog; @override protected void onpreexecute() { // todo auto-generated method stub alertdialog=new alertdialog.builder(ctx).create(); } public backgroundtask(context ctx) { // todo auto-generated constructor stub this.ctx=ctx; } @override protected string doinbackground(string... params) { // todo auto-generated method stub string reg_url="http://10.0.2.2/finddoctor/register.php"; string method=params[0]; if(method.equals("register")) { string type=params[1]; string yourname=params[2]; string regnum=params[3]; string fathername=params[4]; string gender=params[5]; string mobilenumber=params[6]; string password=params[7]; try { url url=new url(reg_url); httpurlconnection connection=(httpurlconnection) url.openconnection(); connection.setrequestmethod("post"); connection.setdooutput(true); outputstream os=connection.getoutputstream(); bufferedwriter bufferedwriter=new bufferedwriter(new outputstreamwriter(os)); string data=urlencoder.encode("type","utf-8")+"="+urlencoder.encode(type,"utf-8")+"&"+ urlencoder.encode("yourname","utf-8")+"="+urlencoder.encode(yourname,"utf-8")+"&"+ urlencoder.encode("regnum","utf-8")+"="+urlencoder.encode(regnum,"utf-8")+"&"+ urlencoder.encode("fathername","utf-8")+"="+urlencoder.encode(fathername,"utf-8")+"&"+ urlencoder.encode("gender","utf-8")+"="+urlencoder.encode(gender,"utf-8")+"&"+ urlencoder.encode("mobilenumber","utf-8")+"="+urlencoder.encode(mobilenumber,"utf-8")+"&"+ urlencoder.encode("password","utf-8")+"="+urlencoder.encode(password,"utf-8"); bufferedwriter.write(data); bufferedwriter.flush(); bufferedwriter.close(); os.close(); inputstream is=connection.getinputstream(); is.close(); return "registration successful"; } catch (malformedurlexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } return null; } @override protected void onpostexecute(string result) { // todo auto-generated method stub alertdialog.setmessage(result); alertdialog.show(); if (result.endswith("registration seccussfull")) { toast.maketext(ctx, result,toast.length_long).show(); } else if(result.endswith("already found")){ alertdialog.setmessage("its works"); alertdialog.show(); } } }
manage condition on server side http://10.0.2.2/finddoctor/register.php , return data android code.
and in android read data server using inputstream , check if registered success or not.
edit : add these lines , show proper output
inputstream is=connection.getinputstream(); bufferedreader reader = new bufferedreader(new inputstreamreader(is)); string line; stringbuilder builder = new stringbuilder(); while((line=reader.readline()) != null) builder.append(line); is.close(); return builder.tostring(); these lines says that, don't care server response.
Comments
Post a Comment