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