Jump to content

[SOLVED] Send results from one php script to another script


mjgdunne

Recommended Posts

<?php session_start();
$_SESSION['varname'] = "variable contents";?>

 

You have to start the session on every page you want to access the info.

 

I would recommend doing a $varname = $_SESSION['varname'] on the pages you need to access the info.  This makes it easier to use the data.

Link to comment
Share on other sites

Hi, i have the following code:

if (isset($_POST['myq'])) {
    $myq = mysql_real_escape_string($_POST['myq']);
    $result = mysql_query("SELECT * FROM members WHERE Firstname LIKE '%$myq' OR Surname LIKE '%$myq'");

    while ($row = mysql_fetch_assoc($result)) {

echo "<p>You searched for: "" . $myq . ""</p>";

 

So would i put $result in like: $_SESSION['$results']= "results";

 

Link to comment
Share on other sites

Actually, you would do $_SESSSION['results'] = $results;  That will store the query in the session variable.

 

I may have confused on the last part of my message.  When you need to access the info on another page, you do

<?php
// It is a good habit to start the session at the top of the page
session_start();
$results = $_SESSION['results'];

// Process the data
?>

Link to comment
Share on other sites

That will not end the session.  There are only 2 ways to end the session: session_destroy() and some other way I cannot remember.

 

EDIT: The "other way" is session_unset(), which only clears the variables; it does not end the session.

Link to comment
Share on other sites

Thanks, but im getting an error:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\search_emp.php:15) in C:\xampp\htdocs\search_emp.php on line 30

Any idea what it could be?

Link to comment
Share on other sites

Here is my code:

<html>
<head>
<title>Car Rentals & Returns</title>
<meta http-equiv="Content-Type" content="text/html" />
<link href="style2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper3">
<img src="images/cars.jpg" width="996" height="100"></a>

<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
<tr>
<td align="center">
<H1>Search Results:</H1>
<form action="edit_emp.php" method="post">
</td>
</table>

<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=30%>
<tr>
<TD ALIGN=CENTER VALIGN=TOP WIDTH=50>
</TD>
<TD ALIGN=LEFT VALIGN=TOP WIDTH=83%>
<TR><TD>



<?php
session_start();

$_SESSION['$result'] = "variable contents";

ini_set( 'display_errors', '1' );
error_reporting ( 2047 );


$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "root", "root")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$myq=$_POST['myq'];



if (isset($_POST['myq'])) {
    $myq = mysql_real_escape_string($_POST['myq']);
    $result = mysql_query("SELECT * FROM members WHERE Firstname LIKE '%$myq' OR Surname LIKE '%$myq'");

    while ($row = mysql_fetch_assoc($result)) {

echo "<p>You searched for: "" . $myq . ""</p>";


echo "<table border=\"1\" align=\"center\">";

echo "<tr><th>First Name</th>";
	echo "<td>";
	echo $row['Firstname'];
echo "</td>";

echo "<tr><th>Surname</th>";
	echo "<td>";
	echo $row['Surname'];
echo "</td>";

echo "<tr><th>Username</th>";
	echo "<td>";
	echo $row['username'];
echo "</td>";

echo "<tr><th>Password</th>";
	echo "<td>";
	echo $row['password'];
echo "</td>";

echo "<tr><th>Email</th>";
	echo "<td>";
	echo $row['email'];
echo "</td>";

echo "<tr><th>Level</th>";
	echo "<td>";
	echo $row['level'];
echo "</td>";



    }
}

if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}

if (mysql_num_rows($result) == 0) {
    echo "No records found";
    exit;
}



exit();
?>


<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
<tr>
<input type="submit" value="Update Details"/>
</form>
<form method="post" action="login_success3.php">
<td align="center"><input type="submit" value="Home"/></form>
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
</BODY>
</HTML>

 

I am still getting the same error.

Link to comment
Share on other sites

<?php
//Added this session_start()
session_start();
?>
<html>
<head>
<title>Car Rentals & Returns</title>
<meta http-equiv="Content-Type" content="text/html" />
<link href="style2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper3">
<img src="images/cars.jpg" width="996" height="100"></a>

<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
<tr>
<td align="center">
<H1>Search Results:</H1>
<form action="edit_emp.php" method="post">
</td>
</table>

<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=30%>
<tr>
<TD ALIGN=CENTER VALIGN=TOP WIDTH=50>
</TD>
<TD ALIGN=LEFT VALIGN=TOP WIDTH=83%>
<TR><TD>



<?php
// Got rid of this session

// Moved this session declaration

ini_set( 'display_errors', '1' );
error_reporting ( 2047 );


$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "root", "root")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$myq=$_POST['myq'];



if (isset($_POST['myq'])) {
    $myq = mysql_real_escape_string($_POST['myq']);
    $result = mysql_query("SELECT * FROM members WHERE Firstname LIKE '%$myq' OR Surname LIKE '%$myq'");
// There was nothing to declare before
$_SESSION['result'] = $result;


    while ($row = mysql_fetch_assoc($result)) {

echo "<p>You searched for: "" . $myq . ""</p>";


echo "<table border=\"1\" align=\"center\">";

echo "<tr><th>First Name</th>";
	echo "<td>";
	echo $row['Firstname'];
echo "</td>";

echo "<tr><th>Surname</th>";
	echo "<td>";
	echo $row['Surname'];
echo "</td>";

echo "<tr><th>Username</th>";
	echo "<td>";
	echo $row['username'];
echo "</td>";

echo "<tr><th>Password</th>";
	echo "<td>";
	echo $row['password'];
echo "</td>";

echo "<tr><th>Email</th>";
	echo "<td>";
	echo $row['email'];
echo "</td>";

echo "<tr><th>Level</th>";
	echo "<td>";
	echo $row['level'];
echo "</td>";



    }
}

