Jump to content

UPDATE statement trouble


MjM8082

Recommended Posts

Having update statement trouble... The error I'm getting is...

 

"Could not query the database - : "

 

Not sure what I'm missing, I had this working before also, but now it's not.

 

 

Here is my code for the update page...

 

 

 

<html>
<head>
<title>Update User</title>
</head>
<body>

<form method="post" action="update_user2.php">

<?php
$dbc = mysqli_connect('localhost', 'se266_user', 'pwd', 'se266') 
	or die(mysql_error());
//delete users
echo '<b>Delete or Update User</b>.<br />';
if (isset($_POST['remove']))
{          
	foreach($_POST['delete'] as $delete_id)
	{             
		$query = "DELETE FROM users WHERE course_id = $delete_id";             
		mysqli_query($dbc, $query) or die ('can\'t delete user');          
	}        
	echo 'user has been deleted.<br />';   
}

if (isset($_POST['update']))	
{      

		$course_id 	= $_POST['course_id'];			
		$course_name = $_POST['course_name'];			
		$student_id = $_POST['student_id'];



		$query = "UPDATE users SET course_name ='". $course_name ."' WHERE course_id = $course_id";             			
		$updres = mysqli_query($query);
		if(!$updres)
		{  	die(" Could not query the database - : <br/>". mysqli_error() ); }
		else
		{	echo 'course has been updated.<br />';  	} 

}	


//display users info with checkbox to delete  
$query = "SELECT * FROM users";  
$result = mysqli_query($dbc, $query);  
while($row = mysqli_fetch_array($result))
{      
	echo '<input type="checkbox" value="' .$row['course_id'] . '" name="delete[]" />'; 
	echo ' ' .$row['course_name'] .' '. $row['student_id'];
	echo '<br />';  
}
mysqli_close($dbc);

?>	

<form method="POST" action="update_user2.php">			
<label for="course_id">Course ID:</label> 	
<input type="text" id="course_id" name="course_id" />
<br />			
<label for="course_name">Course Name:</label>

<input type="text" id="course_name" name="course_name" />
<br />		
<label for="course_name">Student ID:</label>

<input type="text" id="student_id" name="student_id" />
<br />					
<input type="submit" name="remove" value="Remove" />
<input type="submit" name="update" value="Update" />
<br><br>
</form>



</body>
</html>

 

 

 

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.