Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: saving

  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    saving

    hi,
    i created a form in which you will put all the data, my prblem is, I want to save it in the database and at the same time it will appear on another page with a table form, I don't know if i used the right code.. please check my code below...

    thanks

    ====this is the form code===
    <form method="get" action ="#.php">
    <table border=0 class="sam" align=center>
    <td class="td1"><br><br>
    <br>Users Information
    <td class="td1"><td class="td1"><td class="td1">
    <tr><td>
    Department:<td>
    <select name="department">
    <option value="Select...">Select...</option>
    <option value="Cebu">Cebu</option>
    <option value="Davao">Davao</option>
    <option value="Executive">Executive</option>
    <option value="Finance">Finance</option>
    <option value="Marketing">Marketing</option>
    <option value="MIS">MIS</option>
    <option value="Quality and Customer Care">Quality and Customer Care</option>
    <option value="Sales">Sales</option>
    <option value="Service">Service</option>
    <option value="Supply Chain">Supply Chain</option></select>
    </td>
    <td>
    &nbspDate:<td> <input type="text" name="dept" size="10">
    </td>
    <tr>
    <td>
    User Name:<td><input type="text" name="user" size="27">
    </td>
    <tr>
    <td class="td1">
    <br>
    Issued Equipment
    <td class="td1"><td class="td1"><td class="td1">
    </td>
    <tr>
    <td>
    Form:<td><select name="form">
    <option value="Select...">Select...</option>
    <option value="Desktop">Desktop</option>
    <option value="Laptop">Laptop</option>
    <option value="Notebook">Notebook</option>
    </select>
    </td>

    ===this is the save code===
    <?php

    header("Expires: Thu, 17 May 2001 10:17:17 GMT");
    header("Last-Modified: ".gmdate("D, d M Y H:i:s"). " GMT");
    header("cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");

    session_start();
    $_SESSION['mainFrameurl']=$_SERVER["REQUEST_URI"];

    include_once("images/connect.php");

    $sserial = $_REQUEST['serial'];

    if($sserial)

    {
    $sql="SELECT*FROM tblmaster WHERE serial =".$sserial;

    $result = mysql_query($sql);

    $sLoaddepartment = mysql_result($result,$i,"department");
    $sLoaduserName = mysql_result($result,$i,"userName");
    $sLoadissued = mysql_result($result,$i,"issued");

    $sLoadform = mysql_result($result,$i,"form");
    $sLoadbrand = mysql_result($result,$i,"brand");
    $sLoadmodel = mysql_result($result,$i,"model");
    $sLoadserial = mysql_result($result,$i,"serial");
    $sLoaddatepurchased = mysql_result($result,$i,"datepurchased");

    $sLoadprocessor = mysql_result($result,$i,"processor");
    $sLoadsystem = mysql_result($result,$i,"system");
    $sLoadusb = mysql_result($result,$i,"usb");
    $sLoadmemory = mysql_result($result,$i,"memory");
    $sLoadharddisk = mysql_result($result,$i,"harddisk");
    $sLoadphone = mysql_result($result,$i,"phone");

    $sLoadcost = mysql_result($result,$i,"cost");
    $sLoadremarks = mysql_result($result,$i,"remarks");

    }
    ?>

    ====and this is the table code where I want those data to appear====
    <table border=1>
    <th class="td1">Department</th>
    <th class="td1">User Name</td></th>
    <th class="td1">Form</td></th>
    <th class="td1">Type/Model</td></th>
    <th class="td1">Brand</td></th>
    <th class="td1">Date Purchased</td></th>
    <!---the primary key-->
    <th class="td1">Serial Number</td></th>
    <th class="td1">Processor</td></th>
    <th class="td1">Operating System</td></th>
    <th class="td1">Memory</td></th>
    <th class="td1">USB Flash Drive</td></th>
    <th class="td1">Harddisk Capacity</td></th>
    <th class="td1">Telephone Model</td></th>
    <th class="td1">Acquisition Cost</td></th>

    <tr>
    <td name="department"></td>
    <td name="user"></td>
    <td name="form"></td>
    <td name="model"></td>
    <td name="brand"></td>
    <td name="purchase"></td>
    <td name="serial"></td>

  • #2
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Check the links here and here.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #3
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    You are trying to SELECT but never actually INSERT INTO the database. You have to insert the values into the table before you can SELECT them. Try reading up some one SQL.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #4
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    adding and saving

    ohh I see thanks....but i'm confuse where do i put that INSERT INTO code..do i need to create another file? ...

    INSERT INTO 'tblmasterinvent' ('department', 'userName', 'issued', 'form', 'brand', 'model', 'serial', 'datepurchased', 'processor', 'system', 'usb', 'memory', 'harddisk', 'phone', 'cost', 'remarks' )

    is this what you mean? where do i put this one.... also i'm using phpmyadmin... i created there my database and table.....

    thanks again...

  • #5
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    You should add it to the save code...since the insert is what actually saves the information...also in your INSERT code you're inserting those static values and not variables.

    PHP Code:
    <?php

    header
    ("Expires: Thu, 17 May 2001 10:17:17 GMT");
    header("Last-Modified: ".gmdate("D, d M Y H:i:s"). " GMT");
    header("cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");

    session_start();
    $_SESSION['mainFrameurl']=$_SERVER["REQUEST_URI"];

    include_once(
    "images/connect.php");

    $sserial $_REQUEST['serial'];

    if(
    $sserial)

    {
    $sql "INSERT INTO 'tblmasterinvent' ('department', 'userName', 'issued', 'form', 'brand', 'model', 'serial', 'datepurchased', 'processor', 'system', 'usb', 'memory', 'harddisk', 'phone', 'cost', 'remarks' )";

    $result mysql_query($sql) or die(mysql_error()); // you will want error testing while you're developing

    $sql="SELECT*FROM tblmaster WHERE serial =".$sserial;

    $result mysql_query($sql) or die(mysql_error()); //same here

    $sLoaddepartment mysql_result($result,$i,"department");
    $sLoaduserName mysql_result($result,$i,"userName");
    $sLoadissued mysql_result($result,$i,"issued");

    $sLoadform mysql_result($result,$i,"form");
    $sLoadbrand mysql_result($result,$i,"brand");
    $sLoadmodel mysql_result($result,$i,"model");
    $sLoadserial mysql_result($result,$i,"serial");
    $sLoaddatepurchased mysql_result($result,$i,"datepurchased");

    $sLoadprocessor mysql_result($result,$i,"processor");
    $sLoadsystem mysql_result($result,$i,"system");
    $sLoadusb mysql_result($result,$i,"usb");
    $sLoadmemory mysql_result($result,$i,"memory");
    $sLoadharddisk mysql_result($result,$i,"harddisk");
    $sLoadphone mysql_result($result,$i,"phone");

    $sLoadcost mysql_result($result,$i,"cost");
    $sLoadremarks mysql_result($result,$i,"remarks");

    }
    ?>
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #6
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks again..... i tried what you've suggested, when i hit the save button, this messages appear You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1...i also tried to replace the $sLoad into this $add like this...

    $adddepartment = $_REQUEST['department'];
    $adduserName = $_REQUEST['userName'];
    $addissued = $_REQUEST['issued'];

    it also do the same... what will I do? I also want that if I hit the save button it will give me a message if it successfully save on my database for confirmation.... hope u can help me again please...
    Last edited by angelstar; 01-02-2008 at 07:11 AM.

  • #7
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Just a note..I'm just copying and pasting your code I'm not actually debugging your script b/c I want you to learn. But I will point out the things that I do notice.

    PHP Code:
    $sql "INSERT INTO 'tblmasterinvent' ('department', 'userName', 'issued', 'form', 'brand', 'model', 'serial', 'datepurchased', 'processor', 'system', 'usb', 'memory', 'harddisk', 'phone', 'cost', 'remarks' )"//you quoted the table name (tblmasterinvent).....those should be either left off or replaced with backticks ( ` ). 
    Review this link.
    http://www.w3schools.com/php/php_mysql_insert.asp
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #8
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Actually, I just looked at all your code and I've noticed a few things wrong such as you using the "get" method opposed to "post". I'm actually on my way to bed but if you haven't figured anything out in a few hours then I'll break it all down for you.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #9
    Regular Coder
    Join Date
    Dec 2007
    Location
    Nebraska
    Posts
    113
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Input values that are inserted into queries also need to be escaped using the appropriate escaping function for the database you are using. In this case mysql_real_escape_string().

    There are security considerations that require escaping, but you also can run into trouble if any input contains single quotes (like the name O'Grady).

    Find a tutorial on PHP and MySQL. There are plenty out there. You reall need at least knowledge of the basics of database access, SQL and security to do this sort of thing right.
    Deliver yesterday, code today, think tomorrow.

  • #10
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry for my late response, just trying to managed my time, 'coz I'm a working student...anyway thanks for your advice..I'm going to try what you all said, hope I can make it right now.. Thanks again..

  • #11
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey, thanks sooooo much! I did it! it save to my database, now i'm trying to do the next step, that it will appear into other page all the data that i've save for viewing.. the table form.... can you give me some sort of hint.. what to do...


    thanks so much again

    ==this is the sample table that i'm working on===
    table border=1>
    <th class="td1">Department</th>
    <th class="td1">User Name</td></th>
    <th class="td1">Form</td></th>
    <th class="td1">Type/Model</td></th>
    <th class="td1">Brand</td></th>
    <th class="td1">Date Purchased</td></th>
    <!---the primary key-->
    <th class="td1">Serial Number</td></th>
    <th class="td1">Processor</td></th>
    <th class="td1">Operating System</td></th>
    <th class="td1">Memory</td></th>
    <th class="td1">USB Flash Drive</td></th>
    <th class="td1">Harddisk Capacity</td></th>
    <th class="td1">Telephone Model</td></th>
    <th class="td1">Acquisition Cost</td></th>


  •  

    Posting Permissions

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