SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PROBLEM IN INSERTING data in the mysql table

    Hello,
    I have problem in inserting data in a Mysql table. I have a table with 31 fields, Id being auto incremental.
    But when I want to insert record in a table it is falling to insert. Where Iam going wrong???
    Your help will be highly appreciated.


    PHP Code:
    include ('Connections/conn.php');

    //Declaring variables, 
         
    $tUsername=$_POST['Username'];
         
    $tDivision=$_POST['Division'];
         
    $tExtension=$_POST['Extension'];
         
    $tStation=$_POST['Station'];
         
    $tSummary=$_POST['Summary'];
         
    $tCategory=$_POST['Category'];
         
    $tDescription=$_POST['Description'];
         
    $tAttachment=$_POST['Attachment'];
         
    $tResponse=$_POST['Response'];
         
    $tStatus=$_POST['Status'];
       
       
    $userdetails=mysql_query("select name from phpdesk_staff where username='$tUsername'")or die("<center>
    <font face=\"arial\" size=\"2\">Error!! Select Operation Failed. Reason: "
    .mysql_error()."</font></center>");
    $row mysql_fetch_object($userdetails);
    $LnameandFname$row->name;
     
    $userid=mysql_query("select id from phpdesk_staff where username='$tUsername'")or die("<center>
    <font face=\"arial\" size=\"2\">Error!! Select Operation Failed. Reason: "
    .mysql_error()."</font></center>");
    $row mysql_fetch_object($userid);
    $usernameid$row->id
       
       
    $defadmin=mysql_query("select admin from phpdesk_categories where name='$tCategory'")or die("<center>
    <font face=\"arial\" size=\"2\">Error!! Select Operation Failed. Reason: "
    .mysql_error()."</font></center>");
    $row mysql_fetch_object($defadmin);
    $sectionadmin$row->admin;   
     
     
    $selectadmin=mysql_query("select role_holder from phpdesk_admins where name='$sectionadmin'")or die("<center>
    <font face=\"arial\" size=\"2\">Error!! Select Operation Failed. Reason: "
    .mysql_error()."</font></center>");
    $row mysql_fetch_object($selectadmin);
    $selectadminfinal$row->role_holder;   
         

    $usertype=mysql_query("select type from phpdesk_users where username='$tUsername'")or die("<center>
    <font face=\"arial\" size=\"2\">Error!! Select Operation Failed. Reason: "
    .mysql_error()."</font></center>");
    $row mysql_fetch_object($usertype);
    $selectusertype$row->type;   
            
    $tsection=mysql_query("select section from phpdesk_admins where name='$sectionadmin'")or die("<center>
    <font face=\"arial\" size=\"2\">Error!! Select Operation Failed. Reason: "
    .mysql_error()."</font></center>");
    $row mysql_fetch_object($tsection);
    $adminsection$row->section;        
       
       
       
       
           
    //Time functions, with format HH:MM:SS    
      
    $today =time("h:i:s ");
      
    $curtime time();
      
    $utcdiff date('Z'$curtime);  // get difference to UTC in seconds
      
    $bmttime $curtime $utcdiff 7200;  // BMT = UTC+0100
      
    $deecho ='     ' date('H:i:s'$bmttime) . ' ' date(''$curtime);
      
    $testtime=time("his ");



    $query "SELECT * FROM phpdesk_users  WHERE  username='$tUsername'";




    $mysql_query="INSERT INTO phpdesk_tickets(admin_id,admin_user,admin_email,title,edited,waiting,text,status,opened, priority,group,owner,fields,values,attach,replies,userid,station,division,phone,assigned,category,unit,reassigned,
    section,openedby,editedby,assigned_on,closed,closedby)"
    ."VALUES ('$usernameid','$tUsername', 'noemail','$tSummary','$testtime','$selectusertype','$tDescription','Open','$testtime','medium','nill','$LnameandFname','nil','nil','$tAttachment','0','0','$tUsername','$tStation','$tDivision','$tExtension','$selectadminfinal','$tCategory','0','0','$adminsection','nill','$testtime','0','nill')";
     echo
    $mysql_query ;
     
    mysql_query($mysql_query) or die('Error, insert query'); 
    ?> 


    DROP TABLE IF EXISTS `phpdesk_tickets`;

    CREATE TABLE `phpdesk_tickets` (
    `id` int(255) NOT NULL auto_increment,
    `admin_id` int(255) NOT NULL default '0',
    `admin_user` varchar(255) NOT NULL default '',
    `admin_email` varchar(255) NOT NULL default '',
    `title` varchar(255) NOT NULL default '',
    `edited` int(32) NOT NULL default '0',
    `waiting` varchar(255) NOT NULL default '',
    `text` mediumtext NOT NULL,
    `status` varchar(6) NOT NULL default '',
    `opened` int(32) NOT NULL default '0',
    `priority` varchar(6) NOT NULL default '',
    `group` varchar(255) NOT NULL default '',
    `owner` varchar(255) NOT NULL default '',
    `fields` varchar(255) NOT NULL default '',
    `values` mediumtext NOT NULL,
    `attach` varchar(255) NOT NULL default '',
    `replies` int(100) NOT NULL default '0',
    `userid` varchar(255) NOT NULL default '',
    `station` varchar(50) NOT NULL default '',
    `division` varchar(100) NOT NULL default '',
    `phone` varchar(100) NOT NULL default '',
    `assigned` varchar(100) NOT NULL default '',
    `category` varchar(100) NOT NULL default '',
    `unit` varchar(100) NOT NULL default '',
    `reassigned` int(11) NOT NULL default '0',
    `section` varchar(100) NOT NULL default '',
    `openedby` varchar(100) NOT NULL default '',
    `editedby` varchar(100) NOT NULL default '',
    `assigned_on` int(11) NOT NULL default '0',
    `closed` int(11) NOT NULL default '0',
    `closedby` varchar(100) NOT NULL default '',
    PRIMARY KEY (`id`)
    ) TYPE=MyISAM;

    SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

  2. #2
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1st of all u post ur thread twice,,, try to post once...
    2nd what error u got when inserting data to table...
    Show the error.

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes as mmarif4u said, there is no meaning of giving such long PHP code. Instead its better to give what error you got while inserting data so that others will know what may be the solution.

  4. #4
    Quake 1 Addict CreedFeed's Avatar
    Join Date
    Feb 2002
    Location
    Milwaukee, WI
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change your last line of code to:

    PHP Code:
    mysql_query($mysql_query) or die('Error, insert query: 'mysql_error()); 
    The mysql_error() function will give you some clue of what the problem is.
    -- Steve Caponetto
    Quake 1 Resurrection :: CreedFeed

  5. #5
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean 1st of all u post ur thread twice,,, try to post once???
    Iam not receiving any error?

  6. #6
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I would suggest writing sql query in a little bit different way. For example:
    PHP Code:
    $sql "INSERT INTO phpdesk_tickets SET";
    $sql .= " admin_id = '".$usernameid."'";
    $sql .= ", admin_user = '".mysql_real_escape_string($tUsername)."'";
    $sql .= ", admin_email = 'noemail'";
    $sql .= ", title = '".mysql_real_escape_string($tSummary)."'";
    //etc... 
    This way, you are sure you are not missing any field, or don't have more than you need.
    I'm guessing that's the problem there. If that doesn't work, try echoing query or add something like this:
    PHP Code:
    mysql_query($mysql_query) or die('Query error. Error:'.mysql_error().' Query was: '.$mysql_query); 
    -- Jelena --

  7. #7
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See the main page of forum for php ur post is twice:
    one is: PROBLEM IN INSERTING data in the mysql table and
    other is: INSERTING data in the mysql table

    If u got no error then try the error function,
    try this to know the error what error it is:

    PHP Code:
    mysql_query($mysql_query) or die('Error, insert query: ' mysql_error()); 

  8. #8
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This the error Iam receiving.'group,owner,fields,values,attach,replies,userid,station,division,phone,assigned,' at line 1

  9. #9
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wait a little i want to see ur query..

  10. #10
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $mysql_query="INSERT INTO phpdesk_tickets(admin_id,admin_user,admin_email,title,edited,waiting,
    text,status,opened,priority,group,owner,fields,values,attach,replies,userid,station,division,
    phone,assigned,category,unit,reassigned, 
    section,openedby,editedby,assigned_on,closed,closedby) VALUES ('
    $usernameid','$tUsername', 
    'noemail','
    $tSummary','$testtime','$selectusertype','$tDescription','Open','$testtime','medium',
    'nill','
    $LnameandFname','nil','nil','$tAttachment','0','0','$tUsername','$tStation','$tDivision',
    '
    $tExtension','$selectadminfinal','$tCategory','0','0','$adminsection','nill','$testtime','0','nill')"
    echo
    $mysql_query 
    mysql_query($mysql_query) or die('Error, insert query:' mysql_error()); 
    ?> 
    try this one may be it works...

  11. #11
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have not tested right now but your problem must be in your field named "group" because this is reserved word by mysql database. so please try changing your field name group to another something like fldGroup then try. Also i noticed another field named text. This is database type in mysql. so change this field too something else.
    Last edited by Raju Gautam; Feb 5, 2007 at 03:52.

  12. #12
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,322
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    duplicate threads merged
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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