Hello everyone,
I am very new to PHP and all scripting for that matter. I just started last monday doing this stuff so bear with me. My coding will be newbie code and this is a test run before I make the site go live for the department. I will clean it up and make it for the new standards as I do use <center></center> instead of the <div > tags.
Basically, I would like this site to update possibly using AJAX without having to refresh. I can add/delete/modify the records in the Database but only way to see the updates is to throw in a refresh script. I have done a lot of research on this before coming here and I did look at the w3schools site and can not figure out how to make there PHP and AJAX Database work on my own coding.
Any help would be much appreciated.
<?php
global $Names;
$Names = array();
// Connecting to the localhost
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Selecting the Database and Table for use
mysql_select_db("oncall", $con);
$result = mysql_query("SELECT * FROM techs");
// Setting the Default Column Headers used in the Table
echo "<center><table cellspacing='3' cellpadding='10' border='5'>
<tr>
<td><b><u>Name</u></b></td>
<td><b><u>Location</u></b></td>
<td><b><u>PDA</u></b></td>
<td><b><u>Nextel</u></b></td>
<td><b><u>Cell Phone</u></b></td>
<td><b><u>Home Phone</u></b></td>
<td><b><u>Fax</u></b></td>
<td><b><u>Email</u></b></td>
<td><b><u>Region</u></b></td>
<td><b><u>FM</u></b></td>
<td><b><u>Area Manager</u></b></td>
</tr>
";
// Building the table as defined under the Default Headers
$c = 0;
while($row = mysql_fetch_array($result))
{
echo "<tr>
<td>" . $row['Name'] . "</td>
<td>" . $row['Location'] . "</td>
<td>" . $row['PDA'] . "</td>
<td>" . $row['Nextel'] . "</td>
<td>" . $row['CPhone'] . "</td>
<td>" . $row['HPhone'] . "</td>
<td>" . $row['Fax'] . "</td>
<td>" . $row['Email'] . "</td>
<td>" . $row['Region'] . "</td>
<td>" . $row['FM'] . "</td>
<td>" . $row['AreaManager'] . "</td>
</tr>";
$Names[$c] = $row['Name'];
$c++;
}
echo "</table></center>";
?>
<br />
<br />
<center>
<form action="tabletechs.php" method="post">
<?php
//var_dump($Names);
// Selecting a Name that will be either modified or deleted from the drop down list
echo "Name: <select name='name'>
<option value=''>Select a Name</option>";
$x = 0;
foreach ($Names as $Name)
{
echo "<option value=\"" . $Name . "\">" . $Name . "</option>";
}
echo "</select><br /><br />";
?>
The below HTML coding is actually at the end of the PHP coding so both are on one page.
Name to add: <input type="text" size="10" name="name2" />
<br />
<br />
<table>
<tr>
<td>Name: </td>
<td><input type="text" size="10" name="name3" /></td>
<td>Location: </td>
<td><input type="text" size="10" name="Location" /></td>
<td>PDA: </td>
<td><input type="text" size="10" name="PDA" /></td>
<td>Nextel: </td>
<td><input type="text" size="10" name="Nextel" /></td>
<td>Cell Phone: </td>
<td><input type="text" size="10" name="CPhone" /></td>
<td>Home Phone: </td>
<td><input type="text" size="10" name="HPhone" /></td>
<td>Fax: </td>
<td><input type="text" size="10" name="Fax" /></td>
<td>Email: </td>
<td><input type="text" size="10" name="Email" /></td>
<td>Region: </td>
<td><input type="text" size="10" name="Region" /></td>
<td>FM: </td>
<td><input type="text" size="10" name="FM" /></td>
<td>Area Manager: </td>
<td><input type="text" size="10" name="AreaManager" /></td>
</table>
<br />
<br />
<select name="option">
<option value="">Select an Option</option>
<option value="add">Add</option>
<option value="delete">Delete</option>
<option value="modify">Modify</option>
</select>
<br />
<br />
<input type="submit" value="Make Change"/>
</form>
</center>