Jump to content

Mysql Update


Dusaro

Recommended Posts

I have made this, although i can not seem to the status...

 

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'];

$con = mysql_connect("host","user","password");
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))
{
	echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>';
}
else
{
	die('Could not submit: ' . mysql_error());
}
mysql_close($con);

?>

 

What is wrong?

Link to comment
https://forums.phpfreaks.com/topic/249359-mysql-update/
Share on other sites

try do this:

 

$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>';
}

 

Adding the "or die(mysql_error())" will tell you if there's any error on MySQL part. I had this issue on my "learning project", i work on 2 machines at work and at home, and when i set up the site at work i didnt gave permitions to the user to modify the database data result the site was working except for the writing into the mysql i couldnt see any changes and all the code was working t home. Hope this helps you out

 

Link to comment
https://forums.phpfreaks.com/topic/249359-mysql-update/#findComment-1280456
Share on other sites

nope, that didn't work...

 

Updated code for 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);

?>

 

It should change the Status field in the table for the member selected.

Link to comment
https://forums.phpfreaks.com/topic/249359-mysql-update/#findComment-1280469
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.