mtvaran 0 Newbie Poster

Its difficult to find out what's wrong from the code itself. It comes down to debugging and finding the cause of the problem yourself. Did you check out the result from the echo $sql; as I told you before? What output did it give?

Did it print something like: SELECT take.StudentID,student.StudentName,take.CourseID,course.CourseName FROM take,student,course WHERE take.StudentID = student.StudentID AND take.CourseID = course.CourseID AND take.StudentID LIKE '%' ORDER BY take.StudentID ASC; Is your $_POST[sid] getting the value you want it to pull?
Did you encapsulate the variables like I told you to?
Are you getting an error or just not getting any data?
Is StudentID a unique ID. If so why do you need to use LIKE?

mysql_fetch_array() is giving you an error because $result is not a resource. $result is not a resource because you sql query is incorrect.

YES now it works, i had to take the "line 33" off.i previously put it for error finding. :)

mtvaran 0 Newbie Poster

It looks like your sql query has an error in it somewhere. I think the problem is with the $_POST[sid] not being encapsulated change it to {$_POST['sid']} . It should work.

If not then try this. Change the sql query to the following.

$sql = "SELECT take.StudentID,student.StudentName,take.CourseID,course.CourseName FROM take,student,course WHERE take.StudentID = student.StudentID AND take.CourseID = course.CourseID AND StudentID LIKE '$_POST[sid]%' ORDER BY StudentID ASC";
echo $sql;
$result=mysql_query($sql);

The above will print out the sql query on the page. I hope you are using PHPmyAdmin. Run the query there and see if you get the response you are looking for. If you find an error, fix the sql statement and try again.

Let us know if you still have a problem.

this is my full query for searching data from multiple table. still i could not get any result. could anyone check please where am i made mistake?

<?php  
 		
 	$con = mysql_connect("localhost","root","");
	if (!$con)
  	{
  	die('Could not connect: ' . mysql_error());
  	}

	mysql_select_db("uni", $con);
	
$sql = "
    SELECT take.StudentID
          ,student.StudentName
          ,take.CourseID
          ,course.CourseName
    FROM take
        ,student
        ,course
    WHERE take.StudentID = student.StudentID
    AND take.CourseID = course.CourseID
    AND take.StudentID LIKE '$_POST[sid]%'
    ORDER BY take.StudentID ASC
";

$result = mysql_query($sql) or trigger_error('MySQL Error: ' . mysql_error(), E_USER_ERROR);

echo"<br>";
		
echo "<center><table width=700 border=1>";
echo "<tr><th>StudentID</th><th>StudentName</th><th>CourseID</th><th>CourseName</th></tr>";

while($row = mysql_fetch_array ($result))
echo mysql_error();
{
 
echo "<tr><td>";
echo $row['StudentID'];
echo "</td><td>";
echo $row['StudentName'];
echo "</td><td>";
echo $row['CourseID'];
echo "</td><td>";
echo $row['CourseName'];
echo "</td></tr>";

}

echo "</table>";
		
	mysql_close($con); 
?>
mtvaran 0 Newbie Poster

still same error message

mtvaran 0 Newbie Poster

Hi guys, could you please check this code for me. basically displaying data from two table.
i get error massage like...
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\dis_take.php on line 91

<?php  
 		
 	$con = mysql_connect("localhost","root","");
	if (!$con)
  	{
  	die('Could not connect: ' . mysql_error());
  	}

	mysql_select_db("uni", $con);
	
$result = mysql_query("SELECT take.StudentID,student.StudentName,take.CourseID,course.CourseName FROM take,student,course WHERE take.StudentID = student.StudentID AND take.CourseID = course.CourseID AND StudentID LIKE '$_POST[sid]%' ORDER BY StudentID ASC");

echo"<br>";
		
echo "<center><table width=700 border=1>";
echo "<tr><th>StudentID</th><th>StudentName</th><th>CourseID</th><th>CourseName</th></tr>";

while($row = mysql_fetch_array ($result))

{

echo "<tr><td>";
echo $row['StudentID'];
echo "</td><td>";
echo $row['StudentName'];
echo "</td><td>";
echo $row['CourseID'];
echo "</td><td>";
echo $row['CourseName'];
echo "</td></tr>";

}

echo "</table>";
		
	mysql_close($con); 
?>
mtvaran 0 Newbie Poster

thanks guys.

mtvaran 0 Newbie Poster

could anyone provide code for me how to search data using column name.

example: if i have 2 columns called NAME,ID then i select NAME or ID and enter the keyword to search.
would greatly appreciate your help!

mtvaran 0 Newbie Poster

You want help with the code, yet you haven't posted any. Making tables is fine, but you need to show us the php you have so far.

<?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());
$result  = mysql_query("SELECT DISTINCT CourseID FROM examquesion") or trigger_error('MySQL error: ' . mysql_error());


echo '<select name="cid">';

while($row = mysql_fetch_array($result))
{

    echo '<option value="' . $row['CourseID'] . '">'  . $row['CourseID'] . ' </option>';
}

