Forum Moderators: coopster

Message Too Old, No Replies

Unexpected Error

Beginner in PHP

         

shaundunne

10:22 am on Dec 27, 2007 (gmt 0)

10+ Year Member



parse error, unexpected T_STRING, expecting ',' or ';' on line 19

Code is the following

<?php
//connect to server and select database
$mysql = mysql_connect("server","username","password");
//if connection connection fails
if (mysql_connect_error()) {
echo "connection failure";
exit();
//insert into table
} else {
$sql = "INSERT INTO email (email) VALUES
'".$POST["email"]."',";
$res = mysql_query(mysql,$sql);
}
//success or failed message
if ($res === TRUE) {
echo "A record has been inserted";
} else {
echo "Could not insert record:%s\n" mysql_error(mysql);
mysql_close(mysql);
}
?>

line 19 is

echo "Could not insert record:%s\n" mysql_error(mysql);

can anybody help?
Cheers

[edited by: shaundunne at 10:35 am (utc) on Dec. 27, 2007]

[edited by: coopster at 2:36 pm (utc) on Dec. 27, 2007]
[edit reason] exemplified username/password [/edit]

shaundunne

10:26 am on Dec 27, 2007 (gmt 0)

10+ Year Member



just realized that putting my password in the topic is probably not the best idea?

can someone delete that?

Cheers

shaundunne

11:15 am on Dec 27, 2007 (gmt 0)

10+ Year Member



All sorted ,

please ignore , thanks, see you soon

PHP_Chimp

11:46 am on Dec 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got your password removed ;)

echo "Could not insert record:%s\n" mysql_error(mysql);

Are you not trying to use -

sprintf('Could not insert record:%s\n', mysql_error(mysql));
// OR
echo 'Could not insert record:'.mysql_error(mysql)."\n";
// OR
echo "Could not insert record:mysql_error(mysql)\n";

Im not sure about the last one, as you may well get an error about white space, but it may work and its the least code to write :)

Your original echo doesnt accept placeholders like the sprintf [uk.php.net]if you would like to keep with the %s version of printing.

shaundunne

11:51 am on Dec 27, 2007 (gmt 0)

10+ Year Member



I got it sorted

went with

echo "Could not insert record:%s\n".mysql_error();

works fine now , thank you