Jump to content

Recommended Posts

I have worked a lot with PHP and MySQL with Flash/Actionscript, but I am new to working with PHP and MySQL with HTML. I basically have a page used to edit a database entry with the standard add/edit/delete functions and next/previous buttons to go to the next/previous entry.

 

The problem I am having is that I am trying to define a function for the loading sequence, where I can just call load(); and the PHP will execute and load the variables from MySQL into the HTML page. However, it will not work as a function, although it works when it is not within a function. I am guessing the HTML loads after the PHP function is executed.

 

Here is an example of my file. I am using $PHP_SELF to relay the information back each time the page loads, which may be part of the problem.

 

You can view the page at:

http://www.quick-sites.biz/TestServer/Property/Editor/

 

I will being working on it though so you may see a different version.

 

<?php

 

//Include

include("../PHP/Include.php");

 

function load(){

//Query

$entryID= 0;

$limit= 1;

$query= "SELECT * FROM `property` LIMIT ".$entryID.",".$limit;

$data= mysql_query($query);

 

//Data

$row= mysql_fetch_array($data);

$id= $row['id'];

$property_Owner= $row['property_Owner'];

$property_Phone= $row['property_Phone'];

$property_Street= $row['property_Street'];

$property_City= $row['property_City'];

$property_State= $row['property_State'];

$property_Zip= $row['property_Zip'];

$property_ARV= $row['property_ARV'];

$property_Repairs= $row['property_Repairs'];

$property_Offer= $row['property_Offer'];

$property_Status= $row['property_Status'];

 

//Total

$totalQuery= "SELECT * FROM `property`";

$totalData= mysql_query($totalQuery);

$total= mysql_num_rows($totalData);

echo $entryID;

echo $id;

echo $total;

}

load();

 

//Functions

if(isset($_POST['next'])) {

nextPage();

}

if(isset($_POST['previous'])) {

previousPage();

}

if(isset($_POST['add'])) {

add();

}

if(isset($_POST['edit'])) {

edit();

}

if(isset($_POST['delete'])) {

delete();

}

 

//Add

function add(){

$add_Owner= $_POST['property_Owner'];

$add_Phone= $_POST['property_Phone'];

$add_Street= $_POST['property_Street'];

$add_City= $_POST['property_City'];

$add_State= $_POST['property_State'];

$add_Zip= $_POST['property_Zip'];

$add_ARV= $_POST['property_ARV'];

$add_Repairs= $_POST['property_Repairs'];

$add_Offer= $_POST['property_Offer'];

$add_Status= $_POST['property_Status'];

$addQuery= "INSERT INTO `property` (`id`, `property_Owner`, `property_Phone`, `property_Street`, `property_City`, `property_State`, `property_Zip`, `property_ARV`, `property_Repairs`, `property_Offer`, `property_Status`) VALUES ('', '$add_Owner', '$add_Phone', '$add_Street', '$add_City', '$add_State', '$add_Zip', '$add_ARV', '$add_Repairs', '$add_Offer', '$add_Status')";

mysql_query($addQuery);

load();

}

 

//Edit

function edit(){

$id= $_POST['id'];

$edit_Owner= $_POST['property_Owner'];

$edit_Phone= $_POST['property_Phone'];

$edit_Street= $_POST['property_Street'];

$edit_City= $_POST['property_City'];

$edit_State= $_POST['property_State'];

$edit_Zip= $_POST['property_Zip'];

$edit_ARV= $_POST['property_ARV'];

$edit_Repairs= $_POST['property_Repairs'];

$edit_Offer= $_POST['property_Offer'];

$edit_Status= $_POST['property_Status'];

$editQuery= "UPDATE `property` SET `property_Owner` = '".$edit_Owner."' ,`property_Phone`= '".$edit_Phone."' ,`property_Street` = '".$edit_Street."' ,`property_City`= '".$edit_City."' ,`property_State` = '".$edit_State."' ,`property_Zip`= '".$edit_Zip."' ,`property_ARV`= '".$edit_ARV."' ,`property_Repairs` = '".$edit_Repairs."' ,`property_Offer`= '".$edit_Offer."' ,`property_Status`= '".$edit_Status."' WHERE `id`=".$id;

mysql_query($editQuery);

load();

}

 

//Delete

function delete(){

$id= $_POST['id'];

$deleteQuery= "DELETE FROM `property` WHERE `id`=".$id;

mysql_query($deleteQuery);

load();

}

 

//nextPage

function nextPage(){

$entryID= $_POST['entryID'];

$entryID+= 1;

load();

}

 

//previousPage

function previousPage(){

$entryID= $_POST['entryID'];

$entryID+= 1;

load();

}

 

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/Editor.dwt" codeOutsideHTMLIsLocked="false" -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- InstanceBeginEditable name="head" -->

<title>Property Manager</title>

<link rel="stylesheet" type="text/css" href="../CSS/Layout.css" />

<!-- InstanceEndEditable -->

</head>

 

<body>

<div id="Site">

<div id="SiteHeader">

Editor<br />

<form name="Logout" action="../index.php">

<input type="submit" name="login" value="Logout" />

</form>

</div><!--SiteHeader-->

<!-- InstanceBeginEditable name="body" -->

<div id="SiteBody">

<div id="Editor_Information">

<form id="form_Property" name="form_Property" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">

<input type="hidden" name="entryID" value="<?php echo $entryID; ?>" />

