Jump to content

PHP/MySQL: Why does this call doesn't work ?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
fedlerner

fedlerner

    Newbie

  • Members
  • PipPip
  • 16 posts
Hi!

I'm a bit new on working with MySQL on PHP.. I have the following code:
$result = mysql_query(sprintf('INSERT INTO portfolio (uid,symbol,shares) VALUES(%d,"%s",%d)

    ON DUPLICATE KEY UPDATE shares=shares+%d',

        $_SESSION["uid"], $s->symbol, $_POST["amount"], $_POST["amount"]));


Which isn't working.. Can anyone help me with it ?

Regards,
Federico.-

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
why do you do the sprintf? any particular reason? normal concatenation would work as good I assume? have you tried to echo the content and see what it gives instead of sending it to the sql server?

$sql = 'INSERT INTO portfolio (uid,symbol,shares) VALUES('.$_SESSION["uid"].',".$s->symbol.",'.$_POST["amount"].') ON DUPLICATE KEY UPDATE shares=shares+'.$_POST["amount"];
echo $sql;
$result = mysql_query($sql) or die("Error: ".mysql_error());

that will get you the error outputs you might need...
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
fedlerner

fedlerner

    Newbie

  • Members
  • PipPip
  • 16 posts
I'm a stupid :P The error happened because the table is "portfolios", not "portfolio".
Thanks for your help, as your code printed me the error :)

Regards,
Federico.-