Jump to content

Recommended Posts

Hi,

 

I have the following code which allows a user to enter a name for a mysql column field. Once they have submitted the form they are then redirected back to the form which allows them to enter the name for another mysql column form.

 

When they are returned to the form, I would like the new column field added to the file named userinfo.php

 

The problem is, I need the column field variable entered into the userinfo.php in the following format

 

$newcolumn = $info['newcolumn']

 

but when I put it like this

 

$stringData = "$newcolumn = $info['newcolumn']";

 

I get this error

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/tropicsb/public_html/MemberSiteMaker/admin.php on line 398

 

// Profile and Application details

case "profileFields":

session_start();
if(isset($_SESSION['username']))
{

$newcolumn = $_GET['newcolumn'];

$file = "lib/userinfo.php";
$fh = fopen($file, 'a') or die ("Cant open file");
$stringData = "$newcolumn = $info['newcolumn']";
fwrite($fh, $stringData);
fclose($fh);


echo "This is the logged in page\n<br>";
ECHO <<<PAGE
<form action=admin.php?cmd=addfield&username=admin method=POST>
<input type=text name=newcolumn>
<input type=submit name=submit>
PAGE;

} else {

echo "This is a failed login";

}

break;

case "addfield":

include_once("data/mysql.php");

$newcolumn = $_POST['newcolumn'];

$mysqlPassword = (base64_decode($mysqlpword));

$con = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die(mysql_error());
mysql_select_db("$dbname", $con) or die(mysql_error());


$result=mysql_query("ALTER TABLE members
ADD $newcolumn VARCHAR(30) AFTER approved") or die("Alter Error: ".mysql_error());
mysql_close($con);

echo "Database has been modified successfully.";

echo '<meta http-equiv="REFRESH" content="5;url=admin.php?cmd=profileFields&username=admin&$newcolumn">';


break;

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/230457-trouble-appending-file/
Share on other sites

Hi thanks for your reply, I changed the code to what you said, but now all what is written to the file is

 

$newcolumn = $info['newcolumn']

 

it does not carry the value given to the $newcolumn variable from

 

$newcolumn = $_POST['newcolumn'];

 

however if I just put

 

$stringData = '$newcolumn';

 

it will write the value to the file such as $name

 

I am not sure how stringData can actually write the following string to file. I am using name as the value given to $newcolumn

 

$stringData = '$name = $info[\'name\']';

 

As always, any help is much appreciated

 

Paul

thanks for your reply, but still no luck.

 

The script adds a new column to the database using the $newcolumn variable

 

it then adds the variable value such as $name to the file, however it has to be written to the file like this.

 

$newcolumn = $info['newcolumn'];

 

where newcolumn will be the variable value so:

 

$name = $info['name'];

 

the $info['name']; is required in the file as it is used to retreive information from the mysql database

 

Many Thanks

Ideally something like this should work

 

$stringData = '$' . $newcolumn . '= $info[' . $newcolumn ']';

 

but i get this error

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/tropicsb/public_html/MemberSiteMaker/admin.php on line 429

 

any ideas on how to fix this? It would really help as it should write what I need to file then

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.