tags:

views:

38

answers:

2

Hello,

I have a page called guestbook.php in which contains

 $('#guest_form').ajaxForm({});

When the form is triggered it goes to a save.php page which contains and values inserted

if($_POST['x']){

$xx = $_POST['x'];
$yy = $_POST['y'];
$zz = $_POST['z'];


$query_one = "INSERT INTO xxx (x1,yl,z1,z2) values ('$xx','$yy','$zz','00000')";
mysql_select_db($database_1, $1);
$Result = mysql_query($query_guest_one, $1) or die(mysql_error());

So far so good.

Now I run a select query based on the insert and display it in a div on the guestbook.php page. That is where I cannot do it.

All help appreciated.

Thanks Jean

A: 

Assuming you have a primary key after the INSERT query you can do something like:

$id = mysql_insert_id();
$query = mysql_query("SELECT * FROM guestbook WHERE id = $id");
$row = mysql_fetch_array($query);

echo $row['x1'];
echo $row['y1'];

// etc
fire
yup, now how I want to display echo $row['x1'];echo $row['y1'];in the guestbook.php
Jean
A: 

You can select all records in the table using

$result=mysql_query("SELECT * FROM xxx");
while ($record=mysql_fetch_array($result)) {
    // using your example, access the data you need
    print_r($record["x1"]);
    print_r($record["y1"]);
    // and so on..
}

You can filter the records requesting a column with a particular value

$result=mysql_query(sprintf(
    "SELECT * FROM xxx WHERE x1 = '%s' ",
    mysql_real_escape_string("some value")
));

Please remember to sanitize your values with mysql_real_escape_string before inserting or searching if they come from user input.

These are the most basic queries. I suggest you to find a tutorial about SQL, google is your friend and you'll learn many non obvious things

Riccardo Galli
if x1 and y1 is the first name and last name respectively then how do I place it the respective fields on the guestbook.php?
Jean