Local Hero
11-27-2005, 09:38 PM
I'm getting my info from a PHP/MySQL book. I'm trying to insert data into my database table and my $sql function isn't working.
$conn = @mysql_connect('localhost', 'root', 'password')
or die( "Err:Conn" );
$rs = @mysql_select_db( "books", $conn )
or die( "Err:Db" );
$sql="insert into transactions (transaction_date, transaction_description, provider, transaction_type, withdrawal_amount, deposit_amount)
values ( \"$dateall\", \"$description\", \"$provider\", \"$trans_type\", $withdraw, $deposit)";
$rs = mysql_query( $sql, $conn );
if($rs){ echo("Record Added");}
if(!$rs){ echo("Record NOT Added");}
In my database the transaction_date is formatted YYYY-MM-DD. I am using this code for the $dateall:
$datemonth = $_POST['month'];
$dateday = $_POST['day'];
$dateyear = $_POST['year'];
$dateall = $dateyear . "-" . $datemonth . "-" . $dateday;
This outputs "2005-11-27"
The transaction_description, provider, and transaction_type are all text, and the withdraw and deposit are currency and formatted 0.00 in the DB.
I can't figure out which values need \" or if their formatted correctally. Can anyone help me?
$conn = @mysql_connect('localhost', 'root', 'password')
or die( "Err:Conn" );
$rs = @mysql_select_db( "books", $conn )
or die( "Err:Db" );
$sql="insert into transactions (transaction_date, transaction_description, provider, transaction_type, withdrawal_amount, deposit_amount)
values ( \"$dateall\", \"$description\", \"$provider\", \"$trans_type\", $withdraw, $deposit)";
$rs = mysql_query( $sql, $conn );
if($rs){ echo("Record Added");}
if(!$rs){ echo("Record NOT Added");}
In my database the transaction_date is formatted YYYY-MM-DD. I am using this code for the $dateall:
$datemonth = $_POST['month'];
$dateday = $_POST['day'];
$dateyear = $_POST['year'];
$dateall = $dateyear . "-" . $datemonth . "-" . $dateday;
This outputs "2005-11-27"
The transaction_description, provider, and transaction_type are all text, and the withdraw and deposit are currency and formatted 0.00 in the DB.
I can't figure out which values need \" or if their formatted correctally. Can anyone help me?