...

View Full Version : PHP FORM SUBMIT with User ID into Database



jonny1990
01-27-2012, 01:58 PM
Hi guys, need a little help in regards to submitting my form and the id of the user currently logged in needs to display in the FK id of my second table:

Here is my current code:

form page:




<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form enctype="multipart/form-data" id="form1" name="form1" method="post" action="secondPic.php">
<p>
<label for="name1">Fav Location Name: </label>
<input type="text" name="name1" id="name1" />
</p>
<p>
<label for="photo1">Fav Location Photo: </label>
<input type="file" name="photo1"><br>
</p>
<p>
<label for="id">ID: <? echo $rows['id']; ?> </label>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" />
</p>
</form>



</body>
</html>


uploader page



<?php
include "common.php";
$secondid = $_GET['id'];
DBConnect();



$Link = mysql_connect($Host, $User, $Password);

//This is the directory where images will be saved
$target = "second/";
$target = $target . basename( $_FILES['photo1']['name']);


$favname = $_POST["name1"];
$pic2=($_FILES['photo1']['name']);
$id = $_POST["$id"];



$Query ="INSERT into $Table_2 values ('0', '$id', '$favname', '$pic2')";

if (mysql_db_query ($DBName, $Query, $Link)){
print ("A record was created <br><a href=index.php> return to index </a>\n");

// Connects to your Database
//mysql_connect("localhost", "jonathon_admin", "hello123") or die(mysql_error()) ;
//mysql_select_db("jonathon_admin1") or die(mysql_error()) ;


//Writes the photo to the server
if(move_uploaded_file($_FILES['photo1']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}


} else {

print (" - Your Record was not created");
}

mysql_close($Link);
?>

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

Spookster
01-27-2012, 07:08 PM
Did you have a question?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum