Connecting Tech Pros Worldwide Forums | Help | Site Map

sql insert question

Mikey P
Guest
 
Posts: n/a
#1: Jul 17 '05
hi all thanks again for all th direction you guys have given me..

i have a partial backend done for uploading graphics to a directory
and information into mysql. Now what i'm having problems with is
getting the file path with the file name to upload to the sql
database.

Right now i have 2 unique qualifiers carrying over (jobnum, custID).
I'm querying the database to find those matching qualifier and i need
to fill in the file name into the directorytile field in the db. here
is what i have now (excuse the sloppy code i'm a newbie!):


<?php


mysql_connect ('localhost', 'acme', 'acme') ;
mysql_select_db ('olcg');
$query = mysql_query("SELECT directorytile FROM itl WHERE
jobnum='$jobnum' AND custID='$custID'") or die (mysql_error());

if (isset($_POST['submit'])) {
$sql = "INSERT INTO itl SET
directorytile='$file_name'";
}
?>

<?php



if($file_name !="")
{
copy ("$file", "/home/guestdir/www/olcg/$file_name")
or die("Could not copy file");
}
else { die("No file specified"); }

?>


again thanks so much!!!!!

Tim Roberts
Guest
 
Posts: n/a
#2: Jul 17 '05

re: sql insert question


phatnugs420@comcast.net (Mikey P) wrote:[color=blue]
>
>hi all thanks again for all th direction you guys have given me..
>
>i have a partial backend done for uploading graphics to a directory
>and information into mysql. Now what i'm having problems with is
>getting the file path with the file name to upload to the sql
>database.
>
>Right now i have 2 unique qualifiers carrying over (jobnum, custID).
>I'm querying the database to find those matching qualifier and i need
>to fill in the file name into the directorytile field in the db. here
>is what i have now (excuse the sloppy code i'm a newbie!):
>...
>mysql_select_db ('olcg');
>$query = mysql_query("SELECT directorytile FROM itl WHERE
>jobnum='$jobnum' AND custID='$custID'") or die (mysql_error());
>
>if (isset($_POST['submit'])) {
> $sql = "INSERT INTO itl SET
> directorytile='$file_name'";
> }[/color]

INSERT is only used to add an entirely new record. To update the fields in
an existing record, you use UPDATE. Further, an SQL connection has no
concept of a "current record", so you have to tell it exactly which
record(s) to update. Hence:

$sql = "UPDATE itl SET directorytile='$file_name' " .
"WHERE jobnum='$jobnum' AND custID='$custID';";
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Closed Thread


Similar PHP bytes