Page 1 of 1

view data just entereed into the database.

Posted: Tue Jan 20, 2009 9:41 pm
by kalp1200
Hi

How do I view the data I just entered into the database, i do not want to view all the records, just the records that I JUST ENTERED

For example, I have this adddatahtml.php page, where I field up the textboxes and enter, the id - is an autoincremented value, once entered, the page should display that the data(adddata.php) has been entered ( I have done this ), the following is my php codes, I want the viewdesktopinline.php page to display that the following data has been entered

<?
$desktop_model=$_POST['desktop_model'];
$desktop_manufacturer=$_POST['desktop_manufacturer'];
$desktop_casing=$_POST['desktop_casing'];

$URL="/testing/viewdesktopinline.php";

include ('connect.php');

$sql="INSERT INTO record_db_desktopmodel(desktop_model,desktop_manufacturer,desktop_casing,processorVALUES('$desktop_model','$desktop_manufacturer','$desktop_casing')";

if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
else
header ("Location: $URL");

?>

Re: view data just entereed into the database.

Posted: Tue Jan 20, 2009 10:07 pm
by susrisha
kalp1200 wrote:

Code: Select all

 
 
$desktop_model=$_POST['desktop_model']; 
$desktop_manufacturer=$_POST['desktop_manufacturer']; 
$desktop_casing=$_POST['desktop_casing']; 
 
$URL="/testing/viewdesktopinline.php";
 
include ('connect.php');
 
$sql="INSERT INTO record_db_desktopmodel(desktop_model,desktop_manufacturer,desktop_casing,processorVALUES('$desktop_model','$desktop_manufacturer','$desktop_casing')";
 
if (!mysql_query($sql))
  {
    die('Error: ' . mysql_error());
  }
else
    header ("Location: $URL");
 
Well in this code you can get the unique incremented id of the latest inserted data. probably you can send the id as a GET variable to your viewdesktopinline.php as

Code: Select all

viewdesktopinline.php?id=$id
and do a mysql query at the other page to get all the details.

I am writing a sample code here which you might want to use.

Code: Select all

 
//put this after the insert query
$id = mysql_insertid($sql_connection);
$URL = "viewdesktopinline.php?id = $id";
 
Access the same in viewdesktopinline.php

Code: Select all

 
//code in viewdesktopinline.php
 
$id =$_GET['id'];
$query = "SELECT * from yourtable WHERE id = $id";
$result = mysql_query($query);
 
 

Re: view data just entereed into the database.

Posted: Tue Jan 20, 2009 11:33 pm
by josh
If you just inserted them you shouldn't need to query against them, in the rare chance this is actually what you need you could store a token to partition your records. By the way its mysql_insert_id() but that only gets the last row. Thing is you shouldnt need any rows, you already have them because you just inserted them

Re: view data just entereed into the database.

Posted: Wed Jan 21, 2009 1:41 am
by kalp1200
hi, thanks for the reply, but I just cant get it to work, I have done the following ..

adddesktop.php

<?
$desktop_model=$_POST['desktop_model'];
$desktop_manufacturer=$_POST['desktop_manufacturer'];
$desktop_casing=$_POST['desktop_casing'];

include ('connect.php');


$sql="INSERT INTO record_db_desktopmodel(desktop_model,desktop_manufacturer,desktop_casing,)VALUES('$desktop_model','$desktop_manufacturer','$desktop_casing',')";

$id = mysql_insertid($sql);
$URL= "viewdesktopinline.php?id = $id";

if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
else
header ("Location: $URL");

?>


viewdesktopinline.php

<td bordercolor="#CCFF33" colspan="2" style="height: 36px">
<font face="Verdana" style="font-size: 8pt">You have entered the following</font></td>
</tr>
<?php
include ('connect.php');
//$id =$_GET['id'];
$query = "SELECT * from record_db_desktopmodel WHERE id = $id";
$id =$_GET['id'];
$result = mysql_query($query);
?>
<tr>
<td colspan="2" height="213" class="style34">

<table cellpadding="0" cellspacing="0" style="width: 555px; height: 827px;">
<form method="POST" name="add_desktop" action="php/admin_adddesktop.php" onSubmit="return checkform(this);">

<tr>
<td class="style19" colspan="5" height="40">
<strong>Desktop Primary Details</strong></td>
</tr>
<tr>
<td valign="middle" align="right" style="width: 142px; height: 18px;">
<p class="style16">Desktop Model</td>
<td valign="middle" align="center" class="style25" style="height: 18px; width: 20px;">:</td>
<td colspan="3" style="height: 18px" class="style50">
<?php echo $_REQUEST['desktop_manufacturer']; ?> <?php echo $_REQUEST['desktop_model']; ?>; <?php echo $_REQUEST['desktop_casing']; ?></td>
</tr>


I think my php echo _request has to be done differently

but anyway, I am getting this error

Fatal error: Call to undefined function: mysql_insertid() in C:\Program Files\Apache Group\Apache2\htdocs\testing\php\admin_adddesktop.php on line 89

Re: view data just entereed into the database.

Posted: Wed Jan 21, 2009 3:23 am
by josh
Obviously you completely ignored me

Re: view data just entereed into the database.

Posted: Wed Jan 21, 2009 3:46 am
by susrisha

Code: Select all

 
$id = mysql_insertid($sql);//this line to be replaced with 
$id = mysql_insert_id($sql);
//this line in viewdesktopinline.php to be changed
$query = "SELECT * from record_db_desktopmodel WHERE id = $id";
        $id =$_GET['id'];
//put $id=$_GET['id']; before the query not after the query.
 
 
And jshpro what you said was right. He already has the variables and their values with him. Could have sent them through session. that would have been a better solution.

Re: view data just entereed into the database.

Posted: Wed Jan 21, 2009 4:06 am
by panic!
mysql_insert_id() not mysql_insertid()

Re: view data just entereed into the database.

Posted: Wed Jan 21, 2009 7:22 pm
by kalp1200
Hi guys, thanks alot, but I am getting this error now

Error: Failed to read auto-increment value from storage engine

My table has an autoincrement primary key field