









|
[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
[NMLUG] PHP/MySQL scripts
- Subject: [NMLUG] PHP/MySQL scripts
- From: nmlug@swcp.com (Tim Price)
- Date: 19 Oct 2000 14:43:44 -0600
Are there any PHP/MySQL gurus in the group that could be so kind as to take a look at the two PHP4 scripts, addtots1.php4 and addtots2.php4, I've included below and possibly tell me why data is not inserted into MySQL tables when addtots2.php4 is invoked?
For a little background, I'm attempting to recreate our office automation program using PHP and MySQL for use on the company's Intranet. I've been experimenting with using PHP/MySQL solutions on the Intranet to try and overcome the many incompatibility problems and other issues between Microsoft and Apple products. I created our current office automation program using FoxBase+ Mac (pre-Microsoft) in 1989. It still works great, but we can only use it with Macintoshes on the network. We would like it, and all our apps, to work across all platforms in the office.
These scripts deal with selection of information for input into timesheet tables. The script addtots1.php4 builds a timesheet input form that fills in the employee id number, the employee name, the project number and the project name that have been input and selected from a form built by a script named addtots.php4.
After the employee finishes filling in the rest of the timesheet form and presses the "Save" button, addtots2.php4 is supposed to insert the data that was filled in by addtots1.php4 and input by the employee in the employee's timesheet table that matches the variable $ts (the employee's timesheet table name acquired from the ts field in the table staff), and display the information added to the database before the employee continues.
I have tried various approaches, but I cannot figure out how to get addtots2.php4 to insert the info to the timesheet tables (a modified version of addtots2.php4 will insert data into a timesheet table from the same timesheet form built solely in html).
Depending on the approach I use, I either get "Couldn't execute query!" or "Couldn't add record!" or I get the correct page displaying the data that was on the timesheet form, but when I check the database the record was not added to the table.
I've included the addtots2.php4 script that I think should work because similar scripts work with other projects I've done with PHP/MySQL. This version of the script returns "Couldn't execute query!"
If anyone has any ideas of what I need to do I would really appreciate it. Other elements of the office automation program have gone together very well using PHP/MySQL. The timesheets portion is the most important, and for the moment I have come across a major stumbling block.
Also, I'm a real novice with PHP/MySQL so the scripts may be kind of weird.
===========================================================================
<?php // addtots1.php4
$connection = mysql_connect("localhost","user","pw")
or die ("Unable to connect to database.");
$db = mysql_select_db("arcadmin", $connection)
or die ("Unable to select database.");
$sql = "SELECT stid, name, ts FROM staff
WHERE stid='$id' and password='$password'";
$result = mysql_query($sql, $connection) or die ("Couldn't get results.");
while ($row = mysql_fetch_array($result)) {
$id = $row["stid"];
$name = $row["name"];
$ts = $row["ts"];
$num = mysql_numrows($result) or die ("Couldn't get count.");
if ($num == 1) {
echo "
<HTML>
<HEAD>
<TITLE>Add to Time Sheets</TITLE>
</HEAD>
<BODY>
<FORM method=\"POST\" action=\"addtots2.php4\">
<tr>
<td valign=top><strong>Employee ID Number:</strong></td>
<td valign=top><INPUT type=\"text\" name=\"stid\" value=\"$id\" size=5 maxlength=5></td>
</tr>
<tr>
<td valign=top><strong>Name:</strong></td>
<td valign=top><INPUT type=\"text\" name=\"name\" value=\"$name\" size=30 maxlength=50></td><br>
</tr>
<br>
";
}
else if ($num == 0) {
echo "You are not authorized!";
}
$sql = "SELECT projno2, shortdesc FROM projects WHERE projno2 = \"$sel_record\"";
$sql_result = mysql_query($sql) or die ("Couldn't execute query!");
if (!sql_result) {
echo "<P>Couldn't get record!";
} else {
while ($row = mysql_fetch_array($sql_result)) {
$projno = $row["projno2"];
$project = $row["shortdesc"];
$id = $row["stid"];
}
echo "
<tr>
<td valign=top><strong>Project No:</strong></td>
<td valign=top><INPUT type=\"text\" name=\"projno\" value=\"$projno\" size=15 maxlength=16></td>
</tr>
<tr>
<td valign=top><strong>Project:</strong></td>
<td valign=top><INPUT type=\"text\" name=\"project\" value=\"$project\" size=60 maxlength=80></td>
</tr><br>
<br>
<center>
<tr>
<td valign=top><strong>Description of work done and expenses:</strong></td><br>
<td valign=top>
<TEXTAREA name=\"descript\" cols=100 rows=4>$descript</TEXTAREA><br>
</td>
</tr>
</center>
<br>
<tr>
<td valign=top><strong>Date:</strong></td>
<td valign=top><INPUT type=\"text\" name=\"projdate\" size=12 maxlength=15></td>
</tr>
<tr>
<td valign=top><strong>Hours Worked:</strong></td>
<td valign=top><INPUT type=\"text\" name=\"reghours\" size=12 maxlength=15></td><br>
</tr>
<br>
<tr>
<td valign=center><INPUT type=\"checkbox\" name=\"persleave\" value=\"T\"> Personal Leave</td>
</tr>
<tr>
<td valign=top><strong>Expenses:</strong></td>
<td valign=top><INPUT type=\"text\" name=\"expenses\" size=12 maxlength=15></td>
</tr>
<tr>
<td valign=top><strong>Mileage:</strong></td>
<td valign=top><INPUT type=\"text\" name=\"mileage\" size=12 maxlength=15></td><br>
</tr>
<tr>
<td valign=center><INPUT type=\"checkbox\" name=\"travel\" value=\"T\"> Travel Hours - check here<br></td><br>
</tr>
<br>
<br>
<center>
<tr>
<td align=center colspan=2><INPUT type=\"submit\" value=\"Save\"></td> </tr>
<tr>
<td align=center colspan=2><INPUT type=\"button\" value=\"Cancel\" onClick=\"history.back()\"></td>
</tr>
</center>
</FORM>
</BODY>
</HTML>
";
} }
?>
=========================================================
<?php // addtots2.php4
$sql = "INSERT INTO \"$ts\" VALUES (\"$id\", \"$name\", \"$projno\", \"$project\", \"$descript\", \"$projdate\", \"$reghours\", \"$persleave\", \"$expenses\", \"$mileage\", \"$travel\")";
$connection = mysql_connect("localhost","user","pw")
or die ("Unable to connect to database.");
$db = mysql_select_db("arcadmin", $connection)
or die ("Unable to select database.");
$sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query!");
if (!$sql_result) {
echo "<P>Couldn't add record!";
} else {
echo "
<HTML>
<HEAD>
<TITLE>ARC Add to Time Sheet</TITLE>
</HEAD>
<BODY>
<h3>Time sheet entry added</h3>
<FORM method=\"POST\" action=\"addtots3.php4\">
<tr>
<td valign=top><strong>Employee ID Number:</strong></td>
<td valign=top>$stid</td>
</tr>
<tr>
<td valign=top><strong>Name:</strong></td>
<td valign=top>$name</td><br>
</tr>
<tr>
<td valign=top><strong>Project:</strong></td>
<td valign=top>$projno</td>
</tr>
<tr>
<td valign=top>$project</td>
</tr><br>
<tr>
<td valign=top><strong>Date:</strong></td>
<td valign=top>$projdate</td>
</tr>
<tr>
<td valign=top><strong>Hours Worked:</strong></td>
<td valign=top>$reghours</td>
</tr>
<tr>
<td valign=top><strong>Travel Hours:</strong></td>
<td valign=top>$travel</td>
</tr><br>
<tr>
<td valign=top><strong>Description of work done and expenses:</strong></td>
<td valign=top>$descript</td>
</tr><br>
<tr>
<td valign=top><strong>Personal Leave:</strong></td>
<td valign=top>$persleave</td>
</tr>
<tr>
<td valign=top><strong>Expenses:</strong></td>
<td valign=top>$expenses</td>
</tr>
<tr>
<td valign=top><strong>Mileage:</strong></td>
<td valign=top>$mileage</td><br>
</tr>
<br>
<center>
<tr>
<td align=center colspan=2><INPUT type=\"submit\" value=\"Continue\"></td> </tr><br>
<br>
<a href=\"timesheets.php4\">Return to Menu</a>
</center>
</FORM>
</BODY>
</HTML>
";
}
?>
------------------------------------------------------
To UNSUBSCRIBE send a message to nmlug-request@swcp.com
with only the word unsubscribe in the body. More
information can be found at www.nmlug.org/info.html
-----------------------------------------------------
|
|