echo '</select>';

// ----------------

?>
  </div>
  <p>&nbsp;</p>
  <form id="form1" name="form1" method="post" action="result.php">
    <label>
      <input type="submit" name="Submit" value="Submit" />
    </label>
  </form>

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());
$result  = mysql_query("SELECT DISTINCT StudentID FROM take") or trigger_error('MySQL error: ' . mysql_error());


echo '<select name="sid">';

while($row = mysql_fetch_array($result))
{

    echo '<option value="' . $row['StudentID'] . '">'  . $row['StudentID'] . ' </option>';
}

echo '</select>';

// ----------------
echo "<br><br>";

 mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error());
$result  = mysql_query("SELECT DISTINCT QuesionNo,MarksAllocated FROM examquesion ORDER BY QuesionNo ASC") or trigger_error('MySQL error: ' . mysql_error());

echo "<table width=200 border=1>";
echo "<tr><th>QuesionNo</th><th>MarksAllocated</th><th>ActualMarks</th></tr>";


while($row = mysql_fetch_array ($result))
{
echo "<tr><td>";
echo $row['QuesionNo'];
echo "</td><td>";
echo $row['MarksAllocated'];
echo "</td><td>";
echo $row['ActualMarks'];
echo "</td></tr>";
}

?>
mtvaran 0 Newbie Poster

hi guys, I would greatly appreciate it if you could help me with this code

I have some tables called,

Student (SID,SNAME) -> I have got data into it
Course(CID,CNAME) -> I have got data into it
Take(SID,CID) -> I have got data into it
quesion (CID,QNO,MRKS)-> I have got data into it
answer (SID,CID,QNO,ACTUALMRKS) ->I need to insert data into it?

Now I want to display CID as drop-down menu from Take table

if I select a data from above the drop-down menu then another drop-down menu should create automatically with the SID form Take who is taking particular CID.

If I selected both field then QNO (should come from the question table) and a extra text field (depend on how many QNO has itself) has to create automatically to enter ACTUALMRKS.

if I submit then all data has to store into the answer table

mtvaran 0 Newbie Poster

Hi guys, i have to create a drop-down menu for database data, when i select one data from that then next drop-down menu has to create automatically with related data of the 1st selection.
could anyone please give me some help to do this?

NB: i have 3 tables student(sid, sname), course (cid, cname) , take (sid, cid) so if i select one of the cid then another drop down list has to create automatically with sid who is taking the cid .

mtvaran 0 Newbie Poster

thank you every much

mtvaran 0 Newbie Poster

hi guys, i am struggling with cross tab query in mysql. if you have any idea could you please help me? basically i have data into the table like...

cid | Q# | marks
c1 | 1| 50
c1 | 2 | 50
c1 | 3 | 50

but i need to be display the data like...

cid | Q1 | Q2 | Q3
c1 | 50 | 50 | 50

mtvaran 0 Newbie Poster

is result.php actually being called and if so, have you tried to see what your queries look out. Try and echo out the $sql variable.

Also are you are looping thru the $qno array, try print_r($qno); to see if there is actually data in there

im bit new with php so the problem is i couldn't find error data easily.:?:
as you can see basically im displaying a column field as drop-down list.
then ask enter No of question'
(if i enter 2 then 2 text field will be created automatically)
after i enter data into it.
then all data have to be stored into another table.
Eg:
cid, q#,marks
c1,1,50
c1,2,50.

here evrything has been displayed well but when i click submit, the data doesn't insert into table

mtvaran 0 Newbie Poster

Hi guys, basically here pull out the data from database then creating taxt field automatically and submit into anther table. everything works fine but data not inserting in to the table. could you guys check my code please?

<?php

$con = mysql_connect("localhost","root","");

mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error());
?>
<?php
$result  = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error());


echo '<select name ="cid[]">';

while($row = mysql_fetch_array($result))
{

    echo '<option value="' . $row['CourseID'] . '">'. $row['CourseID'] .'</option>';
}

echo '</select>';
//------------------
?>
   
 <?php
if(!empty($_POST["submit"]))
{
 $value = empty($_POST['question']) ? 0 : $_POST['question'];
?>
 <form name="form1" method="post" action="result.php">
 <?php


 for($i=0;$i<$value;$i++)
 {
  echo 'Question NO: <input type="text" name="qno[]" size="2" maxlength="2" class="style10">&nbsp;&nbsp;&nbsp;&nbsp;
        Enter Marks: <input type="text" name="marks[]" size="3" maxlength="3" class="style10"><br>';
  }


?>
  <label> <br />
  <br />
  <input type="submit" name="Submit" value="Submit" class="style10">
  </label>
 </form>
<?php
 }
else{
?>

<form method="POST" action="#">


 
<label>
<span class="style10">Enter the Number of Question</span>
<input name="question" type="text" class="style10" size="2" maxlength="2"> 
</label>
<input name="submit" type="submit" class="style10" value="Submit">

 
</form>
<?php }?>

