Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
<?php
session_start();
if(isset($_SESSION['uid']))
{
echo "";
}
else
{
header('location: ../login.php');
}
?>


<?php
include('header.php');
include('titlehead.php');
?>



<table align="center"><tbody><tr><th>  Enter Standard  </th><td>     </td></tr><tr><th>  Enter Student Name </th><td>  
   </td></tr><tr><td></td><td colspan="2"></td></tr></tbody></table>


<?php
if(isset($_POST['submit']))
{
 	include('../dbcon.php');
 	$standard=$_POST['std'];
 	$name=$_POST['name'];
 	$sql="SELECT * FROM `student` WHERE `standard`='$standard' AND `name` LIKE '%$name%'";
 	$run=mysqli_query($con,$sql);
		
		if( mysqli_num_rows($run)<1 )
 		{
		     echo "";
	    }
		else
	{ 
	$count=0;
 	while($data=mysqli_fetch_assoc($run))
   {
   $count++;
	?>

	    
    <?php
  
}
}
}
?>


What I have tried:

I have tried searching on google. But I got No clues as how to resolve this error. I have tried some other ways too but nothing is working.
HTML
<table align="center" width="80%" border="1" style="margin-top: 10px"><tbody><tr><th>No</th><th>Img</th><th>Name</th><th>Roll No</th><th>Edit</th></tr><tr><td colspan="5">no records found</td></tr><tr>		<td>  <?php echo $count; ?> </td>		<td></td>		<td> <?php echo $data['name']; ?> </td>		<td>  <?php echo $data['rollno']; ?> </td>		<td>  EDIT </td>	</tr></tbody></table>
Posted
Updated 31-Mar-18 6:20am
v4
Comments
[no name] 31-Mar-18 9:55am    
Try this: Google[^]

1 solution

PHP
$sql="SELECT * FROM `student` WHERE `standard`='$standard' AND `name` LIKE '%$name%'";

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
 
Share this answer
 
Comments
[no name] 31-Mar-18 10:56am    
Sorry, don't see in the code where he is concatenating the SQL. More I'm missing the part where he correctly defines/sets the Parameter :-)

Please do yourself a favor and don't post template answers where it does not fit ;)
OriginalGriff 31-Mar-18 11:24am    
Sorry, but PHP is nasty in that regard:

$sql="...$standard...";

includes the content of the variable $standard in the string itself - that is the concatenation ppolymorphe was talking about.
[no name] 31-Mar-18 11:26am    
Thank you sir.
OriginalGriff 31-Mar-18 11:35am    
You're welcome!
Patrice T 31-Mar-18 11:58am    
Thank you for the defense.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900