Jump to content

Update database with dropdown list value


anton_1

Recommended Posts

Hey guys, Every help would be greatly apperciated!

 

having a bit of bother updating my database when a user selects a value from the drop down menu

 

here is the code:

 

 

 

echo '<form action="UpdateFields.php" method="post">';

$data = @mysql_query("select AssignedTo from Tickets");

echo "<p>Assigned To:";

echo '<br>';

echo '<br>';

echo '<Select Name="Assign">';

while ($row = mysql_fetch_assoc($data))

{

$ID = $row['id'];

$year = $row['AssignedTo'];

echo "<option value=$id>$year";

}

echo "</select>";

echo "</p>";

 

$data = @mysql_query("select Status from Tickets");

echo "<p>Status:";

echo '<br>';

echo '<br>';

echo '<Select Name="Stat">';

while ($row = mysql_fetch_assoc($data))

{

$ID = $row['id'];

$year = $row['Status'];

echo "<option value=$id>$year";

}

echo "</select>";

echo "</p>";

 

echo '<br>';

echo '<br>';

 

echo  '<input type="submit" name="update" value="Update!" />';

 

echo '</form>';

 

 

goes to:

 

<?php

 

 

$ud_id = $_POST['Assign'];

 

 

 

 

mysql_connect('localhost', 'web101-db1-1', 'mypassword');

mysql_select_db('web101-db1-1');

 

 

 

 

 

 

$query="UPDATE Helpdesk '";          //not sure what goes here

mysql_query($query);

echo "Record Updated";

mysql_close();

 

 

 

 

 

?>

 

 

 

 

 

Link to comment
Share on other sites

in this part:

 

$ID = $row['id'];
$year = $row['AssignedTo'];
echo "<option value=$id>$year";

try:

$id = $row['id'];
$year = $row['AssignedTo'];
echo "<option value='".$id."'>".$year."</option>";

 

$ID and $id are two different things (one uppercase, one lowercase). Do they both exist? do they have the correct values? what does your error_reporting say? (check your error logs) You're also not closing your <option> elements.

 

Link to comment
Share on other sites

This help is really appreciated WebStyles!

 

this is what I have now echo '<form action="UpdateFields.php" method="post">';

 

 

$data = @mysql_query("select AssignedTo from Tickets");

echo "<p>Assigned To:";

echo '<br>';

echo '<br>';

echo '<Select Name="Assign">';

while ($row = mysql_fetch_assoc($data))

{

$id = $row['id'];

$year = $row['AssignedTo'];

echo "<option value='".$id."'>".$year."</option>";

}

echo "</select>";

echo "</p>";

 

 

 

to this page:

 

<?php

 

 

 

$value = $_POST['Assign'];

 

mysql_connect('localhost', 'web101-db1-1', 'Hiyapal2');

mysql_select_db('web101-db1-1');

 

 

 

 

 

 

$query="UPDATE Helpdesk WHERE AssignedTo ='$ud_id'";

mysql_query($query);

echo "Record Updated";

mysql_close();

 

 

?>

 

 

Nothing being displayed?

 

 

 

Link to comment
Share on other sites

<?php

 

 

echo $value = $_POST['Assign'];

 

mysql_connect('localhost', 'web101-db1-1', 'Hiyapal2');

mysql_select_db('web101-db1-1');

 

 

 

 

 

 

$query="UPDATE Helpdesk WHERE AssignedTo ='$ud_id'";

mysql_query($query);

echo "Record Updated";

mysql_close();

 

 

 

?>

 

Still displaying nothing, it doesnt seem to be taking the value from the previous page

Link to comment
Share on other sites

A little offtopic, but I would suggest using var_dump($var); instead of echo because this shows you more debug information. If the variable does not reach the page, and you try to use the variable on that page you should get some WARNING something like call to undefined variable or similar. Do you have error reporting also turned on?

 

this in the beginning of your scripts

ini_set('display_errors', 1);
error_reporting(-1);

Link to comment
Share on other sites

So from this we can see that the variable does reach the page, but it contains value of empty string. Then you get the notice for using variable $ud_id in the SQL query, but you have not set this variable before using it. Where does this $ud_id come from?

Link to comment
Share on other sites

That was an old variable which I have now changed.

 

 

<?php

ini_set('display_errors', 1);

error_reporting(-1);

 

 

$value = $_POST['Assign'];

 

 

var_dump($value);

 

mysql_connect('localhost', 'web101-db1-1', '');

mysql_select_db('web101-db1-1');

 

 

 

 

 

 

$query="UPDATE Helpdesk WHERE AssignedTo ='$value'";

mysql_query($query);

echo "Record Updated";

mysql_close();

 

 

 

 

 

 

 

?>

 

Thanks

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.