mariocesar Posted February 24, 2007 Share Posted February 24, 2007 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. Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted February 24, 2007 Share Posted February 24, 2007 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."')"; Quote Link to comment Share on other sites More sharing options...
mariocesar Posted February 24, 2007 Author Share Posted February 24, 2007 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. Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted February 24, 2007 Share Posted February 24, 2007 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. Quote Link to comment Share on other sites More sharing options...
mariocesar Posted February 25, 2007 Author Share Posted February 25, 2007 Thanks, now they can see the coupon number $result = mysql_query("SELECT * FROM `digicoupons` WHERE `Email`= '$Email'" ) or die(mysql_error()); $row = mysql_fetch_array( $result ); echo " coupon number: ".$row['userID']; Thanks, solved. Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted February 25, 2007 Share Posted February 25, 2007 Glad I could be of assistance Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.