Question Locked

PHP MYSQL

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

wHAT IS THE CORRECT SYSNTAX TO WRITE DATA TO A TABLE IN MYSQL:

THE FOLLOWING CODE FAILS WHEN I ADD TO OTHER CODES WHICH ARE ALREADY CONNECTING TO MYSQL IN PHP
$sql = 'insert into addressbk values ('1', '$fname','$lname','$address')';
mysql_query($sql) or die(mysql_error());

Please help
PM

2 replies

by toivo talikka

[pre]
$sql_insert = "INSERT INTO addressbk (id, fname, lname, address)
VALUES ('1', '$fname', '$lname', '$address')";

$result = mysql_query($sql_insert, $db_connection) or die ("Could not execute query:
\n" . mysql_errno() . ": " . mysql_error() . "
\n");
[/pre]

You have to list the names of the columns in the table - the names used in the above example were just a guess.

You have to use an existing connection to the database, passed to the query in the variable $db_connection.

The above example uses the mysql commands, you can also use the mysqli versions.

This discussion is closed to new replies.