Question

Locked

PHP MYSQL

By mwenyap ·
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

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Try this

by Toivo Talikka In reply to PHP MYSQL

[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: <br>\n" . mysql_errno() . ": " . mysql_error() . "<br>\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.

Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums