The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
C# and PHP Question RRS feed

  • Question

  • I don't really know much at all about PHP. I'm wondering if anyone here can solve a quick question I have.
    Managed to dig through a few tutorials/articles and throw together what I *think* is correct. I understand I currently don't have encryption, etc, but want to get this working first if possible.

    I know its communicating with my server as I get a response back, but it doesn't seem to post. Here's a quick snip it of my c# code.

    int modeid = 1;
    string name = "data2";
    string info = "testing";
    string score = zblah";
    string postData = "ModeID=" + modeid + "&Name=" + name + "&Info=" + info + "&Score=" + score;
    byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);
    postStream.Write(byteArray, 0, postData.Length);


    Here's the server side PHP to submit the score.

    require_once('db.inc.php');
    $sql = "INSERT INTO mygame_highscores (ModeID,Info,Score) VALUES ('".$_POST["ModeID"]."','".$_POST["Info"]."',".$_POST["Score"].")";
    $result = mysql_query($sql);
    echo "Submitted";
    ?>
    I get "Submitted" responded back, but no posting to MySQL. Thank you.
    Friday, February 4, 2011 8:48 AM

Answers

  • Hi,
    $sql = "INSERT INTO mygame_highscores (ModeID,Info,Score) VALUES ('".$_POST["ModeID"]."','".$_POST["Info"]."',".$_POST["Score"].")";
    try to do so: $sql = "INSERT INTO mygame_highscores (ModeID,Info,Score) VALUES ('".$_POST['ModeID']."','".$_POST['Info']."',".$_POST['Score']." i didn't tried it, so I could also be wrong. another suggestion: $result = mysql_query($sql) or die(mysql_error()); //to see what's happening if your query fails.
    Friday, February 4, 2011 12:50 PM

All replies

  • Hi,
    $sql = "INSERT INTO mygame_highscores (ModeID,Info,Score) VALUES ('".$_POST["ModeID"]."','".$_POST["Info"]."',".$_POST["Score"].")";
    try to do so: $sql = "INSERT INTO mygame_highscores (ModeID,Info,Score) VALUES ('".$_POST['ModeID']."','".$_POST['Info']."',".$_POST['Score']." i didn't tried it, so I could also be wrong. another suggestion: $result = mysql_query($sql) or die(mysql_error()); //to see what's happening if your query fails.
    Friday, February 4, 2011 12:50 PM
  • Ah, php.ini should have display_errors = On and error_reporting = E_ALL
    Friday, February 4, 2011 12:54 PM
  • Hi,
    $sql = "INSERT INTO mygame_highscores (ModeID,Info,Score) VALUES ('".$_POST["ModeID"]."','".$_POST["Info"]."',".$_POST["Score"].")";
    try to do so: $sql = "INSERT INTO mygame_highscores (ModeID,Info,Score) VALUES ('".$_POST['ModeID']."','".$_POST['Info']."',".$_POST['Score']." i didn't tried it, so I could also be wrong. another suggestion: $result = mysql_query($sql) or die(mysql_error()); //to see what's happening if your query fails.
    Thank you. I was apparently having an error in MySQL database. Rebuilt it and all is fine.
    Friday, February 4, 2011 4:40 PM
  • I am currently facing the same problem. Could you please post more of your C# und PHP code?

    Benny
    Wednesday, September 21, 2011 2:43 PM