0
<?php
$link = mysql_connect('localhost', 'sc2broad_testing', '1BananA2');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';


mysql_query("INSERT INTO Persons (re) VALUES ('Peter')");

mysql_close($link);

?>

This code isnt taking the value 'peter' and inserting it into persons row 're'?? should i attempt to tell it which database somewhere? thanks . it is saying it connects successfully even if i am not telling it which database to connect to? only the server and user? i am confused.

3
  • 1
    The SQL statement you posted does not 'take the value 'peter' and insert it into persons row 're''. It adds a new row to the table, and sets the 're' column value to 'Peter'. Is this what's confusing you? Commented Jan 3, 2012 at 1:44
  • Do $result = mysql_query(....) or die(mysql_error()) as well. You're assuming the query has succeeded. Commented Jan 3, 2012 at 2:31
  • you are not connecting to any database. Use mysql_select_db('db_name', $link) before mysql_query(). Commented Jan 3, 2012 at 2:37

1 Answer 1

2

I think you may need to specify the database that you are querying to?

mysql_select_db('db_name', $link)

If not try changing the mysql_query to:

print("INSERT INTO Persons (re) VALUES ('Peter')");

You can then check the query is correct and test it works outside of the php.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.