PDA

View Full Version : Problems with data inserting..



emme85
March 12th, 2007, 02:46 AM
hi.. i'm really a newbie in using php.. so, i really NEED help!! i tried to insert data into my table, but it is not inserted.. why is it?? i tried many ways, but still doesn't work..

<?php
$host= 'localhost';
$username= 'root';
$password= '';

$connect =mysql_connect($host, $username, $password) or
die ("could not connect to MySQL sever in localhost");
$db="care_pair";
mysql_select_db($db, $connect) or
die ("could not select database");

?>
<?php

$RNo=$_POST['Report_No'];
$NVessel=$_POST['Name_of_Vessel'];
$RTime=$_POST['Report_Time'];
$DAccident=$_POST['Date_of_Accident'];
$TAccident=$_POST['Time_of_Accident'];
$IPName=$_POST['IP_Name'];
$IPSname=$_POST['IP_Surname'];
$IPDOB=$_POST['IP_DOB'];
$IPNat=$_POST['IP_Nationality'];
$IPsex=$_POST['IP_Sex'];
$IPSAdd=$_POST['IP_Address'];
$IPPass=$_POST['IP_Passport'];

$query = "INSERT INTO Report VALUES ('$RNo','$NVessel','$RTime','$DAccident','$TAccide nt'','IPName','$IPSname','$IPDOB',
'$IPNat','$IPsex','$IPAdd', '$IPPass')";
mysql_query($query);
another way:

$query="INSERT INTO Report SET
Report_No = '$RNo', Name_of_Vessel= '$NVessel', Report_Time= '$RTime', Date_of_Accident= '$DAccident',
Time_of_Accident= '$TAccident', IP_Name= '$IPName', IP_Surname= '$IPSname', IP_DOB= '$IPDOB', IP_Nationality= '$IPNat',
IP_Sex= '$IPsex', IP_Address= '$IPAdd', IP_Passport= '$IPPass'";

$result=mysql_query($query)
or die( "There was an error running '$query' " . mysql_error());

borrob
March 12th, 2007, 07:56 AM
it's difficult to help you, i'm mising a lot of info here. But i still want to give you some advice.
The first thing that i build in any php project is a debugger. This helps a lot. First you get the right info when needed and you'll find it easier to see what msitakes you made. And after you havn't seen the code for a long time you still can find mistakes easily without exactly knowing what the code does.

normally i use a class that writes to a txt file my debug info.

now for youre problem
function run_sql( $sql, $link, $debug )
{
$res = mysql_query( $sql, $link );
if( !$res )
{
$debug->debug( "error", "query error sql:" . $sql . " :end sql;" . "\r\n" );
$debug->debug( "error", mysql_error( $link ) . "\r\n");
$result = null;
return false;
}
else
{
$debug->debug( "message", "query succes" . "\r\n" );
$result = $res;
return true;
}
}
now you'll have some idea about what's going wrong

hope you'll get it.....

BetaWar
March 12th, 2007, 08:42 AM
Another thing you may want to try, instead of creating a whole class to log errors is to just put an output where it is needed.

In this case change you insert code to something like so:

$RNo=$_POST['Report_No'];
$NVessel=$_POST['Name_of_Vessel'];
$RTime=$_POST['Report_Time'];
$DAccident=$_POST['Date_of_Accident'];
$TAccident=$_POST['Time_of_Accident'];
$IPName=$_POST['IP_Name'];
$IPSname=$_POST['IP_Surname'];
$IPDOB=$_POST['IP_DOB'];
$IPNat=$_POST['IP_Nationality'];
$IPsex=$_POST['IP_Sex'];
$IPSAdd=$_POST['IP_Address'];
$IPPass=$_POST['IP_Passport'];

$query = "INSERT INTO Report VALUES ('$RNo','$NVessel','$RTime','$DAccident','$TAccide nt'','IPName','$IPSname','$IPDOB',
'$IPNat','$IPsex','$IPAdd', '$IPPass')";
mysql_query($query) or die("__LINE__, " . mysql_error());