Jump to content

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined


willscarlet
Go to solution Solved by ginerjm,

Recommended Posts

New to PDO having trouble with a simple UPDATE feature. Im sure its a simple thing im just over looking it. any help would be much appreciated :)

<?php
require_once('dbcon.php');

if(isset($_POST['btn_submit'])){
	$student_id = $_POST['txt_student_id'];
	$student_name = $_POST['txt_student_name'];
	$age = $_POST['txt_age'];
	$email = $_POST['txt_email'];
	$address = $_POST['txt_address'];
	$dob = $_POST['txt_dob'];
	if(!empty($student_name)){
		try {
			$stmt = $con->prepare("UPDATE tb_students set student_name= :name,
														  age = :age,
														  email = :email,
														  address = :address,
														  dob = :dob
									WHERE student_id = :student_id");
											
			$stmt->execute(array(':student_name'=>$student_name, ':age'=>$age, ':email'=>$email, ':address'=>$address, ':dob'=>$dob, ':student_id'=>$student_id));
			if($stmt){
				header('Location:index.php');
			}
		}catch(PDOException $ex){
			echo $ex->getmessage();
		}
	}else{
		echo "INPUT NAME";
	}
}	
	$student_id = 0;
	$student_name = '';
	$age = 0;
	$email = '';
	$address = '';
	$dob = '';
	if(isset($_GET['id'])){
		$id = $_GET['id'];
		$stmt = $con->prepare('SELECT * FROM tb_students WHERE student_id = :id');
		$stmt->execute(array(':id'=>$id));
		$row = $stmt->fetch();
		$student_id = $row['student_id'];
		$student_name = $row['student_name'];
		$age = $row['age'];
		$email = $row['email'];
		$address = $row['address'];
		$dob = $row['dob'];
	}

?>

<h2>Edit Student</h2>
<form action="" method="post">
	<table cellpadding="5px">
		<tr>
		<tr>
			<td>Student Name</td>
			<td><input type="text" name="txt_student_name" value="<?=$student_name;?>"></td>
		</tr>
		<tr>
			<td>Age</td>
			<td><input type="text" name="txt_age" value="<?=$age;?>"></td>
		</tr>
		<tr>
			<td>Email</td>
			<td><input type="text" name="txt_email" value="<?=$email;?>"></td>
		</tr>
		<tr>
			<td>Address</td>
			<td><input type="text" name="txt_address" value="<?=$address;?>"></td>
		</tr>
		<tr>
			<td>D.O.B</td>
			<td><input type="text" name="txt_dob" value="<?=$dob;?>"></td>
		</tr>
		<tr>
		<td></td>
		<td><input type="hidden" name="txt_student_id" value="<?=$student_id;?>"></td>
		<td><input type="submit" name="btn_submit"></td>
		</tr>
	</table>
</form>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.