Current location: Hot Scripts Forums » Programming Languages » PHP » Help a Novice with inserting from a combo box


Help a Novice with inserting from a combo box

Reply
  #1 (permalink)  
Old 07-11-08, 12:31 AM
kposki kposki is offline
New Member
 
Join Date: Jul 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Help a Novice with inserting from a combo box

Hi,

I new to PHP and am working on creating an electives database with a web front end using WAMP. As the code below shows, I have created a form that can be used to view data from one table (course) and then insert the user's inputs into another table called suggested. My problem is not with getting values from course table into the combo box....the courseID values are showing in the combo box. My problem is with the inserting of the selected option (courseID) into the second table called suggested...The insert only puts modID, modname and proposer from the input text fields but not courseID from the combo box field. Please is there any help with this...I am so stuck for some days now...Thanks

Code:
PHP Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Suggest electives for a selected cohort</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 </head>
<body>

<form method="post">
<table width="600" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Course Code</td>
<td>
<SELECT NAME='selcosID' ID='selcosID'>
<?php
include 'config.php';
include 
'opendb.php';

   
$query "SELECT * FROM course";
$result mysql_query($query) or die(mysql_error());


while(
$row mysql_fetch_array($result)){

    echo 
"<OPTION VALUE=".$row['selcosID'].">".$row['CourseID']."</OPTION>";
}
?>
</SELECT>
</td>
</tr>

<tr>
<td width="100">Cohort</td>
<td>
<SELECT NAME='selcohort'ID='selcohort'>
<?php
include 'config.php';
include 
'opendb.php';

   
$query "SELECT Cohort FROM course";
$result mysql_query($query) or die(mysql_error());


while(
$row mysql_fetch_array($result)){

    echo 
"<OPTION VALUE=".$row['cohid'].">".$row['Cohort']."</OPTION>";
}
?>
</SELECT>
</td>
</tr>

<tr>
<td width="100">Module Code</td>
<td><input name="modID" type="text" id="modID"></td>
</tr>

<tr>
<td width="100">Module Name</td>
<td><input name="modName" type="text" id="modName"></td>
</tr>

<tr>
<td width="100">Proposer</td>
<td><input name="prop" type="text" id="prop"></td>
</tr>


<tr>
<td width="100">&nbsp;</td>
<td><input name="submit1" type="submit" id="submit1" value="Submit Your Suggestion"></td>
</tr>
</table>
</form>

<?php

if(isset($_POST['submit1']))
{
include 
'config.php';
include 
'opendb.php';

$selcosID $_POST['selcosID'];
$selcohort $_POST['selcohort'];
$modID $_POST['modID'];
$modName $_POST['modName'];
$prop $_POST['prop'];

// prepare the query strings


$query "INSERT INTO suggested (CourseID, Cohort, ModuleID, ModuleName, Proposer) VALUES ('$selcosID', '$selcohort', '$modID','$modName', '$prop')";

mysql_query($query) or die(mysql_error());


include 
'closedb.php';

echo 
"Your suggestion has been successfully submitted";
}


?>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old 07-11-08, 12:41 AM
gavintat gavintat is offline
Newbie Coder
 
Join Date: Dec 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
You mean you cannot insert a correct courseID or got sql statement error?
Reply With Quote
  #3 (permalink)  
Old 07-11-08, 12:47 AM
kposki kposki is offline
New Member
 
Join Date: Jul 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
HI,
I dont get sql errors. It says insert was successful (suggestion has been submitted successfully) but when i go to view my database table, the columns for others are populated but not for CourseID and Cohort.
Thanks
Reply With Quote
  #4 (permalink)  
Old 07-11-08, 02:08 AM
gavintat gavintat is offline
Newbie Coder
 
Join Date: Dec 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
<SELECT NAME='selcohort'ID='selcohort'>
<?php
include 'config.php';
include 'opendb.php';

$query = "SELECT Cohort FROM course";
$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){

echo "<OPTION VALUE=".$row['cohid'].">".$row['Cohort']."</OPTION>";
}
?>
</SELECT>

replace to
echo "<OPTION VALUE=".$row['Cohort'].">".$row['Cohort']."</OPTION>"; ??
Reply With Quote
  #5 (permalink)  
Old 07-11-08, 02:16 AM
kposki kposki is offline
New Member
 
Join Date: Jul 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks gavinat, It works now..Thanks for your time and may you find help in areas where you need help for yourself.
Reply With Quote
  #6 (permalink)  
Old 07-11-08, 03:25 AM
kposki kposki is offline
New Member
 
Join Date: Jul 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Making Progress

