Quote:
|
Originally Posted by Cerasti
Hello!
Code:
<?php
$username = "****";
$password = "****";
$database = "****";
$email = $_POST[ 'email' ];
$query = "INSERT INTO nyhetsbrev VALUES( '', '$email' );";
mysql_connect( localhost, $username, $password );
@mysql_select_db( $database ) or die( "Couldn't select MySQL database" );
mysql_query( $query );
mysql_close( );
?>
Also, is the @ before mysql_select_db() necessary? What's it for?
|
Hi Cerasti,
@before mysql_select_db or any other function ptohibit displaying error
messages. Some times it is good because error message gives hint to hacker
how to break you system You need error message because it help you to see what is wrong
$sql="insert into nyhetsbrev (field1, email) VALUES( '', ' ".$email." ' )";
if(!mysql_query($sql))
{
echo mysql_errno() . ": ";
echo mysql_error() . "<br>";
}
and I usually use auto_increment number for id field and therefore
i would write
$sql="insert into nyhetsbrev (field1, email) VALUES( 0, ' ".$email." ' )";
echo $sql."<br>" // this line to see what your sql is
Please visit http://www.configure-all.com and select PHP from main menu
there you will find code examples that help you
Good luck
|