Jump to content

thomas_dev

Members
  • Posts

    17
  • Joined

  • Last visited

thomas_dev's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. actually I had different plans to implement....but I'm struggling at the initial steps itself. below I'll show my databse structure..but don't scold me for it's structure ..or for adding everything in a single table..I had in my mind to play with making USN as primary key since it is unique.in 4gh08cs052 4 has a meaning (i don't know,i shall tell later),gh stands for college code ,08 for 2008 batch students and cs for computer science 052 the roll number of the student.With this in mind i created a database which holds almost everythind and using which one can access all data..first I wanted to play small so that i get to know how I can play with the bigger table.my table structure was like this mysql> desc marks_info; +-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | usn | varchar(30) | YES | | NULL | | | name | text | YES | | NULL | | | branch_name | text | YES | | NULL | | | current_sem | varchar(20) | YES | | NULL | | | s1s1code | char(10) | YES | | NULL | | | s1s1ia | int(2) | YES | | NULL | | | s1s1ex | int(3) | YES | | NULL | | | s1s1tot | int(3) | YES | | NULL | | | s1s1res | text | YES | | NULL | | | s1s2code | char(10) | YES | | NULL | | | s1s2ia | int(2) | YES | | NULL | | | s1s2ex | int(3) | YES | | NULL | | | s1s2tot | int(3) | YES | | NULL | | | s1s2res | text | YES | | NULL | | | s1s3code | char(10) | YES | | NULL | | | s1s3ia | int(2) | YES | | NULL | | | s1s3ex | int(3) | YES | | NULL | | | s1s3tot | int(3) | YES | | NULL | | | s1s3res | text | YES | | NULL | | | s1s4code | char(10) | YES | | NULL | | | s1s4ia | int(2) | YES | | NULL | | | s1s4ex | int(3) | YES | | NULL | | | s1s4tot | int(3) | YES | | NULL | | | s1s4res | text | YES | | NULL | | | s1s5code | char(10) | YES | | NULL | | | s1s5ia | int(2) | YES | | NULL | | | s1s5ex | int(3) | YES | | NULL | | | s1s5tot | int(3) | YES | | NULL | | | s1s5res | text | YES | | NULL | | | s1s6code | char(10) | YES | | NULL | | | s1s6ia | int(2) | YES | | NULL | | | s1s6ex | int(3) | YES | | NULL | | | s1s6tot | int(3) | YES | | NULL | | | s1s6res | text | YES | | NULL | | | s1s7code | char(10) | YES | | NULL | | | s1s7ia | int(2) | YES | | NULL | | | s1s7ex | int(3) | YES | | NULL | | | s1s7tot | int(3) | YES | | NULL | | | s1s7res | text | YES | | NULL | | | s1s8code | char(10) | YES | | NULL | | | s1s8ia | int(2) | YES | | NULL | | | s1s8ex | int(3) | YES | | NULL | | | s1s8tot | int(3) | YES | | NULL | | | s1s8res | text | YES | | NULL | | | s2s1code | char(10) | YES | | NULL | | | s2s1ia | int(2) | YES | | NULL | | | s2s1ex | int(3) | YES | | NULL | | | s2s1tot | int(3) | YES | | NULL | | | s2s1res | text | YES | | NULL | | | s2s2code | char(10) | YES | | NULL | | | s2s2ia | int(2) | YES | | NULL | | | s2s2ex | int(3) | YES | | NULL | | | s2s2tot | int(3) | YES | | NULL | | | s2s2res | text | YES | | NULL | | | s2s3code | char(10) | YES | | NULL | | | s2s3ia | int(2) | YES | | NULL | | | s2s3ex | int(3) | YES | | NULL | | | s2s3tot | int(3) | YES | | NULL | | | s2s3res | text | YES | | NULL | | | s2s4code | char(10) | YES | | NULL | | | s2s4ia | int(2) | YES | | NULL | | | s2s4ex | int(3) | YES | | NULL | | | s2s4tot | int(3) | YES | | NULL | | | s2s4res | text | YES | | NULL | | | s2s5code | char(10) | YES | | NULL | | | s2s5ia | int(2) | YES | | NULL | | | s2s5ex | int(3) | YES | | NULL | | | s2s5tot | int(3) | YES | | NULL | | | s2s5res | text | YES | | NULL | | | s2s6code | char(10) | YES | | NULL | | | s2s6ia | int(2) | YES | | NULL | | | s2s6ex | int(3) | YES | | NULL | | | s2s6tot | int(3) | YES | | NULL | | | s2s6res | text | YES | | NULL | | | s2s7code | char(10) | YES | | NULL | | | s2s7ia | int(2) | YES | | NULL | | | s2s7ex | int(3) | YES | | NULL | | | s2s7tot | int(3) | YES | | NULL | | | s2s7res | text | YES | | NULL | | | s2s8code | char(10) | YES | | NULL | | | s2s8ia | int(2) | YES | | NULL | | | s2s8ex | int(3) | YES | | NULL | | | s2s8tot | int(3) | YES | | NULL | | | s2s8res | text | YES | | NULL | | | s3s1code | char(10) | YES | | NULL | | | s3s1ia | int(2) | YES | | NULL | | | s3s1ex | int(3) | YES | | NULL | | | s3s1tot | int(3) | YES | | NULL | | | s3s1res | text | YES | | NULL | | | s3s2code | char(10) | YES | | NULL | | | s3s2ia | int(2) | YES | | NULL | | | s3s2ex | int(3) | YES | | NULL | | | s3s2tot | int(3) | YES | | NULL | | | s3s2res | text | YES | | NULL | | | s3s3code | char(10) | YES | | NULL | | | s3s3ia | int(2) | YES | | NULL | | | s3s3ex | int(3) | YES | | NULL | | | s3s3tot | int(3) | YES | | NULL | | | s3s3res | text | YES | | NULL | | | s3s4code | char(10) | YES | | NULL | | | s3s4ia | int(2) | YES | | NULL | | | s3s4ex | int(3) | YES | | NULL | | | s3s4tot | int(3) | YES | | NULL | | | s3s4res | text | YES | | NULL | | | s3s5code | char(10) | YES | | NULL | | | s3s5ia | int(2) | YES | | NULL | | | s3s5ex | int(3) | YES | | NULL | | | s3s5tot | int(3) | YES | | NULL | | | s3s5res | text | YES | | NULL | | | s3s6code | char(10) | YES | | NULL | | | s3s6ia | int(2) | YES | | NULL | | | s3s6ex | int(3) | YES | | NULL | | | s3s6tot | int(3) | YES | | NULL | | | s3s6res | text | YES | | NULL | | | s3s7code | char(10) | YES | | NULL | | | s3s7ia | int(2) | YES | | NULL | | | s3s7ex | int(3) | YES | | NULL | | | s3s7tot | int(3) | YES | | NULL | | | s3s7res | text | YES | | NULL | | | s3s8code | char(10) | YES | | NULL | | | s3s8ia | int(2) | YES | | NULL | | | s3s8ex | int(3) | YES | | NULL | | | s3s8tot | int(3) | YES | | NULL | | | s3s8res | text | YES | | NULL | | | s4s1code | char(10) | YES | | NULL | | | s4s1ia | int(2) | YES | | NULL | | | s4s1ex | int(3) | YES | | NULL | | | s4s1tot | int(3) | YES | | NULL | | | s4s1res | text | YES | | NULL | | | s4s2code | char(10) | YES | | NULL | | | s4s2ia | int(2) | YES | | NULL | | | s4s2ex | int(3) | YES | | NULL | | | s4s2tot | int(3) | YES | | NULL | | | s4s2res | text | YES | | NULL | | | s4s3code | char(10) | YES | | NULL | | | s4s3ia | int(2) | YES | | NULL | | | s4s3ex | int(3) | YES | | NULL | | | s4s3tot | int(3) | YES | | NULL | | | s4s3res | text | YES | | NULL | | | s4s4code | char(10) | YES | | NULL | | | s4s4ia | int(2) | YES | | NULL | | | s4s4ex | int(3) | YES | | NULL | | | s4s4tot | int(3) | YES | | NULL | | | s4s4res | text | YES | | NULL | | | s4s5code | char(10) | YES | | NULL | | | s4s5ia | int(2) | YES | | NULL | | | s4s5ex | int(3) | YES | | NULL | | | s4s5tot | int(3) | YES | | NULL | | | s4s5res | text | YES | | NULL | | | s4s6code | char(10) | YES | | NULL | | | s4s6ia | int(2) | YES | | NULL | | | s4s6ex | int(3) | YES | | NULL | | | s4s6tot | int(3) | YES | | NULL | | | s4s6res | text | YES | | NULL | | | s4s7code | char(10) | YES | | NULL | | | s4s7ia | int(2) | YES | | NULL | | | s4s7ex | int(3) | YES | | NULL | | | s4s7tot | int(3) | YES | | NULL | | | s4s7res | text | YES | | NULL | | | s4s8code | char(10) | YES | | NULL | | | s4s8ia | int(2) | YES | | NULL | | | s4s8ex | int(3) | YES | | NULL | | | s4s8tot | int(3) | YES | | NULL | | | s4s8res | text | YES | | NULL | | | s5s1code | char(10) | YES | | NULL | | | s5s1ia | int(2) | YES | | NULL | | | s5s1ex | int(3) | YES | | NULL | | | s5s1tot | int(3) | YES | | NULL | | | s5s1res | text | YES | | NULL | | | s5s2code | char(10) | YES | | NULL | | | s5s2ia | int(2) | YES | | NULL | | | s5s2ex | int(3) | YES | | NULL | | | s5s2tot | int(3) | YES | | NULL | | | s5s2res | text | YES | | NULL | | | s5s3code | char(10) | YES | | NULL | | | s5s3ia | int(2) | YES | | NULL | | | s5s3ex | int(3) | YES | | NULL | | | s5s3tot | int(3) | YES | | NULL | | | s5s3res | text | YES | | NULL | | | s5s4code | char(10) | YES | | NULL | | | s5s4ia | int(2) | YES | | NULL | | | s5s4ex | int(3) | YES | | NULL | | | s5s4tot | int(3) | YES | | NULL | | | s5s4res | text | YES | | NULL | | | s5s5code | char(10) | YES | | NULL | | | s5s5ia | int(2) | YES | | NULL | | | s5s5ex | int(3) | YES | | NULL | | | s5s5tot | int(3) | YES | | NULL | | | s5s5res | text | YES | | NULL | | | s5s6code | char(10) | YES | | NULL | | | s5s6ia | int(2) | YES | | NULL | | | s5s6ex | int(3) | YES | | NULL | | | s5s6tot | int(3) | YES | | NULL | | | s5s6res | text | YES | | NULL | | | s5s7code | char(10) | YES | | NULL | | | s5s7ia | int(2) | YES | | NULL | | | s5s7ex | int(3) | YES | | NULL | | | s5s7tot | int(3) | YES | | NULL | | | s5s7res | text | YES | | NULL | | | s5s8code | char(10) | YES | | NULL | | | s5s8ia | int(2) | YES | | NULL | | | s5s8ex | int(3) | YES | | NULL | | | s5s8tot | int(3) | YES | | NULL | | | s5s8res | text | YES | | NULL | | | s6s1code | char(10) | YES | | NULL | | | s6s1ia | int(2) | YES | | NULL | | | s6s1ex | int(3) | YES | | NULL | | | s6s1tot | int(3) | YES | | NULL | | | s6s1res | text | YES | | NULL | | | s6s2code | char(10) | YES | | NULL | | | s6s2ia | int(2) | YES | | NULL | | | s6s2ex | int(3) | YES | | NULL | | | s6s2tot | int(3) | YES | | NULL | | | s6s2res | text | YES | | NULL | | | s6s3code | char(10) | YES | | NULL | | | s6s3ia | int(2) | YES | | NULL | | | s6s3ex | int(3) | YES | | NULL | | | s6s3tot | int(3) | YES | | NULL | | | s6s3res | text | YES | | NULL | | | s6s4code | char(10) | YES | | NULL | | | s6s4ia | int(2) | YES | | NULL | | | s6s4ex | int(3) | YES | | NULL | | | s6s4tot | int(3) | YES | | NULL | | | s6s4res | text | YES | | NULL | | | s6s5code | char(10) | YES | | NULL | | | s6s5ia | int(2) | YES | | NULL | | | s6s5ex | int(3) | YES | | NULL | | | s6s5tot | int(3) | YES | | NULL | | | s6s5res | text | YES | | NULL | | | s6s6code | char(10) | YES | | NULL | | | s6s6ia | int(2) | YES | | NULL | | | s6s6ex | int(3) | YES | | NULL | | | s6s6tot | int(3) | YES | | NULL | | | s6s6res | text | YES | | NULL | | | s6s7code | char(10) | YES | | NULL | | | s6s7ia | int(2) | YES | | NULL | | | s6s7ex | int(3) | YES | | NULL | | | s6s7tot | int(3) | YES | | NULL | | | s6s7res | text | YES | | NULL | | | s6s8code | char(10) | YES | | NULL | | | s6s8ia | int(2) | YES | | NULL | | | s6s8ex | int(3) | YES | | NULL | | | s6s8tot | int(3) | YES | | NULL | | | s6s8res | text | YES | | NULL | | | s7s1code | char(10) | YES | | NULL | | | s7s1ia | int(2) | YES | | NULL | | | s7s1ex | int(3) | YES | | NULL | | | s7s1tot | int(3) | YES | | NULL | | | s7s1res | text | YES | | NULL | | | s7s2code | char(10) | YES | | NULL | | | s7s2ia | int(2) | YES | | NULL | | | s7s2ex | int(3) | YES | | NULL | | | s7s2tot | int(3) | YES | | NULL | | | s7s2res | text | YES | | NULL | | | s7s3code | char(10) | YES | | NULL | | | s7s3ia | int(2) | YES | | NULL | | | s7s3ex | int(3) | YES | | NULL | | | s7s3tot | int(3) | YES | | NULL | | | s7s3res | text | YES | | NULL | | | s7s4code | char(10) | YES | | NULL | | | s7s4ia | int(2) | YES | | NULL | | | s7s4ex | int(3) | YES | | NULL | | | s7s4tot | int(3) | YES | | NULL | | | s7s4res | text | YES | | NULL | | | s7s5code | char(10) | YES | | NULL | | | s7s5ia | int(2) | YES | | NULL | | | s7s5ex | int(3) | YES | | NULL | | | s7s5tot | int(3) | YES | | NULL | | | s7s5res | text | YES | | NULL | | | s7s6code | char(10) | YES | | NULL | | | s7s6ia | int(2) | YES | | NULL | | | s7s6ex | int(3) | YES | | NULL | | | s7s6tot | int(3) | YES | | NULL | | | s7s6res | text | YES | | NULL | | | s7s7code | char(10) | YES | | NULL | | | s7s7ia | int(2) | YES | | NULL | | | s7s7ex | int(3) | YES | | NULL | | | s7s7tot | int(3) | YES | | NULL | | | s7s7res | text | YES | | NULL | | | s7s8code | char(10) | YES | | NULL | | | s7s8ia | int(2) | YES | | NULL | | | s7s8ex | int(3) | YES | | NULL | | | s7s8tot | int(3) | YES | | NULL | | | s7s8res | text | YES | | NULL | | +-------------+-------------+------+-----+---------+----------------+ 285 rows in set (0.02 sec) yes ,you see it correctly ..it has 285 rows in it's structure itself..which can accomodate a students usn ,his branch name,his name,his current sem his sem1 subject 1(s1s1code) code,his sem1 subject1 internal marks(<=25)(s1s1ia),sem1 subject1 external marks(<=100)(s1s1ex),sem1 subject 1 total(s1s1tot) and sem1 subject 1 result(pass or fail)(s1s1res).....similarly till sem8 subject 8 result..I mean what if i use only this single table for everything??what is the role of normalization here??Since the USN has all the information I need ,do you think that this is a terribly bad idea to use a structure like this ??my point is that isn't this structure more simple than having multiple table and dealing with the headaches of normalization ..This I wan't to use to store every marks related information of the student of all branch and all sem.Practically the project become very big and the complexity of the project will also be vast..I'm not actually diverting from the main thread..this is the main idea behind all these circus that I'm doing,and this is why I'm a bit hesitant towards creating multiple tables.Whats wrong with the structure??If this all sounds foolish then my extreme apologies. Oh yeah rgarding replies...I'll check it n get back to you asap.
  2. here is the o/p with the new table,which is not how i wanted it to be. mysql> select * from users_code; +-----+------+--------+ | id | usn | slcode | +-----+------+--------+ | 1 | | 12 | | 2 | | 13 | | 3 | | 15 | | 4 | | 17 | | 5 | | 21 | | 6 | | 23 | | 7 | | 24 | | 8 | | 25 | | 9 | | 0 | | 10 | | 0 | | 11 | | 0 | | 12 | | 0 | | 13 | | 0 | | 14 | | 0 | continues.... when an echo $query was done it showed.. Student Marks Entry Results INSERT INTO users_code (usn, slcode) VALUES ('', 12), ('', 13), ('', 15), ('', 17), ('', 21), ('', 23), ('', 24), ('', 25), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0), ('', 0)120 Marks inserted into database.
  3. created a new table. But i''m unable to get the intended result ..the situation is like this ....each student consist of his own unique USN number say 4gh08cs052(a sample)....when an admin logs in he is presented with the table that I've shown in the screenshots,where he can input all the marks of a particular student in respective subjects which is represented as columns from code1 - code8 where each code represent a subject.As soon as the admin clicks the submit button the appropriate entered value should be stored in the database which has the same structure as the frontend table.i.e guess a student has scored 15,20,13,25,24,22,21 marks in his subjects..it should be entered in the html table and stored in the dbase as usn=4gh08cs052, code1=15, code2=20,code3=13,code4=25,code5=24,code6=24,code7=22,code8=21..hope you got an idea.(my english is pathetic..hope you'll somehow understand it). IN SHORT, I WANT TO STORE THE MARKS OF ALL THE STUDENTS IN THE DATABASE GIVING EACH STUDENT A ROW TO ACCOMODATE HIS DATA.
  4. I totally respect the concept of data normalization.. Since I'm very less experienced with this I want to avoid the complexity of using different tables. Isn't there a way that I can add the data to an existing table only?.. In my project I've an idea of fetching everything from a single table.. Does that sound like a bad idea?.. Will surely accept the suggestions offered here.
  5. There have been a good improvement....data is being inserted to the database....but there is something wrong with the query....data is not being added as i expected it to be....the screenshots will explain the rest of the story...updated code is also listed. <?php $con = mysql_connect("localhost","tom",""); if (!$con) { die('Could not connect: ' . mysql_error()); } //select Database mysql_select_db("sms", $con); $result = mysql_query("SELECT * FROM dept_info", $con) or die(mysql_error()); echo "<table border='1'>"; echo '<tr> <th>Sl No</th> <th>USN</th> <th>Name</th><th>code1</th><th>code 2</th> <th>code 3</th> <th>code 4</th> <th>code 5</th> <th>code 6</th> <th>code 7</th> <th>code 8</th></tr>'; echo '<form action = "insert.php" method = "post">'; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo $row['usn']; echo "</td><td>"; echo $row['name']; echo "</td>"; for ($i=1; $i <= 8; $i++) { echo "<td> <input type='text' name='sl[{$row['usn']}][$i]' size='2' /> </td>" ; } echo '</tr>'; } echo ' <div align="bottom"> <input type = "submit" align = "BOTTOM" value = "Proceed"> </div> </form> '; ?> <html> <head> <title>Marks Entry Results</title> </head> <body> <h1>Student Marks Entry Results</h1> <?php $insertData = array(); foreach ($_POST['sl'] as $usn => $codes) { foreach ($codes as $sl) { $insertData[] = sprintf("('%s', %d)", mysqli_real_escape_string($usn), intval($sl)); } } $con = mysql_connect("localhost","tom",""); if (!$con) { die('Could not connect: ' . mysql_error()); } //select Database mysql_select_db("sms", $con); $query = "INSERT INTO dept_info (usn, code1) VALUES\n" . join(",\n", $insertData); echo $query; $result = mysql_query($query); if ($result) { echo mysql_affected_rows()." Marks inserted into database."; } else { echo "An error has occurred. Not added."; } mysql_close(); ?> </body> </html> please help with the query so that tha expected results are obtained.Screenshot is split into two...but both are one image.
  6. again updating my inert.php code..Sorry for spamming..I'm not able to edit it..thats why. <html> <head> <title>Marks Entry Results</title> </head> <body> <h1>Student Marks Entry Results</h1> <?php $insertData = array(); foreach ($_POST['sl'] as $usn => $codes) { foreach ($codes as $sl) { $insertData[] = sprintf("('%s', %d)", mysqli_real_escape_string($usn), intval($sl)); } } $con = mysql_connect("localhost","tom",""); if (!$con) { die('Could not connect: ' . mysql_error()); } //select Database mysql_select_db("sms", $con); $query = mysql_query("INSERT INTO mytable (usn, code1) VALUES\n" . join(",\n", $insertData)); $result = mysql_query($query); if ($result) { echo mysql_affected_rows()." Marks inserted into database."; } else { echo "An error has occurred. Not added."; } mysql_close(); ?> </body> </html> //The description of the table which i made for this is /*mysql> desc mytable; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | usn | varchar(50) | NO | PRI | NULL | | | code1 | int(2) | YES | | NULL | | | code2 | int(2) | YES | | NULL | | | code3 | int(2) | YES | | NULL | | | code4 | int(2) | YES | | NULL | | | code5 | int(2) | YES | | NULL | | | code6 | int(2) | YES | | NULL | | | code7 | int(2) | YES | | NULL | | | code8 | int(2) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 9 rows in set (0.01 sec) */
  7. I've used mysql in first and mysqli in second..I'll change that..will this code be okay.. <html> <head> <title>Marks Entry Results</title> </head> <body> <h1>Student Marks Entry Results</h1> <?php $insertData = array(); foreach ($_POST['sl'] as $usn => $codes) { foreach ($codes as $sl) { $insertData[] = sprintf("('%s', %d)", mysqli_real_escape_string($usn), intval($sl)); } } $con = mysql_connect("localhost","tom",""); if (!$con) { die('Could not connect: ' . mysql_error()); } //select Database mysql_select_db("sms", $con); $query = mysql_query("INSERT INTO mytable (usn, code1) VALUES\n" . join(",\n", $insertData)); $result = $db->query($query); if ($result) { echo $db->affected_rows." Marks inserted into database."; } else { echo "An error has occurred. Not added."; } $db->close(); ?> </body> </html> and a minor change to workingcode.php <?php $con = mysql_connect("localhost","tom",""); if (!$con) { die('Could not connect: ' . mysql_error()); } //select Database mysql_select_db("sms", $con); $result = mysql_query("SELECT * FROM dept_info", $con) or die(mysql_error()); echo "<table border='1'>"; echo '<tr> <th>Sl No</th> <th>USN</th> <th>Name</th><th>code1</th><th>code 2</th> <th>code 3</th> <th>code 4</th> <th>code 5</th> <th>code 6</th> <th>code 7</th> <th>code 8</th></tr>'; echo '<form action = "insert.php" method = "post">'; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo $row['usn']; echo "</td><td>"; echo $row['name']; echo "</td>"; for ($i=1; $i <= 8; $i++) { echo "<td> <input type='text' name='sl[{$row['usn']}][$i]' size='2' /> </td>" ; } echo '</tr>'; } echo ' <div align="bottom"> <input type = "submit" align = "BOTTOM" value = "Proceed"> </div> </form> '; ?>
  8. Sir, sorry for my lack of knowledge in php..I think I totally messed up everything..I'm unable to store the values to dbase..my three codes and screenshots are as shown below.I'm new to php sir.But at this point I desperately need your help. //workingcode.php <?php $con = mysql_connect("localhost","tom",""); if (!$con) { die('Could not connect: ' . mysql_error()); } //select Database mysql_select_db("sms", $con); $result = mysql_query("SELECT * FROM dept_info", $con) or die(mysql_error()); echo "<table border='1'>"; echo '<tr> <th>Sl No</th> <th>USN</th> <th>Name</th><th>code1</th><th>code 2</th> <th>code 3</th> <th>code 4</th> <th>code 5</th> <th>code 6</th> <th>code 7</th> <th>code 8</th></tr>'; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo $row['usn']; echo "</td><td>"; echo $row['name']; echo "</td>"; for ($i=1; $i <= 8; $i++) { echo "<td> <input type='text' name='sl[{$row['usn']}][$i]' size='2' /> </td>" ; } echo '</tr>'; } echo ' <form action = "insert.php" method = "post"> <div align="bottom"> <input type = "submit" align = "BOTTOM" value = "Proceed"> </div> </form> '; ?> I've linked this to an insert.php file as shown below.. <html> <head> <title>Marks Entry Results</title> </head> <body> <h1>Student Marks Entry Results</h1> <?php $insertData = array(); foreach ($_POST['sl'] as $usn => $codes) { foreach ($codes as $sl) { $insertData[] = sprintf("('%s', %d)", mysqli_real_escape_string($usn), intval($sl)); } } @ $db = new mysqli('localhost', 'tom', '', 'sms'); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database.'; exit; } $query = "INSERT INTO mytable (usn, code1) VALUES\n" . join(",\n", $insertData); $result = $db->query($query); if ($result) { echo $db->affected_rows." Marks inserted into database."; } else { echo "An error has occurred. Not added."; } $db->close(); ?> </body> </html> //The description of the table which i made for this is /*mysql> desc mytable; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | usn | varchar(50) | NO | PRI | NULL | | | code1 | int(2) | YES | | NULL | | | code2 | int(2) | YES | | NULL | | | code3 | int(2) | YES | | NULL | | | code4 | int(2) | YES | | NULL | | | code5 | int(2) | YES | | NULL | | | code6 | int(2) | YES | | NULL | | | code7 | int(2) | YES | | NULL | | | code8 | int(2) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 9 rows in set (0.01 sec) */ am i anywhere near..or did I completely lost it??
  9. sir in your insert statement you're telling me to insert each value by myself or did I mistook your code?? I want those input values to be automatically inserted to the dbase upon clicking submit by the end user.. I've added a submit button and linked it to another php code.. only problem is that it is not storing the data properly.. where am I missing.Thanks for your patience so far.
  10. can you give me a small clue as to how I can insert the input data to mysql db??..just a clue..the inserting part..pls.
  11. Yes usn is unique for each student..Can u direct me to a good tutorial where i can read about storing the entered values(values from code 1 - code 8\)by the user to a database??
  12. Hello sir,First of all thank you for spending your valuable time to help me.Th code is working fine..in the name='sl[{$row['id']}][$i]' part can i change the $row[ 'id' ] to $row[ 'usn' ]..???and now am i able to store all the values in the fields to a table inside my database?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.