Php / mysql:无法使用session。价值没有得到储存 [英] Php/mysql : unable to work with session. Value isn't getting stored

查看:74
本文介绍了Php / mysql:无法使用session。价值没有得到储存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图创建两个页面,一个传递值,另一个传递它,并根据条件设置查询。因此,在第一页中,用户从中选择一个ID号,然后单击提交。然后在第二页上。表格将显示该特定ID但是,每当我到达第2页时,我收到以下错误(第2页):



>通知:未定义索引:R_ID



我尝试过:



这里是我的第一页的代码: -



So I am trying to create two pages, one that passes the value and other that receives it and sets the query out based on the condition. So in the first page, the user selects an ID number from the and then clicks on submit.. Then on the second page. the tables are to be shown of that particular ID however, Whenever I get to the 2nd page, I receive the following error (for page 2):

>Notice: Undefined index: R_ID

What I have tried:

Here is the code for my first page:-

<?php
    SESSION_START();
      if (isset($_POST['submit'])) {
    	$No=$_POST['No'];
    	$con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("garden", $con);
    	    $_SESSION['R_ID']=$No;
      }
      
      //$result = mysqli_query($db, "SELECT * FROM recipe_img WHERE RecipeID='$var_value'");
    ?>
    <html>
    <head>
    </head>
    <body>
    <div id="content">
    <p></p>
    <p> select by ID: </p>
    <select name="No" id="No">
    	<option value="No"></option>
    		<?php
    mysql_connect('localhost', 'root', '');
    mysql_select_db('garden');
    
    $sql = "SELECT R_ID FROM recipe";
    $result = mysql_query($sql);
    while ($row = mysql_fetch_array($result)) {
    	$name=$row['R_ID'];
        echo "<option value='".$row['R_ID'] ."'>". $row['R_ID'] ."</option>";
    }
    ?>
    </select>
    <div>
    <input type="submit" name="submit" value="submitting">
    </div>
    </div>
    </body>
    </html>





,这是第二页:



and here's the second page:

<?php
            session_start();
            $db_host = 'localhost'; 
            $db_user = 'root'; 
            $db_pass = ''; 
            $db_name = 'garden'; 
            $con = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
            if (!$con) {
            	die ('Failed to connect to MySQL: ' . mysqli_connect_error());	
            }
            $RID=$_SESSION['R_ID'];
            $Qsql = "SELECT * FROM recipe WHERE recipe.R_ID='$RID'";
            $query = mysqli_query($con, $Qsql);
            if (!$query) {
            	die ('SQL Error: ' . mysqli_error($con));
            }
            ?>
     <html>    
        <body>
            	<h1>Table</h1>
            	<table class="data-table">
            			<tr>
            				<th>Name</th>
            				<th>Cost</th>
            				<th>Step</th>
            			</tr>
            		</table>
            		<?php
            		while ($row = mysqli_fetch_array($query))
            		{
            			echo '<tr>
            					<td>'.$row['Name'].'</td>
            					<td>'.$row['Cost'].'</td>
            					<td>'.$row['Step'].'</td>
            				</tr>';
            		}?>
    
            	</table>
            </body>
            </html>

推荐答案

_POST [' submit'])){
_POST['submit'])) {


否=


_POST [' No' ]。
_POST['No'];


这篇关于Php / mysql:无法使用session。价值没有得到储存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