0 votes
in Education by (1.3m points)
I'm making a 'post text' app and trying to update my database with name and body field. The obj-c code looks like this:

- (IBAction)post:(id)sender

{

    NSLog(@"%@", name);

    NSLog(@"%@", body);

    // create string contains url address for php file, the file name is post.php, it receives parameter :name

    NSString *strURL = [NSString stringWithFormat:@"http://www.mywebsite.com/post.php?name=%@&body=%@",name, body];

    // to execute php code

    NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];

    // to receive the returend value

    NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

    NSLog(@"%@", strResult);

}

And the php code looks like this:

<?php

if (isset($_REQUEST['name']) && isset($_REQUEST['body']) && strlen($_REQUEST['name']) > 0 && strlen($_REQUEST['body']) > 0) {

    //get data

    $title = $_REQUEST['name'];

    $body = $_REQUEST['body'];

    mysql_connect("MyServer","username","password") or die(mysql_error());

    mysql_select_db("Database_Name") or die(mysql_error());

    $date = date("Y-m-d");

    //insert data

    $insert = mysql_query("INSERT INTO news VALUES ('','".mysql_real_escape_string($title)."','".mysql_real_escape_string($body)."','".mysql_real_escape_string($date)."')") or die(mysql_error());

    die("Your text has been posted!");

}

?>

Sometimes it works to post through the app but then it just post (null) as name and null as body. But for the most part it doesn't work at all. It just says in the log:

    2012-06-26 16:54:49.893 AppName[12444:707]

<UITextField: 0x17a390; frame = (63 76; 194 31); text = 'MyName';

clipsToBounds = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x17a4c0>>

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.3m points)
Taking a wild guess here but are name and body pointers to a UITextField object? I'm thinking they might be, based on your log output. If so, you need to use [name text] or name.text to get the actual NSString value from the text field.

Learn More with Blogmepost

blogmepost Online Test

NCERT Questions & Answers

  • NCERT Class 12 Maths Solutions
  • NCERT Class 12 Physics Solutions
  • NCERT Class 12 Chemistry Solutions
  • NCERT Class 12 Biology Solutions
  • NCERT Class 10 Science Solutions
  • NCERT Class 10 Maths Solutions
blogmepost Q&A

CBSE Questions & Answers Portal

  • CBSE Class 12 Maths Questions Answers
  • CBSE Class 12 Physics Questions Answers
  • CBSE Class 12 Chemistry Questions Answers
  • CBSE Class 12 Biology Questions Answers
  • CBSE Class 10 Science Questions Answers
  • CBSE Class 10 Maths Questions Answers
Blogmepost

Learn Math Formula, Revise Notes

  • JEE Crash Course Questions & Answers
  • NCERT Course Questions and Answers
  • CBSE Board Questions Bank
  • ICSE Board Questions Bank
  • Free Study Materials
  • Question & Answers Bank for All Classes
  • Text Book Solutions
  • Previous Year Question Paper
  • NCERT Book Solutions

  • NCERT
  • NCERT Solutions
  • NCERT Solutions for Class 12 Maths
  • NCERT Solutions for Class 12 Physics
  • NCERT Solutions for Class 12 Chemistry
  • NCERT Solutions for Class 12 Biology
  • NCERT Solutions for Class 11 Maths
  • NCERT Solutions for Class 11 Physics
  • NCERT Solutions for Class 11 Chemistry
  • NCERT Solutions for Class 11 Biology
  • NCERT Solutions for Class 10 Maths
  • NCERT Solutions for Class 10 Science
  • NCERT Solutions for Class 9 Maths
  • NCERT Solutions for Class 9 Science
  • CBSE Classes

  • CBSE Class 5 Questions
  • CBSE Class 6 Questions
  • CBSE Class 7 Questions
  • CBSE Class 8 Questions
  • CBSE Class 9 Questions
  • CBSE Class 10 Questions
  • CBSE Class 10 Maths Questions
  • CBSE Class 11 Commerce Questions
  • CBSE Class 11 Engineering Questions
  • CBSE Class 11 Medical Questions
  • CBSE Class 12 Commerce Questions
  • CBSE Class 12 Maths Questions
  • CBSE Class 12 Engineering Questions
  • CBSE Class 12 Medical Questions
  • BOARDS

  • CBSE
  • ICSE
  • NCERT
  • IGCSE
  • Andhra Pradesh
  • Bihar
  • Gujarat
  • Jharkhand
  • Karnataka
  • Kerala
  • Madhya Pradesh
  • Maharashtra
  • Punjab
  • Rajasthan
...