Stupid PHP form! Not working

Get help on web editors (Frontpage, Dreamweaver) and web languages (HTML, ASP, PHP).
Post Reply
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Stupid PHP form! Not working

Post by SBSP »

I have the following code.

Code: Select all

<html>
<font size="1" face="Verdana">
<body>

<form action="userdeleted.php" method="post">



<?php

echo "<SELECT NAME=\"DelU\">";
echo "<option value>"; 
echo "--- Select user ---"; 
echo "</option>";

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("sodadb", $con);

$result = mysql_query("SELECT * FROM extensions");

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

echo $row['ExtensionNum'] .  " " . $row['ExtensionPin'] . " " . $row['ExtensionUsername'] . " " . $row['Department'] . "<BR>"  ;

echo "<option value>"; 
echo $row['ExtensionUsername']; 
echo "</option>";


  }

echo "</SELECT>";



?> 

<input type="submit" value="Delete User"  />



</body>
</font>
</html>

The above connects to MySQL and populates a combo box with data from the ExtensionUsername Field.
You can then select a user and click "Delete User" which is a HTML form with in the PHP <PHP? ?> code.

Which directs to userdeleted.php

The userdeleted.php then post gets a variable from the form element combobox wich is called DelU.

Like so

Code: Select all

$DelUser = $_POST['DelU'];
The problem is the variable $DelUser is just blank so when the below code runs it does a select statement on a blank variable.

"" so if i create a record in the table with the username field blank it deletes it so the statement works.

Something to add to the problem, the code work perfectly on my WAMP (Windows installation) but it doesnt work on
My Ubuntu Xamp installation (PHP on Xamp works as i'm using PHP admin to modify the database on ubuntu and i have one other form that is also working using a text box but in this problem its a selection or "Combo box"

Code: Select all

<html>
<font size="1" face="Verdana">
<body>

<?php


$DelUser = $_POST['DelU'];




$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("sodadb", $con);

mysql_query("DELETE FROM extensions WHERE ExtensionUsername='$DelUser'");

mysql_close($con);

Echo $DelUser  . " has been sucessfully deleted. <BR> <BR> "; 


echo "<a href=\"usermanager.php\">Back</a>"; echo " to the user manager.";



?>


</body>
</font>
</html> 
maxxis
Moderator Emeritus
Posts: 8307
Joined: 30 Jun 2004, 02:00
Location: ( . Y . )
Contact:

Re: Stupid PHP form! Not working

Post by maxxis »

Try this

Code: Select all

<html>
<font size="1" face="Verdana">
<body>

<form action="userdeleted.php" method="post">



<?php

echo "<SELECT NAME=\"DelU\">";
echo "<option value>"; 
echo "--- Select user ---"; 
echo "</option>";

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("sodadb", $con);

$result = mysql_query("SELECT * FROM extensions");

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

echo $row['ExtensionNum'] .  " " . $row['ExtensionPin'] . " " . $row['ExtensionUsername'] . " " . $row['Department'] . "<BR>"  ;

echo "<option value=".$row['ExtensionUsername'].">"; 
echo $row['ExtensionUsername']; 
echo "</option>";


  }

echo "</SELECT>";



?> 

<input type="submit" value="Delete User"  />



</body>
</font>
</html>
The reason you get a blank on the _POST is because the SELECT doesn't have a value assigned to it. The VALUE is the variable that gets sent to the processor page.

Let me know
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Re: Stupid PHP form! Not working

Post by SBSP »

Great!!!

Thanks Maxxis, it works.
po10cy
Registered User
Posts: 7160
Joined: 29 Jun 2004, 02:00
Location: Cape Town
Contact:

Re: Stupid PHP form! Not working

Post by po10cy »

maxxis for the win!
when in doubt, paddle out... ;)
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Re: Stupid PHP form! Not working

Post by SBSP »

po10cy wrote:maxxis for the win!
MFTW :mrgreen:
Post Reply