0

I have a simple insert statement that should use $GLOBALS that has my connection string in. Problem is that it does not insert the data. Have I done this correctly?

Insert.php

<?php
require 'core/init.php';

$Name = $_REQUEST["Name"];
$Venue = $_REQUEST["Venue"];
$Category = $_REQUEST["Category"];

$query = "INSERT INTO bands (Name, Venue, Category)
          VALUES ('$Name', '$Venue', '$Category')";
mysql_query ($query,$GLOBALS)
    or die ("could not add to database");

echo("You have added: <br />");
$result = mysql_query("SELECT * FROM bands ORDER  BY  Band_id DESC LIMIT 1");

while($row = mysql_fetch_array($result))
{
    echo $row['Name']. "" . $row['Venue']. "" . $row['Category'];
    echo "<br />";
}
?>
4

2 Answers 2

1

You need to connect mysql with mysql_connect() function then select database with mysql_select_db() function then you can call mysql_query function

you just cant execute queries with query string parameter you need to execute that connection query first and then select your database

And i suggest you to use mysqli instead of mysql cuz mysql methods will be deprecated soon
Sign up to request clarification or add additional context in comments.

Comments

0

You don't put whole $GLOBALS variable in your mysql_query() call. You put the specific variable with the connection string only:

mysql_query($query, $GLOBALS['connection']) // Assuming you called the connection var "connection"
    or die ("could not add to database");

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.