Author Topic: Updating database from PHP form  (Read 835 times)

docvx

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Updating database from PHP form
« on: August 08, 2010, 01:30:42 AM »
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  :(

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 Code: [Select]
<?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 "<table border='1' width='50%' align='center'>";


  
// 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>";
	



?>


<form action="appadmin.php?appid=<? echo $row['ID']; ?>" method="post" name="Appupdate">
  <p>
    <label for="app_status"></label>
    What action would you like to take on this application?<br />
    <select name="app_status" id="app_status">
      <option value="1">Approve</option>
      <option value="2">Deny</option>
    </select>
  </p>
  <p>Reason for your decision (Please type your reason for making this decision)?<br />
    <label for="reason_decision"></label>
    <textarea name="reason_decision" id="reason_decision" cols="75" rows="5"></textarea>
  </p>
  <p>
    <input type="submit" name="process" id="process" value="Process Application" />
  </p>
</form>




<?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.";
?>



appupdate.php


PHP Code: [Select]



<?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.";
?>




If anyone could see what is wrong with my code, or re-write it and make it work, I would be greatly appreciative!
« Last Edit: August 08, 2010, 01:39:31 AM by docvx »

martswite

  • New Member
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Updating database from PHP form
« Reply #1 on: August 09, 2010, 04:13:58 AM »
Hi do you get any errors when you try to submit the edit form?

docvx

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Updating database from PHP form
« Reply #2 on: August 09, 2010, 04:18:47 AM »
Don't believe so..

meerkat746

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Updating database from PHP form
« Reply #3 on: August 21, 2010, 10:52:59 AM »
Try putting your DB fields between ``, might be a long shot. Also "echo" your $_POST values to make sure they get passed on.
Code: [Select]
//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;
?>
« Last Edit: August 21, 2010, 11:00:03 AM by meerkat746 »