Updating database from PHP form

Hey everyone.

I am slowly learning PHP, I’ve decided to learn PHP -> MySQL database stuff first (because, that serves a great purpose for what I would like to do with my website).

Ok, what I have.

I have an application that is a form, that submits data to the database. <-- Works

I also have a page, of all applications, with a link to their application (http://versionxgaming.com/recruiting2/phpcode.php) <-- So far works

When you click on any of the links, for example, clicking on the link for application ID 18, you get (http://www.versionxgaming.com/forum/applookuptest.php?appid=18) a page that lists their details <-- works

Now, here is the tricky stuff.

I also have an admin page, that is similiar to the page of all the applications, except it has a link to an admin page.

http://versionxgaming.com/recruiting2/adminphpcode.php

And, again, for example, when you click the admin link for app id 18, you get - http://www.versionxgaming.com/recruiting2/appadmin.php?appid=18

This page is the same as the app look up, except at the bottom it has another form. This form is for admins to fill out whether they want to accept or deny the person’s application. There are 2 fields, what they want to do with the application, and the reason for their decision.

This is where I am having problems :frowning:

When they submit the form, it’s supposed to EDIT that respective ID. So if I am on appadmin.php?appid=17, it’s supposed to edit application 17, and insert the data into the database (2 new columns of the database). Note: I am not updating any of the information that already exists, just putting data into 2 columns that are not filled in on the initial application. The two columns are ‘Status’ and ‘reason_decision’

The only data that is in any of these columns is pre-generated default data in Status column. Numbers.

Pending (default) = 0 <- Database automatically assigns this value to the column.
Accepted = 1
Denied = 2

At any rate, here is the code that I have for the 2 files in particular.

appadmin.php

[php]<?php
// Make a MySQL Connection
mysql_connect(“localhost”, “dbuser”, “dbpass”) or die(mysql_error());
mysql_select_db(“versionx_recruit”) or die(mysql_error());

$appid = $_GET[‘appid’];

$getreport = mysql_query(“SELECT ID, Name, Month, Day, Year, Xfire, Steam, status_refer, Referrer, Donate, Division, Reason_Join, Clan_history, Time_Stamp FROM recruit WHERE ID = ‘$appid’”);

/* // Get all the data from the “example” table
$result = mysql_query(“SELECT * FROM recruit”)
or die(mysql_error()); */

echo “

”;

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $getreport )) {

// Print out the contents of each row into a table


$time_stamp = $row['Time_Stamp'];


/* Begin Table Row */
echo "<tr><td width ='25%' align='center'>"; 
echo "Application ID #";
echo "</td><td width ='75%' align='center'>";
echo $row['ID'];
echo "</td></tr>";	
/* End Table Row */
/* Begin Table Row */
echo "<tr><td width='25%' align='center'>"; 
echo "Player Name";
echo "</td><td width ='75%' align='center'>";
echo $row['Name'];
echo "</td></tr>";	
/* End Table Row */
/* Begin Table Row */
echo "<tr><td width='25%' align='center'>"; 
echo "Birthday";
echo "</td><td width ='75%' align='center'>";
echo $row['Month'];
echo "&nbsp;";
echo  $row['Day'];
echo ",";
echo "&nbsp;";
echo $row['Year'];	
echo "</td></tr>"; 
/* End Table Row */
/* Begin Table Row */
echo "<tr><td width='25%' align='center'>"; 
echo "Xfire Username";
echo "</td><td width ='75%' align='center'>";
echo $row['Xfire'];
echo "</td></tr>";	
/* End Table Row */
/* Begin Table Row */
echo "<tr><td width='25%' align='center'>"; 
echo "Steam Address";
echo "</td><td width ='75%' align='center'>";
echo $row['Steam'];
echo "</td></tr>";	
/* End Table Row */
/* Begin Table Row */
echo "<tr><td width='25%' align='center'>"; 
echo "Was this person referred by a member of Version X Gaming?";
echo "</td><td width ='75%' align='center'>";
echo $row['status_refer'];
echo "</td></tr>";	
/* End Table Row */
/* Begin Table Row */
echo "<tr><td width='25%' align='center'>"; 
echo "Who referred them (if applicable)";
echo "</td><td width ='75%' align='center'>";
echo $row['Referrer'];
echo "</td></tr>";	
/* End Table Row */
/* Begin Table Row */
echo "<tr><td width='25%' align='center'>"; 
echo "Is this player able to donate?";
echo "</td><td width ='75%' align='center'>";
echo $row['Donate'];
echo "</td></tr>";	
/* End Table Row */
/* Begin Table Row */
echo "<tr><td width='25%' align='center'>"; 
echo "What division do they wish to join?";
echo "</td><td width ='75%' align='center'>";
echo $row['Division'];
echo "</td></tr>";	
/* End Table Row */
/* Begin Table Row */
echo "<tr><td width='25%' align='center'>"; 
echo "Why do they want to join VerX`";
echo "</td><td width ='75%' align='center'>";
echo $row['Reason_Join'];
echo "</td></tr>";	
/* End Table Row */
/* Begin Table Row */
echo "<tr><td width='25%' align='center'>"; 
echo "Previous Clan History";
echo "</td><td width ='75%' align='center'>";
echo $row['Clan_history'];
echo "</td></tr>";	
/* End Table Row */
/* Begin Table Row */
echo "<tr><td width='25%' align='center'>"; 
echo "Time Application Submitted";
echo "</td><td width ='75%' align='center'>";
echo date('M-jS-Y h:i:s A T', $time_stamp);
echo "</td></tr>";	
/* End Table Row */

}

