Click here to Skip to main content
15,916,941 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
THE ERROR IS
Fatal error: Uncaught Error: Call to undefined function mysql_error() in C:\xampp\htdocs\cecri karikudi\addstudents.php:48 Stack trace: #0 {main} thrown in C:\xampp\htdocs\cecri karikudi\addstudents.php on line 48


<?php
	@ob_start();
	session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>cecri karaikudi</title>
<?php
include('css.php');
?>
</head>

<body>
<div class="row" align="center"><a href="index.php"><img src="img/header.png" class="img img-responsive" alt="" align="center" /></div><div class="clear_fix"></div><div class="row header_bot"><div class="col-sm-8"></div><div class="col-sm-4 pull-right" align="right">
	<?php if(isset($_SESSION['username'])){ ?>
    	 <span class="header_bot_span"><a href="logout.php">Logout</a></span>
    <?php } else { ?>
        <span class="header_bot_span"><a href="admin.php">Admin</a></span>
        <span class="header_bot_span"><a href="student_login.php">Student</a></span>
    <?php } ?>
 </div>
</div>
<div class="clear_fix"></div>

<!-- Start Content -->
	<div class="clearfix"></div>
<div class="row strip">
	class="fa fa-exchange">  <a href="index.php"><span class="strip_font">Home</span></a> / <a class="active" href=""><span class="strip_font" style="color:#C00;">Add Students</span></a>
</div>
<div class="clearfix"></div>


<div class="col-md-12">
<div class="col-md-3 left_side_menu">
	<?php
	 include('db.php');
     include('admin_menu.php');
	 if(isset($_SESSION['username'])){//echo $_SESSION['username'];exit;
	if(isset($_POST['submit'])){
		$class = $_POST['class'];
		$regno = $_POST['regno'];
		$name = $_POST['name'];
		$mob = $_POST['mob'];
		//echo "INSERT INTO student_details (regno,name,parent_mob,class) VALUES ('$regno','$name','$mob','$class')";
		$sql = $db->query("INSERT INTO student_details (regno,name,parent_mob,class) VALUES ('$regno','$name','$mob','$class')") or die(mysql_error());
		
		//die();
		if($sql){
			echo "<script>alert('Your Details Saved Successfully.')</script>";
		}
	}
    ?>
</div>
<div class="col-md-9 col-sm-9 col-xs-12 content_border" style="margin-top:10px; padding:10px;">
<h3 style="font-weight:bold; text-transform:uppercase; padding-bottom:5px;"> Add Students</h3>
<div class="row">
<div class="col-md-6 ol-sm-6 col-xs-12">
<table class="table table-bordered table-responsive">
<?php
	$query = $db->query("select * from class") or die(mysqli_error());
?>
<form name="test" method="post" action="#" enctype="multipart/form-data">
<tr><th>Class</th><td><select name="class" class="form-control my_form">
<?php
	while($row = mysqli_fetch_assoc($query)){ ?>
			<option value="<?php echo $row['class_name']; ?>"><?php echo $row['class_name']; ?></option>
<?php } ?>
</select></td></tr>
<tr><th>Regno</th><td><input type="text" class="form-control my_form" name="regno" /></td></tr>
<tr><th>Name</th><td><input type="text" class="form-control my_form" name="name" /></td></tr>
<tr><th>parent mobile no</th><td><input type="text" name="mob" class="form-control my_form" /></td></tr>
<tr>
<td colspan="2"><center><input type="submit" value="submit" name="submit" class="my_btn" /></center></td>
</tr>
 </form>
</table>
 		</div>
 		<div class="col-md-6 ol-sm-6 col-xs-12"></div>
 	  </div>
   </div>
</div>

<?php
include('footer.php');
} else{		
		header('location:index.php?suc=suc');	
	}
?>
</body>
</html>


What I have tried:

IN DB.PHP

<?php
error_reporting();
$db = new mysqli('localhost', 'root', '', 'cecri karaikudi');
if($db->connect_errno){
	die('Sorry Database not connected !!!');
}
?>
Posted
Updated 24-Feb-20 21:24pm

You can't just post up your code and an error message every time you get a error message - fixing them is a part - and an important part - of producing code.

So look at the message:
Call to undefined function mysql_error()
And at the location:
C:\xampp\htdocs\cecri karikudi\addstudents.php:48
which gives you the file name and the line within the file at which the problem occured.

The message is pretty explicit: the function doesn't exist, and a very quick google: Call to undefined function mysql_error() - Google Search[^] tells you why, and what to do about it.

At a guess based on your questions and code so far, you are finding code on the internet, slamming it together and hoping that it will all just work together: that isn't going to happen. You would almost certainly find it quicker and easier to write the code yourself - this isn't complicated stuff and it was almost certainly all covered in your last tutorial period...
 
Share this answer
 
Use mysqli_error() [^] instead.
 
Share this answer
 

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