Jump to content

How to run instert, and select in 1 block


jjmusicpro

Recommended Posts

Hi everyone!

 

I was trying to run 2 querys in the same block.

 

I wanted enter the zipcode they entered into a database for future analytics later, as well as spit out the results of the search.

 

I already have the search results part working, but i cant seem to get the insert to work correctly.

 

my table for keeping records of the zipcodes searched is:

 

search_id (auto incrment)

zipcode

time_date

 

Thanks for the help everyone!

 

PHPFreaks ROCKS!!!!!!!!

 

  if($_SERVER['REQUEST_METHOD'] == "POST"){ 
   require_once ('connect.php'); 
  require_once ('opendb.php'); 
  
  $zipcode = $_POST['zipcode_entered_search'];<br>
     
    $query = "INSERT INTO searched_zips VALUES ('','$zipcode','','')"; 
    $result = mysql_query($query); 

  $query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode'"; 
  $result = @mysql_query ($query); 
  $count = mysql_num_rows($result); //number of results 

Link to comment
Share on other sites

<?php

  if (isset($_POST['zipcode_entered_search']))){ 
    require_once 'connect.php'; 
    require_once 'opendb.php'; 
    $zipcode = mysql_real_escape_string($_POST['zipcode_entered_search']);
     
    $query = "INSERT INTO searched_zips VALUES ('','$zipcode','','')"; 
    if ($result = mysql_query($query)) { 
      $query = "SELECT * FROM zipcodes WHERE zipcode=" mysql_insertid(); 
      if ($result = mysql_query($query)) {
        $count = mysql_num_rows($result);
      }
    }
  }

?>

Link to comment
Share on other sites

How do i get the date in there?

 

$query = "INSERT INTO searched_zips (zipcode,time_date) VALUES ('$zipcode', NOW())";

 

Also, is there a way to get any more info from the user? when they land on my page? like what keyword was used to get to my site?

 

There is other various info available within the $_SERVER array, but no way of getting any so called keyword unless it is forwarded by the user.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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