Jump to content

need help with passing value from one form to another page


demented_gurl

Recommended Posts

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.  :)

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.

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);}
}
?>

 

 

 

actually i messed up you would pass $id as an integer ;D

 

<?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);}
}
?>

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

Archived

This topic is now archived and is closed to further replies.

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