result.php

<?php
 

$con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error());
mysql_select_db("uni",$con) or die('Could not connect: ' . mysql_error());

foreach ($_POST['cid'] as $c) {$cid [] = $c;}
foreach($_POST['qno'] as $q){$qno[] = $q;}
foreach($_POST['marks'] as $m){$marks[] = $m;}
$ct = 0;
for($i=0;$i<count($qno);$i++)
{

 $sql="INSERT INTO examquesion (CourseID,QuesionNo,MarksAllocated) VALUES('$cid[$i]','$qno[$i]','$marks[$i]')";
 mysql_query($sql,$con) or die('Error: ' . mysql_error());
 $ct++;
 }
echo "$ct record(s) added";
mysql_close($con)
?>
mtvaran 0 Newbie Poster

hi, here im able to create text field but couldn't insert the data. so could anyone please check this code for me.

<?php 
$value=$_POST['question']; 

for($i=0;$i<$value;$i++) 
{ 
echo "Question NO:"; 
echo '<input type="text" name="qno[]">'."\t"; 

echo "Enter Marks:"; 
echo '<input type="text" name="marks[]">'."\t"; 
echo "<br>"; 
} 
?> 
</form> 
<form name="form1" method="post" action="cellresult.php"> 
  <label> 
  <input type="submit" name="Submit" value="Submit"> 
  </label> 
</form> 

</body>

cellresult.php

<body> 
<?php 
$con = mysql_connect("localhost","root",""); 
if (!$con) 
  { 
  die('Could not connect: ' . mysql_error()); 
  } 

mysql_select_db("test", $con); 

$sql="INSERT INTO cell (QNO,MARKS) 
VALUES 
('$_POST['qno']','$_POST['marks']')"; 

if (!mysql_query($sql,$con)) 
  { 
  die('Error: ' . mysql_error()); 
  } 
echo "1 record added"; 

mysql_close($con) 
?> 
</body>
mtvaran 0 Newbie Poster

Thanks for your codes. could you please provide the code that once i create two cells (text field)then i have to store in database table the value from the text field. im bit new & stupid with PHP so please bear with me. thanx

mtvaran 0 Newbie Poster

thank you so much guys for your helps and positive advice. :)

mtvaran 0 Newbie Poster

Hi guys, i have a big problem on these creation. basically if i enter the No of Question then it has to be created No of cells for entering marks.

Eg: No of question = 4 then

quesNO-------Marks
1------------------cell
2------------------cell
3------------------cell
4------------------cell


if anyone of you could help me with this code please!!!!!!!!! hope this would not be too dificult for you guys. Thanks

mtvaran 0 Newbie Poster

Alright, I guess you stopped reading my posts which provided the solution and which only need one more adjustment to work with the table you described in your last post. Finding a solution when you show no effort on solving your OWN problem and use youtube films to learn PHP, is not going to work...

Good luck.

Dear, i copied your coding and ran again, there was same error message like this...

Notice: MySQL error: Unknown column 'sid' in 'where clause' in C:\wamp\www\new.php on line 48

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\new.php on line 52
You search query did not match any record.

that is why i posted the youtube video to understand my question to you all guys.
hope you get my point. if you can provide any solution for me. would appreciate.
thank you

mtvaran 0 Newbie Poster

hi, dear..
In line 37 ,why are you using $field ='$searchword'".....
and in line 45 try to use mysql_num () or mysql_assoc() with mysql_fetch_array.

let me know what exactly you want...

HI DEAR, basicaly i hav a table student, column names (StudentID,StudentName and some more.......) in my database. so now i need to search data using StudentID or StudentName.
if you could watch this clip you will get more.

http://www.youtube.com/watch?v=IYmS5HRo6JI&feature=channel

if you could help me with this function. i would appreciate.
thanx

mtvaran 0 Newbie Poster

>> Line 1 - There is no attribute for the form tag called 'value'

>> Line 4, 5 - Do not use spaces between attributes and their values (so value = "sid" needs to be value="sid" )

>> Line 12 - Add a attribute "name" with the value "submitted" to the submit element, else the if statement on line 17 does not work correctly

>> Line 25, 26 - This is not an error but if the code goes online, it can be exploited by adding SQL code into the value of the form elements, clean it up before adding them to the query:

$searchword = htmlentities(addslashes($_POST['searchword']));

>> Line 48 - You need to place this line within the if statement brackets, as there only is a connection when it has been openend on line 19

~G

hi dear i just made some correction as you suggested but still some error. im bit stupid on php so could u pls check this code again for me?

<body>

<form  method="post" action="new.php"  name="submitted"   /> 
  <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" name ="submitted" /> 
  
</form> 

<?php 
if (isset($_POST['submitted'])){ 
$searchword = htmlentities(addslashes($_POST['searchword']));

$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());  

//$result = 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
mtvaran 0 Newbie Poster

basically this is a search function.(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); 

?>