Forum Moderators: coopster

Message Too Old, No Replies

My script pulls all events

not just events where the id's match

         

BadGoat

12:36 pm on May 26, 2005 (gmt 0)

10+ Year Member



Hi!

The goal is to have the $id, which is set already, get saved into the $dep_id field in a different table.. I think it's a problem in matching variables, but I am not positive. As it is right this moment, the script displays all events with all IDs, not just where $id=$dep_id... Can someone steer me in the right direction?

<html>
<head>
<title>Add Participants</title>
</head>
<body>
<?php
// Connect to database
$connect= mysql_connect("localhost","root")
or die("Could not connect to database in localhost!");
mysql_select_db("testdiw")
or die("Could not select that database!");

$id = $_GET['id'];

$query = "SELECT * FROM diw_alpha WHERE id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

echo '
<TABLE BORDER="0" width=600 cellspacing=0>

<form name="form3" method="post">

<TR>
<TD> ID</TD>
<TD>'.$row['id'].'</TD>
<TR>
<TR>
<TD>Title</TD>
<TD>'.$row['diwtitle'].'</TD>
<TR>
<TD colspan=2> <CENTER>
<select name="name" tabindex="4"><option value="-notset-">- Select a participant -</option> ';

//--- CREATE VIDEOGRAPHY COMPANY SELECT ---
$sql = "SELECT DISTINCT name FROM part_name ORDER BY name";
$name = mysql_query($sql) or die($sql . '<br />' . mysql_error());
while ($row = mysql_fetch_array($name)) {
echo '<option value="' . $row['name'] . '">' . $row['name'] . '</option>';
}
;

echo ' </CENTER></TD>
</TR>
<TR>
<TD COLSPAN=2><BR><CENTER><input type="submit" name="Submit" value="Submit" action="required"></CENTER></TD></FORM>
</TR>
</TABLE> ';

?>

<?PHP
$connect= mysql_connect("localhost","root")
or die("Could not connect to database in localhost!");
$result=mysql_select_db("testdiw")
or die("Could not select that database!");

$sqlquery = "INSERT INTO attendees VALUES('', '". $_POST['name'] ."', '". $_POST['dep_id'] ."')";
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query!");
$sqlquery = "SELECT * from attendees";

$id = $row['id'];

$id = $HTTP_POST_VARS['dep_id'];

$sqlquery1 = "SELECT participant_id, name FROM attendees where dep_id = '$id' ORDER BY name";
$queryresult1 = mysql_query($sqlquery1) or die(" Could not execute mysql query #2!");
$row = mysql_fetch_row($queryresult1);
$participant_id = $row[0];
$name = $row[1];
$byebye = $row[2];


$tdcount = 1;
$numtd = 1; // number of cells per row
echo '
<TABLE width="48%" ALIGN="left" CELLSPACING=2>
<tr>
<>Participant ID </td>
<> Participant Name</td>
<> Action</td>';
while($row = mysql_fetch_array($queryresult1)) {
if ($tdcount == 1) echo "<tr>";
echo '<td> '.$row['participant_id'],'</td><td>'.$row['name'].'</td><td><a href="?participant_id='.$row['participant_id'],'&action=delete">Delete</a></td>';
if ($tdcount == $numtd) {
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
// time to close up our table
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
echo "<td>&nbsp;</td>";
$tdcount++;
}
echo "</tr>";
}
echo '
</table> ';
?>

ketel

4:51 pm on May 26, 2005 (gmt 0)

10+ Year Member



There seem to be a lot of things wrong, here are some things you can look at. Its just a quick look so i might be wrong.

<html>
<head>
<title>Add Participants</title>
</head>
<body>
<?php
// Connect to database
$connect= mysql_connect("localhost","root")
or die("Could not connect to database in localhost!");
mysql_select_db("testdiw")
or die("Could not select that database!");

$id = $_GET['id'];

$query = "SELECT * FROM diw_alpha WHERE id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

echo '
<TABLE BORDER="0" width=600 cellspacing=0>

<form name="form3" method="post">
///// where is the action page going to, action=?

<TR>
<TD> ID</TD>
<TD>'.$row['id'].'</TD>
<TR>
<TR>
<TD>Title</TD>
<TD>'.$row['diwtitle'].'</TD>
<TR>
<TD colspan=2> <CENTER>
<select name="name" tabindex="4"><option value="-notset-">- Select a participant -</option> ';

//--- CREATE VIDEOGRAPHY COMPANY SELECT ---
$sql = "SELECT DISTINCT name FROM part_name ORDER BY name";
$name = mysql_query($sql) or die($sql . '<br />' . mysql_error());
while ($row = mysql_fetch_array($name)) {
echo '<option value="' . $row['name'] . '">' . $row['name'] . '</option>';
}
;
////// you need a </select> somewhere

echo ' </CENTER></TD>
</TR>
<TR>
<TD COLSPAN=2><BR><CENTER><input type="submit" name="Submit" value="Submit" action="required"></CENTER></TD></FORM>
</TR>
</TABLE> ';

?>

<?PHP
$connect= mysql_connect("localhost","root")
or die("Could not connect to database in localhost!");
$result=mysql_select_db("testdiw")
or die("Could not select that database!");

$sqlquery = "INSERT INTO attendees VALUES('', '". $_POST['name'] ."', '". $_POST['dep_id'] ."')";
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query!");
$sqlquery = "SELECT * from attendees";
/////where do you use this query?

$id = $row['id'];
/////the above seems useless what $id do you wan't?

$id = $HTTP_POST_VARS['dep_id'];
/////where did you get the $_POST var from it's not in /////your form? Try to echo '$id' here

$sqlquery1 = "SELECT participant_id, name FROM attendees where dep_id = '$id' ORDER BY name";
$queryresult1 = mysql_query($sqlquery1) or die(" Could not execute mysql query #2!");

/////$row = mysql_fetch_row($queryresult1);
/////$participant_id = $row[0];
/////$name = $row[1];
/////$byebye = $row[2];
///// I don't think you need the above code

$tdcount = 1;
$numtd = 1; // number of cells per row
echo '
<TABLE width="48%" ALIGN="left" CELLSPACING=2>
<tr>
//////<td> needed here
<>Participant ID </td>
<> Participant Name</td>
<> Action</td>';
while($row = mysql_fetch_array($queryresult1)) {
if ($tdcount == 1) echo "<tr>";
////The code below will give trouble i think, try using
/////double quotes for echo, like echo /////"<td>".$row['participant_id'].",</td>.....

echo '<td> '.$row['participant_id'],'</td><td>'.$row['name'].'</td><td><a href="?participant_id='.$row['participant_id'],'&action=delete">Delete</a></td>';
if ($tdcount == $numtd) {
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
// time to close up our table
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
echo "<td>&nbsp;</td>";
$tdcount++;
}
echo "</tr>";
}
echo '
</table> ';
?>