0

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!

3
Contributors
6
Replies
9
Views
5 Years
Discussion Span
Last Post by paulrajj
0

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

0

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);
1

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.

0

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!

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.