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