Forum Moderators: coopster

Message Too Old, No Replies

trying to insert to databse with php

         

kerspink

5:51 pm on Mar 27, 2008 (gmt 0)

10+ Year Member



am trying to insert to a database
and am getting the following error
cannot seem to get rid of it and get the info inserted
can anyone see my probs
any help would be appreciated

<?php

$tablename = 'members';
$fields = array("first_name", "surname", "email");
$values = array( "Tam", "Bam","email@example.com");
$database = 'tool';
$host = 'localhost';
$username = 'username';
$password = 'password';

// Connecting, selecting database
mysql_connect($host, $username, $pass)
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';

mysql_select_db($user) or die('Could not select database');

function add_record($tablename, $fields, $values, $database, $host, $username, $password) {

$record = mysql_query(INSERT INTO members(first_name,surname,email)
VALUES('Tam','Bam','email@example.com')
if (!$record) {
echo "INSERT into contacts table failed: ".mysql_error());
}
}


echo $record;



?>

error reads

Parse error: syntax error, unexpected T_STRING in / / line 25

[edited by: eelixduppy at 6:02 pm (utc) on Mar. 27, 2008]
[edit reason] exemplified [/edit]

wheelie34

6:12 pm on Mar 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



At first glance I think your missing a );

$record = mysql_query(INSERT INTO members(first_name,surname,email)
VALUES('Tam','Bam','email@example.com'));<---

eelixduppy

6:17 pm on Mar 27, 2008 (gmt 0)



You also need to surround the whole string in quotes, like the following:

$record = mysql_query("INSERT INTO members(first_name,surname,email)
VALUES('Tam','Bam','email@example.com')");

Also, welcome to WebmasterWorld! :)