0

I have a SELECT statement, WHILE statement and an INSERT:

$result = mysqli_query($con,"SELECT winner, time, course, market, twitter_pubstatus
FROM combo 
WHERE twitter_pubstatus = 0 AND market = '$win' GROUP BY winner");
while($row = mysqli_fetch_array($result))
{
$winner = $row['winner'];
$time = $row['time'];
$course = $row['course'];

$message = "$winner won the $time at $course.  You are a winner! #GetIn";

$query = "INSERT INTO messageTable (MESSAGE) VALUES($message)or die(mysql_error())";

}

It runs through with no errors. There should be 12 rows that get inserted into the database. What am I doing wrong?

2
  • 1
    Try changing $query = "INSERT INTO messageTable (MESSAGE) VALUES($message)or die(mysql_error())"; to $query = "INSERT INTO messageTable (MESSAGE) VALUES('$message')or die(mysql_error())"; Notice the single quotes in '$message' Commented Apr 8, 2014 at 11:46
  • in addition u are not executing the insert query .. and mixing mysql with mysqli mysql_error() Commented Apr 8, 2014 at 11:46

1 Answer 1

1

Try changing $query = "INSERT INTO messageTable (MESSAGE) VALUES($message)or die(mysql_error())"; to $query = "INSERT INTO messageTable (MESSAGE) VALUES('$message')or die(mysql_error())";

Notice the single quotes in '$message'

And $query is just a string so execute the query
$result=mysqli_query($query)

And then check if query executed by doing this if(!$result) die(mysqli_error());

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

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.