<input type="hidden" name="id" value="<?php echo $id; ?>" />

<table>

<tr>

<td><br />Property Information:</td><td></td>

</tr>

<tr>

<td>Property Street:</td><td><input type="text" name="property_Street" id="property_Street" value="<?php echo $property_Street; ?>" /></td>

</tr>

<tr>

<td>Property City:</td><td><input type="text" name="property_City" id="property_City" value="<?php echo $property_City; ?>"/></td>

</tr>

<tr>

<td>Property State:</td><td>

<select name="property_State" id="property_State" value="<?php echo $property_State; ?>">

            <option>--Please Select--</option>

            <option>AK - Alaska</option>

            <option>AL - Alabama</option>

            <option>AR - Arkansas</option>

            <option>AZ - Arizona</option>

            <option>CA - California</option>

            <option>CO - Colorado</option>

            <option>CT - Connecticut</option>

            <option>DE - Delaware</option>

            <option>FL- Florida</option>

            <option>GA - Georgia</option>

            <option>HI - Hawaii</option>

            <option>IA - Iowa</option>

            <option>ID - Idaho</option>

            <option>IL - Illinois</option>

            <option>IN - Indiana</option>

            <option>KS - Kansas</option>

            <option>KY - Kentucky</option>

            <option>LA - Louisiana</option>

            <option>MA - Massachusetts</option>

            <option>MD - Maryland</option>

            <option>ME - Maine</option>

            <option>MI - Michigan</option>

            <option>MN - Minnesota</option>

            <option>MO - Missouri</option>

            <option>MS - Mississippi</option>

            <option>MT - Montana</option>

            <option>NC - North Carolina</option>

            <option>ND - North Dakota</option>

            <option>NE - Nebraska</option>

            <option>NH - New Hampshire</option>

            <option>NJ - New Jersey</option>

            <option>NM - New Mexico</option>

            <option>NV - Nevada</option>

            <option>NY - New York</option>

            <option>OH - Ohio</option>

            <option>OK - Oklahoma</option>

            <option>OR - Oregon</option>

            <option>PA - Pennsylvania</option>

            <option>RI - Rhode Island</option>

            <option>SC - South Carolina</option>

            <option>SD - South Dakota</option>

            <option>TN - Tennessee</option>

            <option>TX - Texas</option>

            <option>UT - Utah</option>

            <option>VA - Virginia</option>

            <option>VT - Vermont</option>

            <option>WA - Washington</option>

            <option>WI - Wisconsin</option>

            <option>WV - West Virginia</option>

            <option>WY - Wyoming</option>

</select>

</td>

</tr>

<tr>

<td>Property Zip:</td><td><input type="text" name="property_Zip" id="property_Zip" value="<?php echo $property_Zip; ?>"/></td>

</tr>

<tr>

<td><br  />Owner Information:</td><td></td>

</tr>

<tr>

<td>Property Owner:</td><td><input type="text" name="property_Owner" id="property_Owner" value="<?php echo $property_Owner; ?>"/></td>

</tr>

<tr>

<td>Property Phone:</td><td><input type="text" name="property_Phone" id="property_Phone" value="<?php echo $property_Phone; ?>"/></td>

</tr>

</table>

</div>

<div id="Editor_Value">

<table><tr>

<td>Property Value:</td><td></td>

</tr>

<tr>

<td>Property ARV:</td><td><input type="text" name="property_ARV" id="property_ARV" value="<?php echo $property_ARV; ?>"/></td>

</tr>

<tr>

<td>Repairs: </td><td><input type="text" name="property_Repairs" id="property_Repairs" value="<?php echo $property_Repairs; ?>"/></td>

</tr>

<tr>

<td>Current Offer:</td><td><input type="text" name="property_Offer" id="property_Offer" value="<?php echo $property_Offer; ?>"/></td>

</tr>

<tr>

<td>Offer Status:</td>

<td>

<select name="property_Status" id="property_Status" value="<?php echo $property_Status; ?>">

            <option>--Please Select--</option>

            <option>Offer Not Submitted</option>

            <option>Offer Submitted</option>

            <option>Offer Accepted</option>

            <option>Offer Rejected</option>

            <option>Property Purchased</option>

            <option>Property Repaired</option>

            <option>Property Sold</option>

</select>

</td>

</tr>

</table>

</div>

<input name="next" type="submit" value="Next Property" />

<input name="previous" type="submit" value="Previous Property" />

<input name="add" type="submit" value="Add Property"/>

<input name="edit" type="submit" value="Edit Property" />

<input name="delete" type="submit" value="Delete Property" />

</form>

</div><!--SiteBody-->

<!-- InstanceEndEditable -->

</div><!--Site-->

</body>

<!-- InstanceEnd --></html>

 

  • 2 weeks later...

Your missing a while loop to actually get the data it looks like...

 

//Total
$totalQuery= "SELECT * FROM `property`";
$totalData= mysql_query($totalQuery);
$total= mysql_num_rows($totalData);
echo $entryID;
echo $id;
echo $total; 

 

should be more like....

//Total
$totalQuery= "SELECT * FROM `property`";
$totalData= mysql_query($totalQuery);
$total= mysql_num_rows($totalData);
while($row = mysql_fetch_object($totalData))
{
    echo $row->entryID.'<br>';
    echo $row->id.'<br>';
}
echo $row->total.'<br>';

 

Thats what I can see offhand. try that and see if it helps ya.

 

Nate

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.