Jump to content

query question


mariocesar

Recommended Posts

This is a small form and the script grabs the info and insert it into a dbase, in the dbase is an auto icrement field that I want to show together with the message that goes back to the user when they submit the form, here is the script:

 

<? 

$Name=$_POST['Name']; 
$Company=$_POST['Company']; 
$Email=$_POST['Email']; 
   if($Email){

        } 

        else{ 

            $error.="";
            } 


    if($error==""){ 

        echo "Thank you! Now You can print the coupon and send it with your order."; 
        

$connection=mysql_connect('localhost', $user = "mario", $pass = "mario") or die("Unable to connect!"); /* change this! */ 



mysql_select_db("freesamples") or die("Unable to select database!");

$query="INSERT INTO digicoupons ( Name, Company, Email) 

        VALUES( '".$Name."', '".$Company."', '".$Email."')"; 

//////-----> 

$result=mysql_query($query) or die("Error in query:".mysql_error()); 

mysql_close($connection); 
        } 

    else{ 
            print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - <br>\n"; 
            print "$error<br>\n"; 
            print "<br>\n"; 
            print "<br>\n"; 
            print "Please use your \"Back\" button to return to the form to correct the omissions.  Thank you.<br>\n"; 

        } 

?>

 

Thanks.

Link to comment
Share on other sites

First of all, change this:

$connection=mysql_connect('localhost', $user = "mario", $pass = "mario") or die("Unable to connect!"); /* change this! */ 

 

to:

$connection=mysql_connect('localhost', 'mario', 'mario') or die("Unable to connect!"); /* change this! */ 

 

When you say there is an auto_increment field, what is the name of this field?

 

Do this for your query:

 

$query="INSERT INTO digicoupons (field_that_auto_increments, Name, Company, Email) 

        VALUES( '','".$Name."', '".$Company."', '".$Email."')"; 

 

 

 

 

Link to comment
Share on other sites

the name of the field is couponID, I want this record to show next to the message "Thank you! Now You can print the coupon and send it with your order." the script is working I just want to pull the couponID field and echo it to the user here is the table:

CREATE TABLE `digicoupons` (
  `timeStamp` timestamp(14) NOT NULL,
  `couponID` mediumint( NOT NULL auto_increment,
  `Name` varchar(50) binary NOT NULL default '',
  `Company` varchar(50) binary default NULL,
  `Email` varchar(100) binary NOT NULL default '',
  PRIMARY KEY  (`userID`),
  UNIQUE KEY `couponID` (`couponID`,`name`)
) TYPE=MyISAM AUTO_INCREMENT=1002 ;

 

thanks.

Link to comment
Share on other sites

If i gather correctly, you want to create a new entry in your database, which will create a new couponID for itself, and then you want that new couponID to be printed out?

 

If so, before you close your connection to the database, do another query after the inter query to select the couponID from the database where the emai and such = the one's on the page at the time.

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.