echo "</table>";	

?>

What action would you like to take on this application?
Approve Deny

Reason for your decision (Please type your reason for making this decision)?

<?php // Make a MySQL Connection mysql_connect("localhost", "dbuser", "dbpass") or die(mysql_error()); mysql_select_db("versionx_recruit") or die(mysql_error()); $appid = $_GET['appid']; $getreport = mysql_query("SELECT ID, Name, Month, Day, Year, Xfire, Steam, status_refer, Referrer, Donate, Division, Reason_Join, Clan_history, Time_Stamp FROM recruit WHERE ID = '$appid'"); $app_status = $_POST['app_status']; $decision = $_POST['reason_decision']; if (isset($_GET['appid'])){ // appid exists. } $sqlupdate="UPDATE recruit SET Status='$app_status', app_reason='$decision' WHERE ID='$appid'"; $result=mysql_query($sqlupdate) or die ('Error submitting form'); echo "Application processed."; ?>

[/php]
appupdate.php

[php]

<?php // Make a MySQL Connection mysql_connect("localhost", "dbuser", "dbpass") or die(mysql_error()); mysql_select_db("versionx_recruit") or die(mysql_error()); $app_status = $_POST['app_status']; $decision = $_POST['reason_decision']; if (isset($_GET['appid'])){ // appid exists. } $sqlupdate="UPDATE recruit SET Status='$app_status', app_reason='$decision' WHERE ID='$appid'"; $result=mysql_query($sqlupdate) or die ('Error submitting form'); echo "Application processed."; ?>

[/php]

If anyone could see what is wrong with my code, or re-write it and make it work, I would be greatly appreciative!

Hi do you get any errors when you try to submit the edit form?

Don’t believe so…

Try putting your DB fields between ``, might be a long shot. Also “echo” your $_POST values to make sure they get passed on.

//Query
$sqlupdate="UPDATE `recruit` SET `Status`='$app_status', `app_reason`='$decision' WHERE `ID`='$appid'";
//Check if info is passed on
</php
$app_status=$_POST['app_status'];
echo $app_status;
?>
Sponsor our Newsletter | Privacy Policy | Terms of Service