Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to insert to database

Status
Not open for further replies.

kerspink1

Technical User
Mar 21, 2008
5
GB
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","tambam@bools.com");
$database = 'tool';
$host = 'localhost';
$username = 'tool';
$password = 'yippee';

// 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_queryINSERT INTO members(first_name,surname,email)
VALUES('Tam','Bam','tambam@bools.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
 
You are missing opening "(" and closing ")" parenthesis or round brackets in your call to mysql_query as well as a terminating semi colon ";":

Code:
$record = mysql_query[red]>>[blue]([/blue]<<[/red]INSERT INTO members(first_name,surname,email)[red]>>[blue]);[/blue]<<[/red]

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
like this
function add_record($tablename, $fields, $values, $database, $host, $username, $password) {



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

have added these but still getting same error
 
You are still missing the semicolon ";".

You have a ")" too many in your echo statement.
Code:
"INSERT into contacts table failed: ".mysql_error()[red])[/red];
the red one should not be there.

These are very basic syntax problems. Check your syntax for these types of errors.

All lines should end in ";" close your ) and your } etc...





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
i thought u had advised to do this )

$record = mysql_query>>(<<INSERT INTO members(first_name,surname,email)>>);<<
 
That I did yes, but your echo statement is a entirely different line.

mysql_query line:

$record = mysql_query>>(<<INSERT INTO members(first_name,surname,email)>>);<<

echo line:

echo "INSERT into contacts table failed: ".mysql_error()[red])[/red];

2 different lines. 2 different errors.







----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Should your insert not be something like
Code:
$record = "INSERT INTO members (first_name,surname,email)
                 VALUES('Tam','Bam','tambam@bools.com')";
mysql_query($record);
How much PHP/MYSQL do you know ?
At some stage you will have to understand how to concatante strings do put your variables into first_name,surname and email and you will need to understand how to return a database resource conection when you connect e.g
Code:
$db = mysql_connect($host, $username, $pass)
and use that resource whrn you do anything to the connection e.g when you select the database and when you issue the query (which you will need to pass in $db to the function.
I would suggest a bit of googling might help you out here.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top