Easy - Help with HTML values from form :c)

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:

[code]

  <input type="text" name="name" value="" size="32" />
  <input type="submit" value="Do it." />
" /> [/code]

And I this the PHP portion:

[php]

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

[/php]

anybody?

So, what is your question? From your code it look like you have added that second field for ‘file’.

Thanks for your reply!

I would like to know how to put the same value of ‘name’ (taken from the html form) in the ‘file’ field in the table. But add .txt to it.

Yes, now I see. You need to update this line in your php code:

[php]GetSQLValueString($_POST[‘file’], “text”));[/php]

change it to this:
[php]GetSQLValueString($_POST[‘name’].’.txt’, “text”));[/php]

You’re amazing!!! Thank you so much! I’m going to try that now!

Sponsor our Newsletter | Privacy Policy | Terms of Service