Author Topic: Easy - Help with HTML values from form :c)  (Read 321 times)

theinfamousmickey

  • New Member
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Easy - Help with HTML values from form :c)
« on: August 27, 2010, 01:18:34 AM »
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: [Select]
<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 Code: [Select]


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

« Last Edit: August 27, 2010, 12:31:44 PM by theinfamousmickey »

theinfamousmickey

  • New Member
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Easy - Help Concatinating from form :c)
« Reply #1 on: August 27, 2010, 12:05:20 PM »
anybody?

phphelp

  • Administrator
  • Senior Member
  • *****
  • Posts: 777
  • Karma: +3/-0
    • View Profile
    • PHP Help forum
Re: Easy - Help with HTML values from form :c)
« Reply #2 on: August 27, 2010, 01:38:55 PM »
So, what is your question? From your code it look like you have added that second field for 'file'.
Are you experienced in PHP programming and willing to share your knowledge?
Join us at php help forum!

theinfamousmickey

  • New Member
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Easy - Help with HTML values from form :c)
« Reply #3 on: August 27, 2010, 02:14:01 PM »
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.

phphelp

  • Administrator
  • Senior Member
  • *****
  • Posts: 777
  • Karma: +3/-0
    • View Profile
    • PHP Help forum
Re: Easy - Help with HTML values from form :c)
« Reply #4 on: August 27, 2010, 03:13:46 PM »
Yes, now I see. You need to update this line in your php code:

PHP Code: [Select]
GetSQLValueString($_POST['file'], "text"));

change it to this:
PHP Code: [Select]
GetSQLValueString($_POST['name'].'.txt'"text"));
Are you experienced in PHP programming and willing to share your knowledge?
Join us at php help forum!

theinfamousmickey

  • New Member
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Easy - Help with HTML values from form :c)
« Reply #5 on: August 27, 2010, 03:26:47 PM »
You're amazing!!! Thank you so much! I'm going to try that now!