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.
I take it you didn't finish reading the SQL portion of that book.. You'd use the SELECT query statement.
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.
Compact code, use faster functions, open and close less variables etc.. as said you need to be more specific.