How can i get id in php?

I'm trying get id of a user when click,But right now my code is given error I have done this in my other file it work fine with my code I'm trying to use this code but is not working please some should fix my code

request.php


user.php

This will ensure upon clicking , it will trigger to run the back-end query.

answered Jun 20, 2017 at 9:48

FreedomPrideFreedomPride

1,0647 silver badges29 bronze badges

0

Your form use the POST method and you're trying to access the $_GET variable. You should do:

if[isset[$_POST['id']]]{
    $id = $_POST['id'];

answered Jun 20, 2017 at 9:47

You can either put ?id= inside the action attribute of your form tag or do what Gwaldhorf Miopau told in his/her answer, but keep in mind that you have to give the a element inside your form tag a name attribute with the value "id".

answered Jun 20, 2017 at 9:57

TripleDealTripleDeal

6864 silver badges14 bronze badges

  1. $id = intval[$_GET['id']];

  2. Use prepare statement

    $db = $pdo->prepare[' SELECT COUNT[*] FROM `alert_users_account` WHERE `id`=:id  '];
    $db->bindParam[':id', $id];
    $db->execute[];
    $Users = $db->fetchAll[];
    
  3. Use try/catch to see errors

    try {
    $db->execute[]; } catch [PDOException $e] {
    echo '
    ';
      print_r[$e->getMessage[]];
      $db->debugDumpParams[];
    echo "
    "; }

Aurasphere

3,68112 gold badges42 silver badges69 bronze badges

answered Jun 20, 2017 at 11:15

gomazafakagomazafaka

711 silver badge5 bronze badges

In this tutorial you will learn how to pass information from one page to another page in php? Or how to get id from one page to another page? in very easy way. Here I will explain each and everything in step by step learning method so that you can understand this tutorial very easily.

Here I am taking image tutorial example to understand the concept, mean how we can get information from first page to second page? We will show multiple images in first page and when we click on any particular image that will open on second page.

Important Note: For images in database we are using how to upload image in database using PHP MySQL? tutorial. If you don't have images in database then insert some images in database using this tutorial.

What we are doing in this tutorial?

  • Creating two pages[index.php and display.php].
  • Creating multiple show images design page index.php.
  • Creating a variable for $_GET method in index.php.
  • Creating show image design page display.php.
  • Creating a variable to store the $_GET method value in display.php page.

Note: - We will use PHP $_GET method to access the information from one page to another page. $_GET method we use in second page to get id from first page.

PHP $_GET Method

$_GET method is a PHP super global method. Which is use to parse the browser URL and scan & retrieve the given parameter or information by id.

Step 1.

First create an index.php page where we will display multiple images from database. So now copy the below complete PHP code and paste it in index.php page.

Design your show image page like below.

Copy the below complete code and paste it in index.php page.

	
	
	
	
	
	
	Show Image in PHP - Campuslife
	
		body{background-color: #f2f2f2; color: #333;}
		.main{box-shadow: 0 .125rem .25rem rgba[0,0,0,.075]!important; margin-top: 10px;}
		h3{background-color: #4294D1; color: #f7f7f7; padding: 15px; border-radius: 4px; box-shadow: 0 1px 6px rgba[57,73,76,0.35];}
		.img-box{margin-top: 20px;}
		.img-block{float: left; margin-right: 5px; text-align: center;}
		p{margin-top: 0;}
		img{width: 375px; min-height: 250px; margin-bottom: 10px; box-shadow: 0 .125rem .25rem rgba[0,0,0,.075]!important; border:6px solid #f7f7f7;}
	
	

	
		
		

Showing Images from database

How do I find the URL ID?

To Get the ID from URL with JavaScript, we can call the JavaScript string's split method on the URL string. Then we get the last part of it with the JavaScript array at method. We call split with '/' to split the url string by the / . Then we call at with -1 to get the element from the strs array.

How can I get ID from one page to another in PHP?

$id = $_GET["myid"]; If you look at above code you will get idea how we are accessing the first page variable to second page through $_GET variable method to share the information from one page to another page and storing them in $id variable that we have created.

How can I get ID from one table to another in mysql?

$get_teacher = mysqli_query[$link, "SELECT id FROM teachers WHERE first_name = '$teacher_first_name' AND last_name = '$teacher_last_name'"]; $get_teacher_arr = mysqli_fetch_array[$get_teacher]; $result = mysqli_query[$link, "INSERT INTO students [student_id, first_name, last_name, teacher_id] VALUES ['$student_id', '$ ...

Chủ Đề