Results 1 to 11 of 11

Thread: Data xleh masuk dlm table..

  1. #1
    Join Date
    Mar 2007
    Location
    Port Klang, Malaysia
    Posts
    20
    Rep Power
    0

    Data xleh masuk dlm table..

    nie code yg saya gune utk insert data dlm table.. tp xde 1 data pun yg msuk..
    PHP Code:
    <?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");


    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }

    $editFormAction $HTTP_SERVER_VARS['PHP_SELF'];
    if (isset(
    $HTTP_SERVER_VARS['QUERY_STRING'])) 
    {
      
    $editFormAction .= "?" $HTTP_SERVER_VARS['QUERY_STRING'];
    }

    if ((isset(
    $_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) 
    {
      
    $insertSQL sprintf("INSERT INTO Report(Report_No, Name_of_Vessel, Report_Time,
                           Date_of_Accident, Time_of_Accident, IP_Name, IP_Surname, IP_DOB,
                           IP_Nationality, IP_Sex, IP_Address, IP_Passport) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
    ,                     
                           
    GetSQLValueString($_POST['Report_No'], "text"),
                           
    GetSQLValueString($_POST['Name_of_Vessel'], "text"),
                           
    GetSQLValueString($_POST['Report_Time'], "text"),
                           
    GetSQLValueString($_POST['Date_of_Accident'], "text"),
                           
    GetSQLValueString($_POST['Time_of_Accident'], "text"),
                           
    GetSQLValueString($_POST['IP_Name'], "text"),
                           
    GetSQLValueString($_POST['IP_Surname'], "text"),
                           
    GetSQLValueString($_POST['IP_DOB'], "text"),
                           
    GetSQLValueString($_POST['IP_Nationality'], "text"),
                           
    GetSQLValueString($_POST['IP_Sex'], "text"),
                           
    GetSQLValueString($_POST['IP_Address'], "text"),
                           
    GetSQLValueString($_POST['IP_Passport'], "text"));

      
    $Result1 mysql_query($insertSQL) or die( "There was an error running '$query' " mysql_error());
    ?>
    }
    saya gune code yg same utk database yg berlainan (bawah), tp data leh masuk..
    ape silapnyer utk dtabase care_pair(atas)??

    ni code utk database yg lain, dgn code yg same:
    PHP Code:
    <?php
    $host
    'localhost';
    $username'root';
    $password'';

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

    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }

    $editFormAction $HTTP_SERVER_VARS['PHP_SELF'];
    if (isset(
    $HTTP_SERVER_VARS['QUERY_STRING'])) {
      
    $editFormAction .= "?" $HTTP_SERVER_VARS['QUERY_STRING'];
    }

    if ((isset(
    $HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form2")) {
      
    $insertSQL sprintf("INSERT INTO Supplier (Supp_Id, Supp_Name, Supp_Add, Supp_Phone) VALUES (%s, %s, %s, %s)",
                           
    GetSQLValueString($HTTP_POST_VARS['Supp_Id'], "text"),
                           
    GetSQLValueString($HTTP_POST_VARS['Supp_Name'], "text"),
                           
    GetSQLValueString($HTTP_POST_VARS['Supp_Add'], "text"),
                           
    GetSQLValueString($HTTP_POST_VARS['Supp_Phone'], "text"));
                           

      
      
    $Result1 mysql_query($insertSQL) or die(mysql_error());
    }
    ?>

  2. #2
    Join Date
    Jan 2007
    Location
    Petaling Jaya
    Posts
    867
    Rep Power
    169
    well, if u ask me to see any difference on the codes i can tell is this 2

    GetSQLValueString($HTTP_POST_VARS['Supp_Id'], "text")
    GetSQLValueString($_POST['Report_No'], "text"),

    anyway, my suggestion is, dun go so fast in inserting a while lot of data without trying it 1st. Do a similar codes but only insert 1 or 2 data, just to make sure everything is working fine. Then when u r sure the data is inserted to the db successfully, then only u proceed with the rest of ur data

    if u straight away copy and paste and modify, u wont know where's does the error comes from if the data cannot b insert

  3. #3
    Join Date
    Mar 2007
    Location
    Port Klang, Malaysia
    Posts
    20
    Rep Power
    0
    Quote Originally Posted by yipguseng View Post

    GetSQLValueString($HTTP_POST_VARS['Supp_Id'], "text")
    GetSQLValueString($_POST['Report_No'], "text"),
    Actually, is there any difference between $HTTP_POST_VARS and $_POST ??
    it is because, i used other database with the same method/code to insert.. n it worked fine(data inserted).. so, dunno whts wrong with this database..

  4. #4
    Join Date
    Mar 2007
    Location
    Port Klang, Malaysia
    Posts
    20
    Rep Power
    0
    okay.. now im using this sql to insert..
    PHP Code:
    $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'];
    $DOEvent=$_POST['Desc_of_Event'];

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

    $result=mysql_query($query) or die( "There was an error running '$query' " mysql_error()); 
    the values were inserted, but it became like this when i browse the database in phpadmin.. (shows in the picture link below). the first columns empty..



    when i refresh the form, there would be an sql error
    There was an error running 'INSERT INTO Report(Report_No, Name_of_Vessel, Report_Time, Date_of_Accident, Time_of_Accident, IP_Name, IP_Surname, IP_DOB, IP_Nationality, IP_Sex, IP_Address, IP_Passport, Desc_of_Event) VALUES ('','', '','', '','', '','', '', '','','', '')' Duplicate entry '' for key 1

  5. #5
    Join Date
    Jan 2007
    Location
    Petaling Jaya
    Posts
    867
    Rep Power
    169
    if ur Report_No is ur primary key, i assume u will b using auto-increment right? so if u r using auto-increment, u do not need to grab any variable from the form. so the $RNo=$_POST['Report_No']; shouldn't be there so as in the INSERT sql.

    of course u will encounter such error bcoz u r using xxxx=$_POST["xxxx"] to grab the variables stored in the https, so once u refresh it, everything in the https will be refresh and store nothing, so ur $_POST has nothing to grab and tat correspond to ('','', '','', '','', '','', '', '','','', '')

    again the same advise. Try and few data 1st before u really put in so many into the test.

  6. #6
    Join Date
    Mar 2007
    Location
    Port Klang, Malaysia
    Posts
    20
    Rep Power
    0
    Thanks.. but my Report_No(primary key) in Report table is not an auto increment.. it has to be filled in by users. and yes, i had tried with few data before, but it still has the same prob..
    i think i got the
    There was an error running 'INSERT INTO Report(Report_No, Name_of_Vessel, Report_Time, Date_of_Accident, Time_of_Accident, IP_Name, IP_Surname, IP_DOB, IP_Nationality, IP_Sex, IP_Address, IP_Passport, Desc_of_Event) VALUES ('','', '','', '','', '','', '', '','','', '')' Duplicate entry '' for key 1
    because of the blank columns.. (shows on the image..dont know why it became like tht..) i'm only key in data for one time.

  7. #7
    Join Date
    Jan 2007
    Location
    Petaling Jaya
    Posts
    867
    Rep Power
    169
    is seldom having the database's primary key to be insert by user themselve.

    but anyway, i will try it out tonight when i m at home. coz i cant test it now in the offfice ^^

    hope u can wait, but if u have any update on it do post it here
    mean time if anybody out there which see this and knows the solution, please do reply

  8. #8
    Join Date
    Mar 2007
    Location
    Port Klang, Malaysia
    Posts
    20
    Rep Power
    0
    okay.. i had discovered that everytime i opened my form on the browser (without inserting any value), there would be blank columns in my database..
    why is that??

  9. #9
    Join Date
    Jan 2007
    Location
    Petaling Jaya
    Posts
    867
    Rep Power
    169
    sorry for the late trial on this coz is been bz for me for the whole week in the office as well as at home.

    but from wat u said above, i would like to know is all ur sql. php processing code and form in the same page?

  10. #10
    Join Date
    Mar 2007
    Location
    Port Klang, Malaysia
    Posts
    20
    Rep Power
    0
    i don't think it's enough to post all in one page right??
    or hw do u want me to do??

  11. #11
    Join Date
    Mar 2007
    Location
    Port Klang, Malaysia
    Posts
    20
    Rep Power
    0
    yeyy.. finally succeeded!!
    i can insert my data into database without 'that blank columns'!!
    i tried using a hidden field named MM_insert on the form.

    this is my code:
    PHP Code:
    if (isset($_POST['MM_insert']))
    {
        
    $NVessel $_POST['Name_of_Vessel'];
        
    $RNo $_POST['Report_No'];
        
    $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'];
        
    $DOEvent=$_POST['Desc_of_Event'];
        
        
    $query "INSERT INTO Report (Name_of_Vessel, Report_No, Report_Time, Date_of_Accident, Time_of_Accident, IP_Name, IP_Surname, 
                  IP_DOB, IP_Nationality, IP_Sex, IP_Address, IP_Passport, Desc_of_Event) VALUES('
    $NVessel', '$RNo', '$RTime','$DAccident',
                 '
    $TAccident','$IPName', '$IPSname','$IPDOB', '$IPNat','$IPsex','$IPAdd','$IPPass', '$DOEvent')";
        
    mysql_query($query) or die("Error inserting into Report: ".mysql_error());

    of course, i tested it with 2 data first.. then, when there's nothing wrong with it, i continue with others..
    but sadly, i still had problems with the sql to view all the data..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. data cleansing, data management and web design
    By fiafeehily in forum Other Internet Marketing Methods
    Replies: 0
    Last Post: 06-12-2009, 07:48 PM
  2. insert data into multiple table
    By azmaliya in forum Website Programming
    Replies: 18
    Last Post: 06-08-2005, 11:02 AM
  3. camne nak masuk DB??
    By adib in forum Website Programming
    Replies: 2
    Last Post: 11-06-2004, 06:55 PM
  4. Jemputlah Masuk!
    By Innovane in forum Websites Review and Suggestion
    Replies: 14
    Last Post: 12-04-2004, 04:37 PM
  5. baca data dari lbh satu table
    By adique_7 in forum Website Programming
    Replies: 1
    Last Post: 02-05-2002, 12:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37