Jump to content

metabee

Member
  • Posts

    9
  • Joined

  • Last visited

Posts posted by metabee

  1. Hello, I am facing problems of trying to insert exploded values into the database.

     

    I always get this 000 0000-00-00 00:00:000 format

     

    For example I type 100 2000-10-02 06:00:10 6 in the three textboxes,

     

    100 -> textbox 1

    2000-10-02 06:00:10 -> textbox 2

    6 -> textbox 3

     

    it still remain the same 000 0000-00-00 00:00:000.

     

    I want to get this data 100|2000-10-02 06:00:10|6 in sql database.

     

    Can anyone how make it to work?

    1.zip

  2. When you use the above code, what do you get? Errors? If so, what specific error messages are you getting?

     

    I always get this 000 0000-00-00 00:00:000 format

     

    but not this 000|0000-00-00 00:00:00|0 format

     

    For example I type 100 2000-10-02 06:00:10 6 in the three textboxes,

     

    100 -> textbox 1

    2000-10-02 06:00:10 -> textbox 2

    6 -> textbox 3

     

    it still remain the same 000 0000-00-00 00:00:000.

     

    I want to get this data 100|2000-10-02 06:00:10|6 in sql database.

     

    Please help me to solve.

     

     

    textbox codes found in insert.php

    <!--one textbox submit-->
    <!--<tr>-->
    <!--<td>Schedule Time</td>-->
    <!--<td>:</td>-->
    <!--<td><input name="schedule_time" type="text" id="schedule_time"></td>-->
    <!--</tr>-->
    
    
    
    <!--three textboxes submission of schedule_time  000|0000-00-00 00:00:00|0  -->
    <td>Schedule Time</td>
    <td>:</td>
    <td>
    <input type="text" name="schedule_time" id="schedule_time" value="<?php echo $ary[0]; ?>"> <!--000-->
    <input type="text" name="schedule_time" id="schedule_time" value="<?php echo $ary[1]; ?>"> <!--0000-00-00 00:00:00-->
    <input type="text" name="schedule_time" id="schedule_time" value="<?php echo $ary[2]; ?>"> <!--0-->
    </td>
    </tr>

     

     

     

    insert_ac.php

    // Get values from form  
    $name=$_POST['name']; 
    $lastname=$_POST['lastname']; 
    $email=$_POST['email']; 
    $schedule_time = $_POST['schedule_time']; 
    
    
    $val = "000|0000-00-00 00:00:00|0"; 
    
    $ary = explode("|", $val); 
    
    $a = $ary[0]; 
    $b = $ary[1]; 
    $c = $ary[2]; 
    
    $abc = $a . " " . $b .  $c; 
    
    
    
    
    
    // Insert data into mysql  
    $sql="INSERT INTO $tbl_name(name, lastname, email, schedule_time)VALUES('$name', '$lastname', '$email', '$abc')"; 
    $result=mysql_query($sql); 
    
    // if successfully insert data into database, displays message "Successful".  
    if($result){ 
    echo "Successful"; 
    echo "<BR>"; 
    echo "<a href='insert.php'>Back to main page</a>"; 
    } 
    
    else { 
    echo "ERROR"; 
    } 
    
    // close connection  
    mysql_close(); 
    ?>
    
    
    

     

    database file for import

    --
    -- Database: `1`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `test_mysql`
    --
    
    CREATE TABLE IF NOT EXISTS `test_mysql` (
     `id` int(4) NOT NULL AUTO_INCREMENT,
     `name` varchar(65) NOT NULL DEFAULT '',
     `lastname` varchar(65) NOT NULL DEFAULT '',
     `email` varchar(65) NOT NULL DEFAULT '',
     `schedule_time` varchar(25) CHARACTER SET utf8 NOT NULL DEFAULT '000|0000-00-00 00:00:00|0',
     PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
    
    --
    -- Dumping data for table `test_mysql`
    --
    
    INSERT INTO `test_mysql` (`id`, `name`, `lastname`, `email`, `schedule_time`) VALUES
    (1, 'john', 'lere', 'yhh@hotmail.com', '000|0000-00-00 00:00:00|0'),
    

  3. Hello, I want ask about how to use explode to split timestamp? into 3 array variable so that

     

    3 textboxes will combine and insert together into one fieldname which is schedule_time with | as the delimiter.

     

    Please help me solve this explode function problem.

     

    insert_ac.php

    <?php
    
    $host="localhost"; // Host name 
    $username="root"; // Mysql username 
    $password=""; // Mysql password 
    $db_name="1"; // Database name 
    $tbl_name="test_mysql"; // Table name 
    
    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // Get values from form 
    $name=$_POST['name'];
    $lastname=$_POST['lastname'];
    $email=$_POST['email'];
    $schedule_time = $_POST['schedule_time'];
    
    
    $val = "000|0000-00-00 00:00:00|0";
    
    $ary = explode("|", $val);
    
    $a = $ary[0];
    $b = $ary[1];
    $c = $ary[2];
    
    $abc = $a . " " . $b .  $c;
    
    
    
    
    
    // Insert data into mysql 
    $sql="INSERT INTO $tbl_name(name, lastname, email, schedule_time)VALUES('$name', '$lastname', '$email', '$abc')";
    $result=mysql_query($sql);
    
    // if successfully insert data into database, displays message "Successful". 
    if($result){
    echo "Successful";
    echo "<BR>";
    echo "<a href='insert.php'>Back to main page</a>";
    }
    
    else {
    echo "ERROR";
    }
    
    // close connection 
    mysql_close();
    ?>
    

     

     

    insert.php

    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
    <tr>
    <td><form name="form1" method="post" action="insert_ac.php">
    <table width="100%" border="0" cellspacing="1" cellpadding="3">
    <tr>
    <td colspan="3"><strong>Insert Data Into mySQL Database </strong></td>
    </tr>
    <tr>
    <td width="71">Name</td>
    <td width="6">:</td>
    <td width="301"><input name="name" type="text" id="name"></td>
    </tr>
    <tr>
    <td>Lastname</td>
    <td>:</td>
    <td><input name="lastname" type="text" id="lastname"></td>
    </tr>
    <tr>
    <td>Email</td>
    <td>:</td>
    <td><input name="email" type="text" id="email"></td>
    </tr>
    
    
    <!--one textbox submit-->
    <!--<tr>-->
    <!--<td>Schedule Time</td>-->
    <!--<td>:</td>-->
    <!--<td><input name="schedule_time" type="text" id="schedule_time"></td>-->
    <!--</tr>-->
    
    
    
    <!--three textboxes submission of schedule_time  000|0000-00-00 00:00:00|0  -->
    <td>Schedule Time</td>
    <td>:</td>
    <td>
    <input type="text" name="schedule_time" id="schedule_time" value="<?php echo $ary[0]; ?>"> <!--000-->
    <input type="text" name="schedule_time" id="schedule_time" value="<?php echo $ary[1]; ?>"> <!--0000-00-00 00:00:00-->
    <input type="text" name="schedule_time" id="schedule_time" value="<?php echo $ary[2]; ?>"> <!--0-->
    </td>
    </tr>
    
    <tr>
    <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>
    

    insert_ac.zip

  4. Here is the source code for importing csv file into database.

     

    Hello, Ben

    Please combine this code with your basic php system.

     

    uploadcsv.php

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <title>Upload Record By CSV</title>

    </head>

     

    <body>

    <p><form id="form1" action="" method="post" enctype="multipart/form-data">

    <input type="file" name="file" id="file" size="30" />

    <br/>

    <input type="Submit" value="Upload" name="submitBtn">

    </form>

    </p>

    </body>

    </html>

     

    <?php

    if (isset($_POST['submitBtn'])) { //read csv file

     

    $cnx = mysql_connect("localhost","root","") or die("Error!");

    mysql_select_db("record2",$cnx);

     

    $num = 0;

    if (trim($_FILES["file"]["name"]) == "") {

    print "Please select file to upload.<br>";

    } else { //read file

    $fp = fopen($_FILES["file"]["tmp_name"], 'r') or die("can't open file");

    $strTmp = "";

    while ($csv_line = fgetcsv($fp, 1024)) {

    print '<tr>';

    for ($i = 0, $j = count($csv_line); $i < $j; $i++) {

    $strTmp .= "'".$csv_line[$i]."',";

    }

    $strTmp = substr($strTmp,0,strlen($strTmp)-1); //remove last character (,)

    $sql1 = "insert into players(firstname,lastname) values({$strTmp})"; //******/

    $result1 = mysql_query($sql1) or die("error! {$sql1}");

     

    $num++;

    $strTmp = "";

    }

     

    fclose($fp) or die("can't close file");

    print "\n{$num} records created...";

    }

    }

    ?>

     

     

     

     

    uploadplayers.csv

     

    John, Robert

    Jane, Watson

    Venon, Eddie

  5. How far have you gotten so far? Based on the zip file, it looks like you have gotten things started... are you running into any specific errors or issues?

     

     

    Here are things that I am struck on:

     

    How to do calculation between the two tables (tbltransaction and tblfund)?

     

    the (description) drop down list content is from (fieldname called fund_name from tblfund) is according to how many fund name record in the tblfund table.

     

    When you type in the no_of_units in transaction page, the price fieldname will automatically diplay the value.

     

    The amount fieldname will automatically change the value when you buy or sell the transaction.

  6. I have some questions about transaction page. Here is the attachement contain the sql connection file, transactionfundpage and transactiondb used for importing into PHPMYADMIN (XAMPP Control Panel)

     

    How to create two PHP transaction page (one on buy transaction and the another one for sell transaction)?

     

    when you select the drop downlist (description of stock fund) , some of the fieldnames will display the values automatically

     

    the stock price

    the description

    is the stock the client wants to buy or sell

    if sell

    must see amount left in portfolio

    if buy

    add the amoint to the portfolio

     

    the fund currency is from the tblclient (reporting currency) and so the exchange rates is taken from tblcurrency.

     

    No_of_units = quantity of the stock fund that client wants to buy or sell.

    Price = fund price from tblfund * no_of_units

    Amount = The amount of stock fund left in the portfolio

×
×
  • Create New...