Hi, I am making progress. By your help, what I have achieved is getting the user inputs to be inserted successfully into a table called "suggested" in my database.
Next, what I have just achieved is that another user(this time a coordinator)can view the table called "suggested" with an extra column for checkboxes to allow him approve from the suggestions. This went well.
Now I plan to finally insert the values from this table into a table called approved (meaning only the rows with approved column checked will be inserted into this new table).
Problem is I can view the suggestions now, I can tick the checkboxes but on submit, the database shows no values. No sql errors but form cant seem to release values to approved table in my database. Below is my code. I must thank you for this big help.

PHP Code:

<html>

<head>
<title>Approve electives for a selected cohort</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 </head>
<body>

<form method="post">
<table width="600" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Course Code</td>
<td>
<SELECT NAME='selcosID' ID='selcosID'>
<?php
include 'config.php';
include 
'opendb.php';

   
$query "SELECT CourseID FROM course";
$result mysql_query($query) or die(mysql_error());


while(
$row mysql_fetch_array($result)){

    echo 
"<OPTION VALUE=".$row['CourseID'].">".$row['CourseID']."</OPTION>";
}
?>
</SELECT>
</td>
</tr>

<tr>
<td width="100">Cohort</td>
<td>
<SELECT NAME ='selcohort' ID = 'selcohort'>
<?php
include 'config.php';
include 
'opendb.php';

   
$query "SELECT Cohort FROM course";
$result mysql_query($query) or die(mysql_error());


while(
$row mysql_fetch_array($result)){

    echo 
"<OPTION VALUE=".$row['Cohort'].">".$row['Cohort']."</OPTION>";
}
?>
</SELECT>
</td>
</tr>

<tr>
<td width="100">&nbsp;</td>
<td><input name="submit3" type="submit" id="submit3" value="View Suggested Modules"></td>
</tr>
</table>
</form>

<?php

if(isset($_POST['submit3']))  //if 1
{
include 
'config.php';
include 
'opendb.php';

$selcosID $_POST['selcosID'];
$selcohort $_POST['selcohort'];

$query "SELECT * FROM suggested WHERE CourseID='$selcosID' AND Cohort = '$selcohort'" ;

$result mysql_query($query) or die(mysql_error());

if(
mysql_num_rows($result) == 0)
{
?>

<p><br><br>Student Table is empty </p>
<?php
}
else
{

echo 
"<form>";
echo 
"<table border='1'>
<tr>
<th>Course Code</th>
<th>Cohort</th>
<th>Module ID</th>
<th>Module Name</th>
<th>Proposer</th>
<th>Approved</th>

</tr>"
;
while(
$row mysql_fetch_array($result))
{
echo 
"<tr>";
  echo 
"<td>" $row['CourseID'] . "</td>";
  echo 
"<td>" $row['Cohort'] . "</td>";
  echo 
"<td>" $row['ModuleID'] . "</td>";
  echo 
"<td>" $row['ModuleName'] . "</td>";
  echo 
"<td>" $row['Proposer'] . "</td>";
  echo 
"<td><input type='checkbox' name='approve' value='app'/></td>";

  echo 
"</tr>";
}
echo 
"</table>";
echo 
"</form>";

}
include 
'closedb.php';
}

?>

<form method="post">
<table>
<tr>
<td width="100">&nbsp;</td>
<td><input name="submit4" type="submit" id="submit4" value="Submit Approved Electives"></td>
</tr>
</table>
</form>
<?php

if(isset($_POST['submit4']))
{
include 
'config.php';
include 
'opendb.php'//HOW DO I GET $MODID AND $MODNAME FROM ANOTHER PHP SCRIPT CALLED suggested or from the php script above....??....or do I use "require".. ???

$selcosID $_POST['selcosID'];
$selcohort $_POST['selcohort'];
$modID $_POST['modID'];
$modName $_POST['modName'];
$prop $_POST['prop'];

// prepare the query string
$query "INSERT INTO approved (CourseID, Cohort, ModuleID, ModuleName) VALUES ('$selcosID', '$selcohort', '$modID','$modName')";

mysql_query($query) or die(mysql_error());


include 
'closedb.php';

echo 
"Your approval has been successful. $modID has been added to approved electives.";
}


?>


</body>
</html>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Combo box in Simple HTML or DHTML jpee04 HTML/XHTML/XML 3 07-06-08 04:46 AM
Combo box image change with names from database Frogger ASP 4 07-09-06 04:54 AM
Combo Box Question iamtat Visual Basic 3 10-18-05 01:49 PM
dynamic combo box jaishalg PHP 1 02-18-05 09:37 AM
help in combo box mathfxr ASP 0 12-28-04 10:05 PM


All times are GMT -5. The time now is 07:49 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.