0

i have built an air for android app that posts content to facebook and on success sends a url query to a php file to add the post id of the content along with fb_id and the users name. the problem is it is not adding the value i am giving it it is instead adding the same number(dont know where it is coming from) to the post_id and fb_id. i know the right values are being sent by the mobile app.

php:

<?php
/*
------------variables set in flash--------------

 videoVars.postId = result.id
 videoVars.uid = uid //fb user id
 videoVars.firstName = firstName
 videoVars.lastName = lastName

*/

$postId = $_REQUEST['postId'];
$uid = $_REQUEST['uid'];
$firstName = $_REQUEST['firstName'];
$lastName = $_REQUEST['lastName'];

echo $postId.'<br/>';
echo $uid.'<br/>';
echo $firstName.'<br/>';
echo $lastName.'<br/>';



//connect to database
include('db-connect.php');

$addVideo = mysqli_query($dbc , "INSERT INTO content (content_id, post_id, fb_id, first_name, last_name ) VALUES('','".$postId."','".$uid."','".$firstName."','".$lastName."')");

?>

the value i am getting for post_id and user_id are the same even though they should be different. i manually typed the vars in to addressbar in browser and it still misbehaved in the same way. the only way i can add more than one row is to add it in the sql tab of phpMyAdmin

1
  • what is the structure of table content? Commented Apr 2, 2014 at 11:45

3 Answers 3

1

If your echo calls output the correct values, check your database table structure and make sure there's no UNIQUE key set for fb_id.

Then, make sure you're escaping all your content with mysqli_real_escape_string ( mysqli $link , string $escapestr ). https://www.php.net/manual/en/mysqli.real-escape-string.php

Is content_id an auto_increment value? If so, try passing NULL for it, without the single quotes, instead of an empty string.

To debug, you can also try echoing your query (first assign it to a variable $sql = "[QUERY HERE]";, then pass the variable to the function, then echo the $sql variable and finally call your file manually.

Sign up to request clarification or add additional context in comments.

10 Comments

the post_id is set to unique that is why im only getting one entry because i am a number that will be unique every time but the correct number is not going in. i will edit Q.
Do your echo calls show the correct data? Did you try to echo the $sql query to see what you're sending to db?
yes i echo ed the query and the correct values are getting echoed out. and still not going to database
What's your table structure? If you copy the MySQL query manually from your PHP file's echo, and into PhpMyAdmin or Sequel Pro, does it still enter the wrong values?
i cant Because there are variables in statement. it works from the php file if i hard code the values but that is no use to me.
|
0

I guess that you have problem on content_id field. it should has auto_increment property.

In your sql, when you inserts content_id as a blank value '' it will convert to 0, next time when you insert a blank value again you will has "Duplicate entry '0' for key 'PRIMARY'" message.

to fix it just remove the primary key field in your query i.e:

$addVideo = mysqli_query($dbc , "INSERT INTO content ( post_id, fb_id, first_name, last_name ) VALUES('".$postId."','".$uid."','".$firstName."','".$lastName."')");

Or you can insert a null value for it:

$addVideo = mysqli_query($dbc , "INSERT INTO content (content_id, post_id, fb_id, first_name, last_name ) VALUES(null,'".$postId."','".$uid."','".$firstName."','".$lastName."')");

You can try to print out your current - wrong sql error like this:

$addVideo = mysqli_query($dbc , "INSERT INTO content (content_id, post_id, fb_id, first_name, last_name ) VALUES('','".$postId."','".$uid."','".$firstName."','".$lastName."')");
if (!$addVideo) {
        printf("Error: %s\n", mysqli_error($dbc));
    }

1 Comment

any time i used ai values before i just used '' and it worked without any issue. also i have edited the question
0

The problem is the id were being stored as ints in the database and the biggest allowable int value is 2147483647 which is being put in each time and as the numeric ids are bigger numbers than 2147483647 and one of the fields is set to unique it can only add one row. i have changed the type to bigint and it is working fine now. i have also implemented some of @ dAngelov suggestions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.