html - How to add and delete data into a MySQL database using PHP? -


i add / delete information database using php @ area. mean have array of courses user has selected , combine array courses have in database. same thing except instead of adding courses deleting. though using concat, can't figure out how use in code.

my php file looks this:

<?php  include("account.php");  //connect mysql database  session_start();  $dbc = mysqli_connect($hostname, $username, $password, $database) or die("unable connect mysql database");  echo "connected mysql<br>";  $adchoice = $_post['adlist'];  $user = $_post['name'];  $num = $_post['number'];  if(isset($_post['submit']))  {  	$query2 = "select * studentdb studentname = '". mysqli_real_escape_string($dbc,$user) ."' , studentid = '". mysqli_real_escape_string($dbc,$num) ."'" ;  	$result2 = mysqli_query($dbc,$query2);  	if (mysqli_num_rows($result2) == 1)   	{  		while($row = mysqli_fetch_array($result2, mysqli_both))  		{  			print "originial courses:";  			echo '<br />'.'student name: ' . $row['studentname'] . '| student e-mail: ' . $row['e-mail'] .';'. '| student id: ' . $row['studentid'] . '| student courses: ' . $row['student courses'] .'<br />';  		}  	}  	if ($adchoice == '3')  	{  		echo "user: " .$user .'<br />';  		print "you have chosen add classes<br>";   	}  	if ($adchoice == '4')  	{  		echo "user: " .$user .'<br />';  		print "you have chosen drop classes<br>";   	}  	foreach ($_post['classes'] $select)  	{  		echo "you have selected : " .$select .'<br />'; // displaying selected value  	}  		if ($adchoice == '3')  	{     //add classes db here  	}    	if ($adchoice == '4')  	{    //delete classes in db here  	}  }  else  {  	echo "error<br>";  }  ?>

as courses selected this:

			<select name ="classes[]" multiple>';  			<option value = cs332>{cs 332}</option>";  			<option value = cs241>{cs 241}</option>";  			<option value = math333>{math 333}</option>";  			<option value = econ201>{econ 201}</option>";  			<option value = phys111>{phys 111}</option>";  			<option value = cs114>{cs 114}</option>";  			<option value = math337>{math 337}</option>";  			<option value = sts201>{sts 201}</option>";  			</select>

i have no idea how combine array items in database located under student courses specific student without erasing update, same deleting. reinstate question : i need in combining array data located in database , need in using array delete data located in database without erasing there.

example :

for adding: if array looks this: classes[] = cs 113 , cs 114, cs 332 , courses in database cs 364 , cs 213 , cs 202 want result cs 113 , cs 114, cs 332, cs 364 , cs 213 , cs 202

for deleting: if array looks this: classes[] = cs 113 , cs 114, cs 332 , courses in database cs 113 , cs 114 , cs 202 want result cs 202

             <td>  			 <select id = "mylistad" name = "adlist" >                 <option value = "3" >add</option>  			   <option value = "4" >drop</option>               </select>  			</td>

the user select beforehand whether want add or drop classes , array create based off decision. question makes sense.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -