Hi all you programers. I have been trying to teach myself PHP and Mysql. Been reading books and doing a little code off an on for about 4 years now and I still suck. LOL
I have gotten this to work on my home setup and my personal setup at work. But cannot get it to work on the live server at work. I am trying to setup a inventory system for about 5000 PC,Printers in about 5 diffrent locations. (a multi site hospital) The reason I cannot use phpmy inventory is because of the complex information needed to make it useful. But I could write a long thread about that. My first step I am working on is a simple upload text file that inserts the info into a database table with only two fields. So here is the info,
Home and personal setup. PHP 5 and mysql 5 on Windows xp running apache.
Live server is PHP4 and mysql 4 on Windows server & MS iie. (did'nt set it up)
DB is inventory. table is ica. fields are icaname varchar(15) and icanum varchar(5)
I am connecting to the db and table because i added echos in my conn.php to say so if connected.
Here is input form. upica.php
<html>
<h1> Input file for upload<br>
<form action ="addica.php" method="post" enctype="multipart/form-data">
<td>Copy the most current STAR.DAT file to your desktop. Rename it to STAR.TXT</td>
<td>Browse and select STAR.TXT then click submit. This will overwrite the current information</td>
<td>in the database with the most current. In the future we hope to do this</td>
<td>automatically.</td>
<br>
<tr>
<td><input type = "hidden" name ="MAX_FILE_SIZE" value ="2000000">
<input name ="stardat" type ="file" id="userfile" size = "60"></td>
</tr>
<br>
<tr>
<td align = "center"><input type = "submit" value="submit"></td>
</tr>
</html>
Here is the conn.php. of course i change the info..
$username = "hidden";
$password = "hidden";
$hostname = "localhost";
$db = "inventory";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
$selected = mysql_select_db($db,$dbh)
or die("Could not select first_test");
print "Connected to My Database $db <br>";
?>
Here is the close.php
?php
mysql_close($dbh);
?>
Here is the insert script addica.php. It calls conn.php and close.php to connect and disconnect.
<?php
include('conn.php');
if ((isset($_FILES['stardat']['name']) &&
(dirname($_FILES['stardat']['type']) == 'text') &&
is_uploaded_file($_FILES['stardat']['tmp_name'])&&
($_FILES['stardat']['size']) > 0))
{
$tmpName = $_FILES['stardat']['tmp_name'];
$tmpName = addslashes($tmpName);
$result = "LOAD DATA LOCAL INFILE '$tmpName' REPLACE INTO TABLE ica FIELDS TERMINATED BY ',' ";
$results=mysql_query($result);
}
else
{
echo "Incorrect file name and/or type and/or file blank.";
}
include('close.php');
?>
I get no errors but no data is inserted as well. Not really worried about security at the moment. Just want it to insert. Cannot figure out why it works on one system and not the other. if i use the new version of phpmysqladmin it inserts but not a old version.(error about cannot use this command..blah blah) and I also noticed it does not replace. it adds. but that's another problem. I one day want to grab it from \aserver\where\thefile\ischanged when someone polls. But had problems getting it to even read the file. I think that live server is not setup right. Would welcome cleaner code as well because that's my problem.