if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}

if (mysql_num_rows($result) == 0) {
    echo "No records found";
    exit;
}



exit();
?>


<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
<tr>
<input type="submit" value="Update Details"/>
</form>
<form method="post" action="login_success3.php">
<td align="center"><input type="submit" value="Home"/></form>
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
</BODY>
</HTML>

 

 

Hope that works.

Link to comment
Share on other sites

Thanks, that got rid of the error, if i use the following displaying the results in input fields will it work:

<?php
session_start();
?>

<html>
<head>
<title>Car Rentals & Returns</title>
<meta http-equiv="Content-Type" content="text/html" />
<link href="style2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper3">
<img src="images/cars.jpg" width="996" height="100"></a>

<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
<tr>
<td align="center">
<H1>Search Results:</H1>
<form action="edit_emp.php" method="post">
</td>
</table>

<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=30%>
<tr>
<TD ALIGN=CENTER VALIGN=TOP WIDTH=50>
</TD>
<TD ALIGN=LEFT VALIGN=TOP WIDTH=83%>
<TR><TD>


<?php

$_SESSION['result'] = "$result";

ini_set( 'display_errors', '1' );
error_reporting ( 2047 );


$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "root", "root")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$myq=$_POST['myq'];


while ($row = mysql_fetch_assoc($result)) {

echo "<p>You searched for: "" . $myq . ""</p>";


echo "<table border=\"1\" align=\"center\">";

echo "<tr><th>First Name</th>";
	echo "<td>";
	echo '<input type="text" name="firstname" value="'. $row['Firstname'] .'" size="20" />';
echo "</td>";

echo "<tr><th>Surname</th>";
	echo "<td>";
	echo '<input type="text" name="surname" value="'. $row['Surname'] .'" size="20" />';
echo "</td>";

echo "<tr><th>Username</th>";
	echo "<td>";
	echo '<input type="text" name="username" value="'. $row['username'] .'" size="20" />';
echo "</td>";

echo "<tr><th>Password</th>";
	echo "<td>";
	echo '<input type="text" name="password" value="'. $row['password'] .'" size="20" />';;
echo "</td>";

echo "<tr><th>Email</th>";
	echo "<td>";
	echo '<input type="text" name="email" value="'. $row['email'] .'" size="20" />';
echo "</td>";

echo "<tr><th>Level</th>";
	echo "<td>";
	echo '<input type="text" name="level" value="'. $row['level'] .'" size="20" />';
echo "</td>";



    }
}





exit();
?>


<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
<tr>
<input type="submit" value="Update Details"/>
</form>
<form method="post" action="login_success3.php">
<td align="center"><input type="submit" value="Home"/></form>
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
</BODY>
</HTML>

Link to comment
Share on other sites

Thanks, i put that in, but two errors, any idea?

Notice: Undefined variable: result in C:\xampp\htdocs\edit_emp.php on line 52

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\edit_emp.php on line 52

 

Link to comment
Share on other sites

I just replaced it, should i leave it in? Here is the code:

<?php
session_start();
?>

<html>
<head>
<title>Car Rentals & Returns</title>
<meta http-equiv="Content-Type" content="text/html" />
<link href="style2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper3">
<img src="images/cars.jpg" width="996" height="100"></a>

<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
<tr>
<td align="center">
<H1>Search Results:</H1>
<form action="edit_emp.php" method="post">
</td>
</table>

<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=30%>
<tr>
<TD ALIGN=CENTER VALIGN=TOP WIDTH=50>
</TD>
<TD ALIGN=LEFT VALIGN=TOP WIDTH=83%>
<TR><TD>


<?php

$_SESSION['result'] = "$result";

ini_set( 'display_errors', '1' );
error_reporting ( 2047 );


$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "root", "root")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");




$row = mysql_fetch_array($result);



echo "<table border=\"1\" align=\"center\">";

echo "<tr><th>First Name</th>";
	echo "<td>";
	echo '<input type="text" name="firstname" value="'. $row['Firstname'] .'" size="20" />';
echo "</td>";

echo "<tr><th>Surname</th>";
	echo "<td>";
	echo '<input type="text" name="surname" value="'. $row['Surname'] .'" size="20" />';
echo "</td>";

echo "<tr><th>Username</th>";
	echo "<td>";
	echo '<input type="text" name="username" value="'. $row['username'] .'" size="20" />';
echo "</td>";

echo "<tr><th>Password</th>";
	echo "<td>";
	echo '<input type="text" name="password" value="'. $row['password'] .'" size="20" />';;
echo "</td>";

echo "<tr><th>Email</th>";
	echo "<td>";
	echo '<input type="text" name="email" value="'. $row['email'] .'" size="20" />';
echo "</td>";

echo "<tr><th>Level</th>";
	echo "<td>";
	echo '<input type="text" name="level" value="'. $row['level'] .'" size="20" />';
echo "</td>";



exit();
?>


<TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
<tr>
<input type="submit" value="Update Details"/>
</form>
<form method="post" action="login_success3.php">
<td align="center"><input type="submit" value="Home"/></form>
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
</BODY>
</HTML>

Link to comment
Share on other sites

I used

if (isset($_POST['myq'])) {
    $myq = mysql_real_escape_string($_POST['myq']);
    $result = mysql_query("SELECT * FROM members WHERE Firstname LIKE '%$myq' OR Surname LIKE '%$myq'");

 

This is the edit results page, i need to get the results from results, do i still need a query?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.