0

enter image description hereMy php file inserts into table row 0 values, I cannot find solution for that.

<?php
$selected_button = $_POST['a'];

$conn = mysql_connect('localhost','root','');
if(!$conn )
{
  die('Could not connect: ' . mysql_error());
}
  $sql = "INSERT INTO answers (member_id, question_id, answer) VALUES (1, 2,'$selected_button')";

mysql_select_db('ipad',$conn);
$result = mysql_query($sql, $conn);
if(!$result)
{
    return false;
}
return true;


mysql_close($conn);
?>

after insert i receive, member_id = 0 ; question_id = 0 ; answer = NULL

7
  • 2
    How does your schema look like? Commented Jan 7, 2014 at 10:31
  • 3
    mysql_query is deprecated, consider replacing with the supported php.net/manual/de/ref.pdo-mysql.php Commented Jan 7, 2014 at 10:32
  • adding your schema here will be useful to spot the issue. Commented Jan 7, 2014 at 10:34
  • change $result = mysql_query($sql, $conn); to $result = mysql_query($sql, $conn) or die('ERROR: ' . mysql_error()); and check if it breaks the code.. Commented Jan 7, 2014 at 10:45
  • btw your database name is not ipad .. referring to the screenshot.. Commented Jan 7, 2014 at 10:51

2 Answers 2

4

If you are using mysql, it should be:

$result = mysql_query($sql, $conn);

But try to use mysqli as mysql is deprecated.

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

2 Comments

Was waiting till someone finally spots this :) Gz, you are the winner!
i have this right now, and problem is the same, earlier i tried with mysqli also, and the same problem occure
0

There is no query running right now. query is first paramter in mysql_query. $result = mysql_query($sql,$conn);

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.