actually, i'm a newbie in php...i'd like to ask you guys.....how to display back all the data from the database for these coding....here's the coding....

($_POST ['action'] == 'pointofcontact'){
	
	$projectid = $_POST['projectid']; 
	
	
	$poc = '';

		//echo "Pastikan pilihan anda betul!!<br><br>";
		for ($i=1; $i <= 3; $i++){
		
			$poc = 'poc' . $i;
			
			$poc2 = $_POST[$poc];
			
			if (!empty($poc2)){
			$query = "insert into projectcontact set resourcesid = '$poc2', projectid = '$projectid'";
	
			$result = mysql_query($query);
			$projectid = $_POST['projectid'];
			}
			//echo $poc2."<br>";
			
		}
	
	if ($result){
		
		header ('Location: createproject.php?action=projectmanager&projectid='. $projectid);
		
		
		
	}


and number 2 is this :-

else if ($_POST ['action'] == 'uploaddownload'){

$projectid = $_POST['projectid']; 
$docname = $_POST['docname'];

$remarks =  $_POST ['remarks'];



$query = "insert into user_upload set docname= '$docname' ,  remarks = '$remarks' '";

$result = mysql_query ($query);


if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; // $_FILES["file"]["error"] - the error code resulting from the file upload
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />"; // $_FILES["file"]["name"] - the name of the uploaded file
    echo "Type: " . $_FILES["file"]["type"] . "<br />"; // $_FILES["file"]["type"] - the type of the uploaded file
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";//$_FILES["file"]["size"] - the size in bytes of the uploaded file
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";// $_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server
    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }

}

i wantto display these two element....thanks in advance.....

Dani AI

Generated

For : the simplest, reliable flow is (1) make sure each successful insert stores the right columns (include projectid on file rows), (2) verify inserts by checking the database error/return value, then (3) run a SELECT for the same projectid and loop the result set to print HTML. As hinted, listing rows from the DB is the way to show what was saved — use a modern API and prepared statements rather than the deprecated mysql_* calls.

Common problems visible in the posted code

  • A syntax error in the user_upload INSERT will stop the row being saved (an extra quote is present).
  • projectid is not being inserted into user_upload, so later SELECTs may not match.
  • Only the last loop result is checked before redirect; individual insert failures can be missed.
  • File moves can silently fail if permissions are wrong or move_uploaded_file returns false.
    Fixes: check and log DB errors (or catch exceptions), confirm move_uploaded_file returned true, and avoid redirecting until inserts are validated.

Minimal example (secure pattern) for fetching and displaying both tables with PDO:

$pdo = new PDO('mysql:host=localhost;dbname=DBNAME', 'user', 'pass', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$stmt = $pdo->prepare(
  'SELECT pc.resourcesid, u.docname, u.remarks, u.filename
   FROM projectcontact pc
   LEFT JOIN user_upload u ON u.projectid = pc.projectid
   WHERE pc.projectid = ?'
);
$stmt->execute([$projectid]);
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
  echo '<tr>';
  echo '<td>' . htmlspecialchars($row['resourcesid']) . '</td>';
  echo '<td>' . htmlspecialchars($row['docname']) . '</td>';
  echo '<td>' . htmlspecialchars($row['remarks']) . '</td>';
  if (!empty($row['filename'])) {
    echo '<td><a href="/upload/' . rawurlencode($row['filename']) . '">download</a></td>';
  }
  echo '</tr>';
}

Troubleshooting checklist: enable DB error reporting, run the failing INSERT manually in a client to see the error, check the upload folder permissions, sanitize and uniquify filenames, and prefer server-side MIME checks (finfo) rather than trusting client-sent types.

Hi Asyieen,
I'm afraid the reason why nobody has answered so far is that it's not very clear what you actually want.

You posted a script that inserts records into projectcontact and user_upload.
And you say you want to display "these two elements". Word "element" is usually used for referencing a tag in a HTML document, while with databases we speak about tables, their records / rows and their attributes.

So what do you need? To list all records in a database table? Have a look at documentation for mysql_fetch_assoc() there's an example that does just that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.