I created a Javascript application that creates a moving quote.(http://economymoving.net/get_an_online_moving_quote.php)
The quote page should insert a record in the db, display the record on a new page called viewquote.php and send an alert email to the company. Currently, the phpmyadmin database receives the record but viewquote.php doesn't display the correct quote. It shows the same wrong quote each time. For now, the email is generated when viewquote.php loads but it would be better to send the email from the quote page.

I am working with Dreamweaver CS5 and phpMyAdmin 5.1

I'm pretty sure this is the section of code that's causing the issue.

:: quote page ::

mysql_select_db($database_writeQuote, $writeQuote);
  $Result1 = mysql_query($insertSQL, $writeQuote) or die(mysql_error());
  
    $insertGoTo = "viewquote.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));

I sure would appreciate your help. While searching for an answer I noticed there are some very talented folks on this website!

If the insert works, then the problem is most likely with the retrieval of the latest record. Check that code instead.

This is the code from the viewquote page that should display the last quote.

mysql_select_db($database_getQuote, $getQuote);
$query_lastQuote = "SELECT * FROM quotes";
$lastQuote = mysql_query($query_lastQuote, $getQuote) or die(mysql_error());
$row_lastQuote = mysql_fetch_assoc($lastQuote);
$totalRows_lastQuote = mysql_num_rows($lastQuote);

You need to loop through the fetching records when you are having more than one record from your table, or if you want the quote value of last inserted record, then you can use order by and limit to get the last inserted quote value.

$query_lastQuote = "SELECT * FROM quotes order by auto_id desc limit 0,1";

I am assuming that you are having the auto increment column as auto_id.

Yes it should display the last record inserted.

Thanks Paulrajj, you now have the title of PHP Hero in my book!

One last question, when the viewquote page loads, it sends a notifocation email to the company. Is that an acceptable practice? If not can you give me a recommendation and demonstrate a little more of your PHP Heroism?

Thanks again!

Ya. Its acceptable and it depends upon your requirement. The thing is if you want to send the notification email whenever you view the page then its an acceptable one. Otherwise you need to have some conditions based on only the notification mail will be send at the first time of the page is loading.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.