Kampuni ya ICT

Blog

SEHEMU YA II-2: MAANDALIZI JINSI YA KUTUMIA PHP KUINGIZA DATA KATIKA DATABASE

2017.11.2

Hatua ya 1 – Kujenga Database MySQL.

Ingia kwenye localhost/phpmyadmin harafu ingiza jina la database mpya,  apa nimetumia  “student”  kama jina la database mpya ambayo naenda kuijenga kwa ajili ya kuandaa kujenga meza ndani yake, kisha bonyeza  GO button.

baba

Hatua ya 2 – Kujenga meza.

Kwanza kabisa, tunapaswa kuunda meza kwa data yako. Ni utaratibu rahisi sana unaoweza kufanya na phpMyAdmin, ambayo iko jopo lako la kudhibiti hosting. Sasa ingiza jina la meza jipya la “data”, idadi ya mashamba katika meza hiyo ni “5” na bonyeza GO button. Baada ya mashamba kuundwa, skrini inayofuata itaonyeshwa kwako

m4
MUHIMU: Andika maelezo ya darasani ya MySQL uliyounda ya student pamoja na jina la meza yako data, yataitajika katika hatua inayofuata.
Jina la faili ni connect.php Hizi code ndio zinakuwezesha kuunganisha php na database ambayo umeiunda na kukuwezesha kutuma taarifa zako katika database kwa kutumia fomu.

<?php mysql_connect("localhost","root","")or die("not connected"); mysql_select_db("student") or die("no db found"); if(isset($_POST['submit'])){ $name=$_POST['name']; $fname=$_POST['fname']; $roll=$_POST['roll']; $result=$_POST['result']; $query ="insert into data(name,fname,roll,result)values('$name','$fname','$roll','$result')"; if(mysql_query($query)) { echo "Student's data is inserted successfully"; } } ?> <html> <head><title>Student's data</title></head> <body> <form action="connect.php" method="post"> <center><table border="1" width="400" height="300"> <tr> <td colspan="5" align="center" bgcolor="grey">Student's Information</td> </tr> <tr> <td align="right">Name:</td><td><input type="text" name="name"></td> </tr> <tr> <td align="right">Father's Name:</td><td><input type="text" name="fname"></td> </tr> <tr> <td align="right" >Roll No:</td><td><input type="text" name="roll"></td> </tr> <tr> <td align="right">Result:</td><td><input type="text" name="result"></td> </tr> <tr> <td colspan="5" align="center"><input type="submit" name="submit" value="submit"></td> </tr> </table></center> </form> </body> </html>


Author : Dickson Peter