Jump to content

Recommended Posts

I have made a thread earlier but i did not get any help.

 

changeapp.php

<form method="post" name="memberadd" action="change_app_complete.php">

<label>Name:</label>
<select name="member">
<?php
$con = mysql_connect("host","user","password");
if (!$con)
{
	die('Could not connect: ' . mysql_error());
}
mysql_select_db("database",$con);
$sqlquery="SELECT * FROM `application` Order By Name";
$result=mysql_query($sqlquery,$con);
while($row=mysql_fetch_array($result))
{
	echo "<option value='".$row['ID']."'>".$row['Name']." (".$row['Status'].")</option>";
}
?>
</select>
<br>

<label>Status:</label>
<select name="Status">
<option value="PENDING">PENDING</option>
<option value="ACCEPTED">ACCEPTED</option>
<option value="DENIED">DENIED</option>
<br>
<input type="submit" value="submit" />
</form>

 

 

change_app_complete.php

<?php
$status=$_POST['Status'];
$member=$_POST['Name'];

$con = mysql_connect("host","user","pass");
if (!$con)
{
	die('Could not connect: ' . mysql_error());
}
mysql_select_db("database",$con);

$sql="UPDATE application SET Status = '$status' WHERE Name= '$member'";
if(mysql_query($sql,$con) or die(mysql_error()))
{
	echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>';
}
else
{
	die('Could not submit: ' . mysql_error());
}
mysql_close($con);

?>

 

This does not return any errors and does not change the Status...

Link to comment
https://forums.phpfreaks.com/topic/249443-update-table-in-php/
Share on other sites

Having played with this for awhile, I find that it works for me.  The column called Status is set to PENDING or ACCEPTED or DENIED. maybe the problem is in this part    WHERE Name= '$member'";    This is a number. it comes from <option value='".$row['ID']

 

If you want a name remove the value from <option>

 

echo "<option>".$row['Name']." (".$row['Status'].")</option>";

Link to comment
https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1280898
Share on other sites

did not seem to work...

 

changeapp.php:

<html>
<head>
<title>Honorable Brothers - Change Application Status</title>
</head>
<body>
<h1>Change Application Status</h1>
<hr>
<form method="post" name="appchange" action="change_app_complete.php">

<label>Name:</label>
<select name="member">
<?php
$con = mysql_connect("mysql17.000webhost.com","a2186214_gbclan","replay123");
if (!$con)
{
	die('Could not connect: ' . mysql_error());
}
mysql_select_db("a2186214_hbclan",$con);
$sqlquery="SELECT * FROM `application` Order By Name";
$result=mysql_query($sqlquery,$con);
while($row=mysql_fetch_array($result))
{
	echo "<option>".$row['Name']." (".$row['Status'].")</option>";
}
?>
</select>
<br>

<label>Status:</label>
<select name="Status">
<option value="PENDING">PENDING</option>
<option value="ACCEPTED">ACCEPTED</option>
<option value="DENIED">DENIED</option>
<br>
<input type="submit" value="submit" />
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1280982
Share on other sites

Your select menu's name attribute is 'member' <select name="member">. You would need to reference $_POST['member'] to get the value that was selected.

 

Your original <option tags had a value='...' attribute. That is what you should use and since the values were the ID, you should use the ID column in the WHERE clause in your UPDATE query, not the name column.

 

 

Link to comment
https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1281008
Share on other sites

... remove the value from <option>

 

^^^ That won't work for two reasons -

 

1) It results in invalid HTML and only certain browsers submit the display text when the value attribute is not present.

 

2) The display text is not just the name, so in the browsers where this would submit a value, it would take extra processing in the php code to get just the name out of the value.

 

@Dusaro, what ever table column you use, you must be consistent throughout all your code. You started by using the ID as the value in the form's select menu options. You must have had a plan to use the ID or you wouldn't have written the code to do that.

Link to comment
https://forums.phpfreaks.com/topic/249443-update-table-in-php/#findComment-1281102
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.