Insert query error

I am getting the following error trying to run the below query. Any
suggestions on what I am doing wrong?

Thank you,

Something went wrong while inserting your store visitCannot add or
update a child row: a foreign key constraint fails (`store`.`posts`,
CONSTRAINT `posts_ibfk_1` FOREIGN KEY (`post_store`) REFERENCES
`stores` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE)

$sql = "INSERT INTO
posts(market, type, post_store, post_tptest, post_content, post_by, post_date)
VALUES('" . mysql_real_escape_string($_POST['market']) . "',
'" . mysql_real_escape_string($_POST['type']) . "',
'" . mysql_real_escape_string($_POST['post_store']) . "',
'" . sha1($_POST['post_tptest']) . "',
'" . mysql_real_escape_string($_POST['post_content']) . "',
" . $_SESSION['user_id'] . ",
NOW())";

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Chris Stinemetz [ Sa, 06 August 2011 06:41 ] [ ID #2063059 ]

Re: Insert query error

Chris,

Why not escape, and extract the data prior to Insert string?

On 06/08/2011 05:41, Chris Stinemetz wrote:
> I am getting the following error trying to run the below query. Any
> suggestions on what I am doing wrong?
>
> Thank you,
>
> Something went wrong while inserting your store visitCannot add or
> update a child row: a foreign key constraint fails (`store`.`posts`,
> CONSTRAINT `posts_ibfk_1` FOREIGN KEY (`post_store`) REFERENCES
> `stores` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE)
>
> $sql = "INSERT INTO
> posts(market, type, post_store, post_tptest, post_content, post_by, post_date)
> VALUES('" . mysql_real_escape_string($_POST['market']) . "',
> '" . mysql_real_escape_string($_POST['type']) . "',
> '" . mysql_real_escape_string($_POST['post_store']) . "',
> '" . sha1($_POST['post_tptest']) . "',
> '" . mysql_real_escape_string($_POST['post_content']) . "',
> " . $_SESSION['user_id'] . ",
> NOW())";
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Gavin Chalkley [ Sa, 06 August 2011 10:29 ] [ ID #2063060 ]

Re: Insert query error

--20cf303638dbe6588d04a9e31371
Content-Type: text/plain; charset=UTF-8

Chris

The error is indicated by the keywords a foreign key constraint fails, This
implies that some value in "store" table is missing which u are trying to
insert in posts. So check for the value u are trying to input in "post"
table. U have to check for the values of "post_store" field from the input
list in "store" table's store_id field
============
regds
amit

"The difference between fiction and reality? Fiction has to make sense."


On Sat, Aug 6, 2011 at 10:11 AM, Chris Stinemetz
<chrisstinemetz [at] gmail.com>wrote:

> I am getting the following error trying to run the below query. Any
> suggestions on what I am doing wrong?
>
> Thank you,
>
> Something went wrong while inserting your store visitCannot add or
> update a child row: a foreign key constraint fails (`store`.`posts`,
> CONSTRAINT `posts_ibfk_1` FOREIGN KEY (`post_store`) REFERENCES
> `stores` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE)
>
> $sql = "INSERT INTO
> posts(market, type, post_store, post_tptest, post_content, post_by,
> post_date)
> VALUES('" . mysql_real_escape_string($_POST['market']) . "',
> '" . mysql_real_escape_string($_POST['type']) . "',
> '" . mysql_real_escape_string($_POST['post_store']) . "',
> '" . sha1($_POST['post_tptest']) . "',
> '" . mysql_real_escape_string($_POST['post_content']) . "',
> " . $_SESSION['user_id'] . ",
> NOW())";
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--20cf303638dbe6588d04a9e31371--
Amit Tandon [ So, 07 August 2011 06:50 ] [ ID #2063073 ]
PHP » gmane.comp.php.database » Insert query error

Vorheriges Thema: Left Join
Nächstes Thema: RE: 47951 by: Chris Stinemetz