Jump to content

mtvaran

Members
  • Posts

    61
  • Joined

  • Last visited

    Never

Everything posted by mtvaran

  1. could anyone please modify my code and post it back for me? im really fed up with this function. im almost "zero" in PHP
  2. thanks dear for ur help. however now there is no error message & even nothing pull from database. it seems blank page :-\
  3. could anyone check this code for me plsss? (i have to search the data from database) <form method="post" action="search.php" name="submitted" value ="true" /> <label>TYPE: <select name="field"> <option value = "sid">StudentID</option> <option value = "sname">StudentName</option> </select> </label> <label>WORD: <input type="text" name="searchword" /> </label> <input type="submit" /> </form> <?php if (isset($_POST['submitted'])){ $con = mysql_connect("localhost","root",""); mysql_select_db("uni", $con) or trigger_error('MySQL error: ' . mysql_error()); $field= $_POST['field']; $searchword = $_POST['searchword']; $result = mysql_query("SELECT* FROM student WHERE $field = '$searchword'") or trigger_error('MySQL error: ' . mysql_error()); // = mysql_query($query); //$num_rows = mysql_num_rows($result); //echo"num_rows results found."; echo"<table>"; echo "<tr><th>StudentID</th><th>StudentName</th></tr>"; while($row = mysql_fetch_array($result)){ echo "<tr><td>"; echo "$row ['field']"; echo "</td><td>"; echo "$row ['searchword']"; echo "</td></tr>"; } echo"</table>"; } mysql_close($con); ?>
  4. could you edit & post my code pls if you wud nt mind? thanx
  5. basically this is a search function <form method="post" action="test1.php"> <input type = "hidden" name="submitted" value ="true" /> <label>TYPE: <select name="field"> <option value = "sid">StudentID</option> <option value = "sname">StudentName</option> </select> </label> <label>WORD: <input type="text" name="searchword" /> </label> <input type="submit" /> </form> ------------- <?php if (isset($_POST['submitted'])){ $con = mysql_connect("localhost","root",""); mysql_select_db("uni", $con); $field= $_POST['field']; $searchword = $_POST['searchword']; $query = "SELECT* FROM student WHERE $field = '$searchword'"; $result = mysqli_query($con,$query) or die ('error data'); //-----------> error line echo"<table>"; echo "<tr><th>StudentID</th><th>StudentName</th></tr>"; while($row = mysqli_fetch_array($result)){ echo "<tr><td>"; echo "$row ['sid']"; echo "</td><td>"; echo "$row ['sname']"; echo "</td></tr>"; } echo"</table>"; } mysql_close($con); ?> NB: the error message "Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in C:\wamp\www\test1.php on line 21 error data"
  6. i have a drop-down list of coures from course table. then i have two text field to enter No of Ques: Allocated Marks: for example: if i select PHP course and enter 4 for No of Ques , 25 for Allocated marks then it should srote in anothe database table like this Course | QuesNo | Marks PHP 1 25 PHP 2 25 PHP 3 25 PHP 4 25 Can anyone help for this code.hope this will not too dificult for you guys. i will really apriciate. Thanks
  7. its ok dear. i have done that. thank you very much for your help
  8. wow... u were correct... excellent now data is inserted. but it says small error ..... foreach ($_POST['cid'] as $key => $course) { $courses .= $course."-"; //............ this line error } can you find out it for me plsss
  9. still same dear, no error message and no data inserted. wat can i do with this? pls help me with code.
  10. could anyone please help me with the code which is i have already displayed data from two table as a drop-down list and a multi select list but now i need to select one from drop-down list and one or more from multi select list the insert into another database table. here is the coding. it shows no error message( blank page after submit) and nothing inserted on the take able <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } error_reporting(E_ALL); ini_set('display_errors', 1); mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); $result = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name ="cid[]" multiple="multiple" size="10">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['CourseID'] . '">' . $row['CourseName'] . '</option>'; } echo '</select>'; // ---------------- $result = mysql_query("SELECT * FROM student") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name="sid">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['StudentID'] . '">' . $row['StudentName'] . '</option>'; } echo '</select>'; mysql_close($con); ?> <form id="form1" name="form1" method="post" action="update_result.php"> <label> <input type="submit" name="Submit" value="Submit" /> </label> </form> </body> </html> update_result.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); if (!empty($_POST['sid']) && !empty($_POST['cid'])) { foreach ($_POST['cid'] as $key => $course) { $courses .= $course."-"; } $courses = rtrim($courses,"-"); $student = $_POST['sid']; $sql = "INSERT INTO test (StudentID, CourseID) VALUES('".mysql_real_escape_string($student)."','".mysql_real_escape_string($courses)."')"; $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_affected_rows() > 0) { echo mysql_affected_rows() . ' rows added.'; } } mysql_close($con); ?> </body> </html>
  11. well i have a task which is, i have two table in my database which are student (StudentID, StudentName)& course(CourseID, CourseName). i have displayed the field st_id from student (drop-down list) & course_id from course (multi select list). now i need to insert into another table called take which contain the feild StudentID and CourseID. so i have to select one st_id and one or more course_id then submit. there is the code for that so cud you pls check it 4 me. ?php $result = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name ="cid[]" multiple="multiple" size="10">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['CourseID'] . '">' . $row['CourseName'] . '</option>'; } echo '</select>'; // ---------------- $result = mysql_query("SELECT * FROM student") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name="sid">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['StudentID'] . '">' . $row['StudentName'] . '</option>'; } echo '</select>'; // ---------------- if (!empty($_POST['sid']) && !empty($_POST['cid'])) { $student = mysql_real_escape_string($_POST['sid']); $sql = "INSERT INTO take (StudentID, CourseID) VALUES"; foreach ($_POST['cid'] as $key => $course) { $sql .= ($key != 0) ? ", " : " "; $sql .= "('" . $student . "', '" . mysql_real_escape_string($course) . "')"; } $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_affected_rows($query) > 0) { echo mysql_affected_rows($query) . ' rows added.'; } } ?>
  12. cud any1 tell me why this happens? when i run SOME of the php script using localhost, it says APACHE HTTP SERVER STOP WORKING
  13. it says some error as i mentioned mysql_query("UPDATE student SET StudentID = .$row['StudentID']//Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' WHERE student.StudentID ='.$row['StudentID']'"); mysql_query("UPDATE student SET StudentName = .$row['StudentName'] WHERE student.StudentID ='.$row['StudentID']'");
  14. thank you . i will do next time [attachment deleted by admin]
  15. hi, as i mentioned the line , there is an error cud u pls hav a look again... mysql_select_db("uni", $con); $sql=mysql_query("select * from student"); $res=0; while($row=mysql_fetch_array($sql)) { if($row['StudentID']==$_POST["sid"]) { ?> <form id="form2" name="form2" method="post" action="editing.php"> <?php echo "<p>StudentID : <input type=\"text\" name=\"sid\" id=\"sid\" value=\"$row['StudentID']\" />"; //. this line error echo "<p>StudentName :<input type=\"text\" name=\"sname\" id=\"sname\" value=\"$row['StudentName'] \" /> </p>"; $res=1; } } if($res==0) { echo "Please enter the Correct ID. "; } mysql_close($con); ?> update.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con); mysql_query("UPDATE student SET StudentID = .$row['StudentID'] WHERE student.StudentID ='.$row['StudentID']'"); mysql_query("UPDATE student SET StudentName = .$row['StudentName'] WHERE student.StudentID ='.$row['StudentID']'"); echo "Successfully Edited";
  16. it says something like, Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in .............................
  17. could anyone pls check this coding? i need to display the data from database into the text field for editing then submit to the existing database. mysql_select_db("uni", $con); $sql=mysql_query("select * from student"); $res=0; while($row=mysql_fetch_array($sql)) { if($row['StudentID']==$_POST["sid"]) { ?> <form id="form2" name="form2" method="post" action="update.php"> <h2><p><?php echo "StudentID :" ?> <input type="text" name="sid" id="sid" value="<?php echo"".$row['StudentID'] ?>" /> <p><?php echo "StudentName :" ?> <input type="text" name="stname" id="stname" value="<?php echo"".$row['StudentName'] ?>" /> </p> <?php $res=1; } }?> <h2> <?php if($res==0) { echo "Please enter the Correct ID. "; } update.php mysql_select_db("uni", $con); mysql_query("UPDATE student SET StudentID = .$row['StudentID'] WHERE student.StudentID = '.$row['StudentID']'"); mysql_query("UPDATE student SET StudentName = .$row['StudentName'] WHERE student.StudentID = '.$row['StudentID']'"); echo "Successfully Edited"; //submit button
  18. could anyone pls check this coding? i need to display the data from database into the text field for editing then submit to the existing database. mysql_select_db("uni", $con); $sql=mysql_query("select * from student"); $res=0; while($row=mysql_fetch_array($sql)) { if($row['StudentID']==$_POST["sid"]) { ?> <form id="form2" name="form2" method="post" action="update.php"> <h2><p><?php echo "StudentID :" ?> <input type="text" name="sid" id="sid" value="<?php echo"".$row['StudentID'] ?>" /> <p><?php echo "StudentName :" ?> <input type="text" name="stname" id="stname" value="<?php echo"".$row['StudentName'] ?>" /> </p> <?php $res=1; } }?> <h2> <?php if($res==0) { echo "Please enter the Correct ID. "; } update.php mysql_select_db("uni", $con); mysql_query("UPDATE student SET StudentID = .$row['StudentID'] WHERE student.StudentID = '.$row['StudentID']'"); mysql_query("UPDATE student SET StudentName = .$row['StudentName'] WHERE student.StudentID = '.$row['StudentID']'"); echo "Successfully Edited"; //submit button
  19. thanks for the coding. i have done as u said and now it works without any error message but its not inserting the selected data into the database (take table) im not sure why it is! would you like me to send any of my coding part?
  20. Hi Adam, i wrote the coding as you said but when i run it doesn't say any error massage only says Apache server stop working! so cud you pls check the code if i have made any mistake? <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con); $result = mysql_query("SELECT * FROM course"); echo "<select name ='"cid[]"' multiple='multiple' size = '10'>"; while($row = mysql_fetch_array($result)) { echo "<option value=''>"; echo $row['CourseID']; echo "</option>"; } echo "</select>"; mysql_close($con); ?> -------------------------------------------------------------- <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con); $result = mysql_query("SELECT * FROM student"); echo "<select name = '"sid[]"'>"; while($row = mysql_fetch_array($result)) { echo "<option value=''>"; echo $row['StudentID']; echo "</option>"; } echo "</select>"; mysql_close($con); ?> ------------------------------------------------ <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con); if (!empty($_POST['sid']) && !empty($_POST['cid'])) { $student = mysql_real_escape_string($_POST['sid']); $sql = "INSERT INTO take (StudentID, CourseID) VALUES"; foreach ($_POST['cid'] as $key => $course) { $sql .= ($key != 0) ? ", " : " "; $sql .= "('" . $student . "', '" . mysql_real_escape_string($course) . "')"; } $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_affected_rows($query) > 0) { echo 'Success'; } } mysql_close(); ?>
  21. thanks so much Adam for helping me alot today, i really appreciate. i will try to run this code if i can't i will ask you later. takecare.
  22. well let me explain, i have two table in my database which are student (st_id, st_name)& course(course_id, course_name). i have displayed the field st_id from student (drop-down list) & course_id from course (multi select list). now i need to insert into another table called take which contain the feild st_id and course_id. so i have to select one st_id and one or more course_id then submit. hope you get my point and not too difficult to do this for you.
  23. Hi Adam, i have posted this before but i cudn't get the proper answer jet. if you can pls hava a look. i have already displayed data from database. one is drop-down list another one multi select list, now i need to select one data from drop-down list and one or more data from multi select list then send to another table. hope i have made this clear understand for you. so cud you plss help me if you can ... // coding for displaying drop-down list <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con); $result = mysql_query("SELECT * FROM student"); echo "<select>"; while($row = mysql_fetch_array($result)) { echo "<option>"; echo $row['StudentID']; echo " - "; echo $row['StudentName']; echo "</option>"; } echo "</select>"; mysql_close($con); ?> // this is coding for multi select list <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con); $result = mysql_query("SELECT * FROM course"); echo "<select multiple='multiple' size = '10'>"; while($row = mysql_fetch_array($result)) { echo "<option value=''>"; echo $row['CourseID']; echo "-"; echo $row['CourseName']; echo "</option>"; } echo "</select>"; mysql_close($con); ?> MOD EDIT: . . . [/nobc] tags added . . .
×
×
  • 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.