demented_gurl Posted April 3, 2009 Share Posted April 3, 2009 Hye. I'm new to PHP and I don't know much about the language. I have a form where guests are required to enter their company details (Co name, address, telephone number, etc). and these info will be stored in MySQL database, and the database will generate a unique CoID (using auto-increment in MySQL). My question is, how do I display back the generated CoID to the guest?.. I've tried using session and passing through url, but the CoID won't display because the value of the CoID is not entered in the form. NEED HELP. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/152391-need-help-with-passing-value-from-one-form-to-another-page/ Share on other sites More sharing options...
ober Posted April 3, 2009 Share Posted April 3, 2009 You will need to query the database for the ID. That's not done by passing the value from page to page. The only reason you need to pass a value from page to page here is to determine what record to get the ID from. Quote Link to comment https://forums.phpfreaks.com/topic/152391-need-help-with-passing-value-from-one-form-to-another-page/#findComment-800314 Share on other sites More sharing options...
JeanieTallis Posted April 3, 2009 Share Posted April 3, 2009 You'll need to pass the data as a query to the database, and then retreive the details onto the other page. Quote Link to comment https://forums.phpfreaks.com/topic/152391-need-help-with-passing-value-from-one-form-to-another-page/#findComment-800320 Share on other sites More sharing options...
demented_gurl Posted April 3, 2009 Author Share Posted April 3, 2009 You'll need to pass the data as a query to the database, and then retreive the details onto the other page. thanks..can i pls know how to do that?..I'm sorry..am new to this.. Quote Link to comment https://forums.phpfreaks.com/topic/152391-need-help-with-passing-value-from-one-form-to-another-page/#findComment-800326 Share on other sites More sharing options...
MasterACE14 Posted April 3, 2009 Share Posted April 3, 2009 what is your current code? Quote Link to comment https://forums.phpfreaks.com/topic/152391-need-help-with-passing-value-from-one-form-to-another-page/#findComment-800345 Share on other sites More sharing options...
darkfreaks Posted April 3, 2009 Share Posted April 3, 2009 is there an ID field ??? if so you can do something like <?php /* Create a new mysqli object with database connection parameters */ $mysqli = new mysqli('localhost', 'user','pass','database'); if(mysqli_connect_errno()) { echo "Connection Failed: " . mysqli_connect_errno(); exit(); } $id=$_GET['coid']; $stmt ->$mysqli ->prepare("SELECT*FROM table WHERE id=?"); $stmt ->bind_param('s',$id); if($stmt ->execute()){ while($row=$stmt ->fetch()){print_r($row);} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152391-need-help-with-passing-value-from-one-form-to-another-page/#findComment-800352 Share on other sites More sharing options...
darkfreaks Posted April 3, 2009 Share Posted April 3, 2009 actually i messed up you would pass $id as an integer <?php /* Create a new mysqli object with database connection parameters */ $mysqli = new mysqli('localhost', 'user','pass','database'); if(mysqli_connect_errno()) { echo "Connection Failed: " . mysqli_connect_errno(); exit(); } $id=$_GET['coid']; $stmt ->$mysqli ->prepare("SELECT*FROM table WHERE id=?"); $stmt ->bind_param('i',$id); if($stmt ->execute()){ while($row=$stmt ->fetch()){print_r($row);} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152391-need-help-with-passing-value-from-one-form-to-another-page/#findComment-800367 Share on other sites More sharing options...
demented_gurl Posted April 3, 2009 Author Share Posted April 3, 2009 what is your current code? <?php session_start(); $CoID=$_SESSION['CoID']; ?> <?php require_once('Connections/dbconnection.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO company (ContactName, CoName, CoID, CoAdd, NumOffice, NumHP, NumFax, Email, ContactPreferences) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['ContactName'], "text"), GetSQLValueString($_POST['CoName'], "text"), GetSQLValueString($_POST['CoID'], "int"), GetSQLValueString($_POST['CoAdd'], "text"), GetSQLValueString($_POST['NumOffice'], "text"), GetSQLValueString($_POST['NumHP'], "text"), GetSQLValueString($_POST['NumFax'], "text"), GetSQLValueString($_POST['Email'], "text"), GetSQLValueString($_POST['ContactPreferences'], "text")); mysql_select_db($database_dbconnection, $dbconnection); $Result1 = mysql_query($insertSQL, $dbconnection) or die(mysql_error()); $insertGoTo = "insertEventDetails.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form method="post" name="form1" action="<?php echo $editFormAction; ?>"> <table align="center"> <tr valign="baseline"> <td nowrap align="right">ContactName:</td> <td><input type="text" name="ContactName" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">CoName:</td> <td><input type="text" name="CoName" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">CoAdd:</td> <td><input type="text" name="CoAdd" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">NumOffice:</td> <td><input type="text" name="NumOffice" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">NumHP:</td> <td><input type="text" name="NumHP" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">NumFax:</td> <td><input type="text" name="NumFax" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">Email:</td> <td><input type="text" name="Email" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">ContactPreferences:</td> <td><input type="text" name="ContactPreferences" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right"> </td> <td><input type="submit" value="Insert record"></td> </tr> </table> <input type="hidden" name="CoID" value=""> <input type="hidden" name="MM_insert" value="form1"> </form> <p> </p> </body> </html> the CoID is a hidden file..and i would like to pass the value that the Mysql has assigned to the next page to be displayed.. Quote Link to comment https://forums.phpfreaks.com/topic/152391-need-help-with-passing-value-from-one-form-to-another-page/#findComment-800387 Share on other sites More sharing options...
darkfreaks Posted April 3, 2009 Share Posted April 3, 2009 http://www.zimmertech.com/tutorials/php/59/passing-variables-in-php.php Quote Link to comment https://forums.phpfreaks.com/topic/152391-need-help-with-passing-value-from-one-form-to-another-page/#findComment-800410 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.