Need some help

Discussion in 'PHP' started by mfp, Jan 6, 2009.

  1. #1
    Hi,

    I am new to php & mysql, but i have knowledge of C++. but i wana learn php & mysql. I have read "Learning PHP and MySQL, Second Edition
    by Michele E. Davis and Jon A. Phillips" book to learn php & mysql. I am using XAMPP. Now I wana create a program for my work. I am entering data into MySql with this code
    
    <html>
    <head>
    <title>Letter</title>
    </head>
    
    <body>
    
    <p align="center"><font color="#800080"><i><font size="4">Title</font></i></font></p>
    
    
    
    <form action="consent.php" method="post">
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
      <tr>
        <td width="22%">Insured Name</td>
        <td width="3%" align="center"> :</td>
        <td width="135%"> <input type="text" name="insured_name" size="40" /></td>
      </tr>
      <tr>
        <td width="22%">Insured Address</td>
        <td width="3%" align="center"> :</td>
        <td width="135%"> <input type="text" name="insured_address" size="40" /></td>
      </tr>
      <tr>
        <td width="22%">Policy No</td>
        <td width="3%" align="center"> :</td>
        <td width="135%"> <input type="text" name="policy_no" size="40" /></td>
      </tr>
      <tr>
        <td width="22%">Policy Period</td>
        <td width="3%" align="center"> :</td>
        <td width="135%"> <input type="text" name="policy_wef" size="40" /></td>
      </tr>
      <tr>
        <td width="22%">Vehicle No</td>
        <td width="3%" align="center"> :</td>
        <td width="135%"> <input type="text" name="vehicle_no" size="40" /></td>
      </tr>
      <tr>
        <td width="22%">Vehicle Make & Model</td>
        <td width="3%" align="center"> :</td>
        <td width="135%"> <input type="text" name="vehicle_make_model" size="40" /></td>
      </tr>
      <tr>
        <td width="22%">Engine No</td>
        <td width="3%" align="center"> :</td>
        <td width="135%"> <input type="text" name="engine_no" size="40" /></td>
      </tr>
      <tr>
        <td width="22%">Chassis No</td>
        <td width="3%" align="center"> :</td>
        <td width="135%"> <input type="text" name="chassis_no" size="40" /></td>
      </tr>
      <tr>
        <td width="22%">Date of Registration</td>
        <td width="3%" align="center"> :</td>
        <td width="135%"> <input type="text" name="date_of_reg" size="40" /></td>
      </tr>
      <tr>
        <td width="22%">Date of Loss</td>
        <td width="3%" align="center"> :</td>
        <td width="135%"> <input type="text" name="date_of_loss" size="40" /></td>
      </tr>
      <tr>
        <td width="22%">Registering Authority</td>
        <td width="3%" align="center"> :</td>
        <td width="135%"> <input type="text" name="rto" size="40" /></td>
      </tr>
      </table>
      <br />
    <input type="submit" value="Generate Consent Letter" />
    </form>
    
    
    </body>
    
    </html>
    
    Code (markup):
    & the code of consent.php is

    
    <?php
    require_once("config.php");
    $con = mysql_connect("$db_host","$db_username","$db_password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    mysql_select_db("db_name", $con);
    $sql="INSERT INTO bajaj_consent VALUES ('NULL','$_POST[insured_name]','$_POST[insured_address]','$_POST[policy_no]','$_POST[policy_wef]','$_POST[vehicle_no]','$_POST[vehicle_make_model]','$_POST[engine_no]','$_POST[chassis_no]','$_POST[date_of_reg]','$_POST[date_of_loss]','$_POST[rto]')";
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
      mysql_close($con);
    echo "1 record added";
    ?>
    
    Code (markup):
    & this code is working fyn. But now i wana retrieve data from table but in a letter format, like

    
    letter
    
    $insured_name,
    $insured_address, SOME TEXT HERE, $vehicle_no, SOME MORE TEXT HERE. 
    
    Code (markup):
    I know about smarty template engine. it can be done with smarty, but i dont know how can i retrieve data from table & send it to template file. how can i do this? please help me.
     
    mfp, Jan 6, 2009 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I take it you didn't finish reading the SQL portion of that book.. You'd use the SELECT query statement.
     
    zerxer, Jan 6, 2009 IP
  3. JWRmedia

    JWRmedia Banned

    Messages:
    499
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can look over these free PHP lessons. There is a section dealing with forms as well.
     
    JWRmedia, Jan 7, 2009 IP
  4. SiteTalkZone

    SiteTalkZone Peon

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Why don't you put this:

    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    mysql_select_db("db_name", $con);
    
    PHP:
    In your config file?

    Also just use SELECT to get the information out of your DB.

    $result = mysql_fetch_array ( mysql_query("SELECT insured_address, vehicle_no FROM bajaj_consent"));

    Something like that.
     
    SiteTalkZone, Jan 7, 2009 IP
  5. mfp

    mfp Guest

    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks bro..
     
    mfp, Jan 8, 2009 IP
  6. SiteTalkZone

    SiteTalkZone Peon

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    No worries :)
     
    SiteTalkZone, Jan 11, 2009 IP
  7. skriblk

    skriblk Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    How do you optimize with PHP
     
    skriblk, Jan 11, 2009 IP
  8. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #8
    Going to be any more specific? General optimization tips could fill several books.

    Dan.
     
    Danltn, Jan 11, 2009 IP
  9. SiteTalkZone

    SiteTalkZone Peon

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Compact code, use faster functions, open and close less variables etc.. as said you need to be more specific.
     
    SiteTalkZone, Jan 12, 2009 IP