Jump to content

Easy - Help Concatinating from form :c)


Recommended Posts

Hi guys.

 

So this is what I'm trying to do.

 

I have a form on my website,

 

the user puts in a value and php inserts that value into the database in one field called "name". But I am also trying to use that same value and insert it another field at the same time but just adding "name".".txt". but in a field called "file" (both in the same table of course)

 

Thank you guys so much in advance! I am new and I really appreciate any help! Thank you!

 

Here is my field html:

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">

      <input type="text" name="name" value="" size="32" />
      <input type="submit" value="Do it." />
   
  <input type="hidden" name="numofuser" value="50" />
  <input type="hidden" name="file" value="<?php echo "chatroom-".$name.".txt" ?>" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
       

 

 

And I this the PHP portion:

 


<?php
   
    session_start();

    require_once("dbcon.php");

    if (checkVar($_SESSION['userid'])):

        $getRooms = "SELECT *
                     FROM chat_rooms";
        $roomResults = mysql_query($getRooms);          

?>
<?php require_once('Connections/dbcon.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 chat_rooms (name, numofuser, `file`) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['numofuser'], "int"),
                       GetSQLValueString($_POST['file'], "text"));

  mysql_select_db($database_dbcon, $dbcon);
  $Result1 = mysql_query($insertSQL, $dbcon) or die(mysql_error());

  $insertGoTo = "chatrooms.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_dbcon, $dbcon);
$query_talkabout = "SELECT * FROM chat_rooms";
$talkabout = mysql_query($query_talkabout, $dbcon) or die(mysql_error());
$row_talkabout = mysql_fetch_assoc($talkabout);
$totalRows_talkabout = mysql_num_rows($talkabout);
?>

Link to comment
https://forums.phpfreaks.com/topic/211862-easy-help-concatinating-from-form-c/
Share on other sites

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.