Jump to content

Quick php and mysql question


lucas20042004

Recommended Posts

I have managed to make a form in frontpage that has two textboxes. One for the persons email address and one for comments. When the info is typed and submitted it stores on my database in two fields in a table.

 

My question is how do I make another form on a different page so when they put their email address in a textbox and submit it, it will display their comments on the page that they put in previously on the 1st page.

 

This is a kind of test thing as I just want to get used to it. As you can see im trying to make a kind of order tracking page.

 

Hope you understand thanks  ;D

Link to comment
https://forums.phpfreaks.com/topic/151143-quick-php-and-mysql-question/
Share on other sites

Ive never heard of anyone using frontpage and php but...

 

I assume the database would be mySQL

 

Two functions to look at for this:

 

mysql_query

<----used to set a select statement to pull comments where emailAddress equals what is entered in

and

mysql_fetch_array

<----used to get access to the information returned from the database (if a match is found)

I used a program called forms2go. It can insert things into database but cannot retrive info so I dont know how to do it.

 

As you can see for the purpose of the question my table is called "track" and the two fields are called "email" and "description".

 

 

<?PHP
######################################################
#                                                    #
#                Forms To Go 4.2.0                   #
#             http://www.bebosoft.com/               #
#                                                    #
######################################################







error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);

function DoStripSlashes($fieldValue)  { 
if ( get_magic_quotes_gpc() ) { 
  if (is_array($fieldValue) ) { 
   return array_map('DoStripSlashes', $fieldValue); 
  } else { 
   return stripslashes($fieldValue); 
  } 
} else { 
  return $fieldValue; 
} 
}

function FilterCChars($theString) {
return preg_replace('/[\x00-\x1F]/', '', $theString);
}


if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}

$FTGEmail = DoStripSlashes( $_POST['Email'] );
$FTGDescription = DoStripSlashes( $_POST['Description'] );



$validationFailed = false;


# Include message in error page and dump it to the browser

if ($validationFailed === true) {

$errorPage = '<html><head><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>';

$errorPage = str_replace('<!--FIELDVALUE:Email-->', $FTGEmail, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:Description-->', $FTGDescription, $errorPage);


$errorList = @implode("<br />\n", $FTGErrorMessage);
$errorPage = str_replace('<!--VALIDATIONERROR-->', $errorList, $errorPage);

echo $errorPage;

}

if ( $validationFailed === false ) {

    #====================================================
# Dump field values to a MySQL table                =
#====================================================

$mysqlLink = @mysql_connect("localhost", "username", "password");


if (mysql_errno() == 0) {

@mysql_select_db("database", $mysqlLink);


}

if (mysql_errno() == 0) {

$sqlCmd = sprintf("INSERT INTO `track`(`email`, `description`) VALUES('%s', '%s')",
                   mysql_real_escape_string($FTGEmail, $mysqlLink),
                   mysql_real_escape_string($FTGDescription, $mysqlLink));

@mysql_query($sqlCmd, $mysqlLink);


}

# Redirect user to success page

header("Location: http://www.xxxxx.com");

}

?>

You need something along these lines:

 

<?php

// Get submitted email
$email = $_POST['email'];

// Build query
$query = sprintf("SELECT `comment` FROM `comments` WHERE `email` = '%s'", mysql_real_escape_string($email));

// Execute query
$result = mysql_query($query);

// Check result
if (!$result) die('Invalid query: ' . mysql_error());

// Process result
while ($row = mysql_fetch_assoc($result)) 
{
echo $row['comment'];
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.