Helpful Information
 
 
Category: Medium projects (new script, new features, etc)
Extremely urgent PHP Problem $100 to person who solves problem

Hi Guys

ok im in a rut ..

I'll give $100 to the person who solves my problem & its extremely urgent

Ok heres the scenario ..
I have an admin area where i can add / edit delete db entries

i have a link that when clicked i can input text into a text field and that then creates a folder based on the text

Now.. here is my problem
I then want to be able to create a page based on a template and insert it into the folder ( the foldername is selected from a dropdown menu )
and returns $store = $_POST['store']
so it would be www.mydomain.com/$store/

now i have successfully created a site based on a template ( see example here - http://www.servicedofficesin.co.uk ) this shows the folders & filenames etc etc

but the template for the new site seems to be having a lot of problems

it will create the page with the desired filename & in teh correct folder
but the php in the template is messed up
for example variable names get deleted
so i would have :

= '';

etc


i have included my entire template page below that i want the created pages to be based on & below that is the code for teh page to create the page etc

if anyone has any questions please pm me
thanks in advance



<?php include('storetemplatephpinc.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="keywords" content="<?php echo $row_GetStoreDetails['mkeywords'];?>" />
<meta name="description" content="<?php echo $row_GetStoreDetails['store'];?>"/>
<meta name="robots" content="index,follow,all" />
<meta name="revisit-after" content="1 day" />
<title><?php echo $row_GetStoreDetails['store'];?></title>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="900" height="341" border="0" align="center" cellpadding="5" cellspacing="5" bgcolor="#FFFFFF">
<tr>
<td height="90" colspan="3" valign="top"><img src="../img/logo.jpg" width="392" height="80" align="left" />
<table width="162" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="162" valign="top"><!-- AddThis Button BEGIN -->
<script type="text/javascript">addthis_pub = 'cyates';</script>
<span class="storelistings">Social Bookmark The Page</span><a href="http://www.addthis.com/bookmark.php" onmouseover="return addthis_open(this, '', '[URL]', '[TITLE]')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><br />
<img src="http://s9.addthis.com/button1-bm.gif" width="125" height="16" border="0" alt="" /></a>
<script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3" bgcolor="#666699"><a href="http://www.findvouchercodes.com" class="topmenu">Home</a>&nbsp;&nbsp; |&nbsp;&nbsp; <a href="../newdiscounts.php" class="topmenu">New Discounts</a>&nbsp;&nbsp; |&nbsp;&nbsp; <a href="../popularvouchercodes.php" class="topmenu">Most Popular Voucher Codes </a>&nbsp;&nbsp; |&nbsp;&nbsp; <a href="../vouchercodelist.php" class="topmenu">View Voucher Codes By Store</a> </td>
</tr>
<tr>
<td height="29" colspan="3" valign="top" bgcolor="#E9E9EF"><div class="viewstorebyletter">View Store By Letter :&nbsp;&nbsp;<a href="../vouchercodelist.php?letter=09" class="codesbyletter">0-9</a>&nbsp; <a href="../vouchercodelist.php?letter=a" class="codesbyletter">A</a>&nbsp; <a href="../vouchercodelist.php?letter=b" class="codesbyletter">B</a>&nbsp; <a href="../vouchercodelist.php?letter=c" class="codesbyletter">C</a>&nbsp; <a href="../vouchercodelist.php?letter=d" class="codesbyletter">D</a>&nbsp; <a href="../vouchercodelist.php?letter=e" class="codesbyletter">E</a>&nbsp; <a href="../vouchercodelist.php?letter=f" class="codesbyletter">F</a>&nbsp; <a href="../vouchercodelist.php?letter=g" class="codesbyletter">G</a>&nbsp; <a href="../vouchercodelist.php?letter=h" class="codesbyletter">H</a>&nbsp; <a href="../vouchercodelist.php?letter=i" class="codesbyletter">I</a>&nbsp; <a href="../vouchercodelist.php?letter=j" class="codesbyletter">J</a>&nbsp; <a href="../vouchercodelist.php?letter=k" class="codesbyletter">K</a>&nbsp; <a href="../vouchercodelist.php?letter=l" class="codesbyletter">L</a>&nbsp; <a href="../vouchercodelist.php?letter=m" class="codesbyletter">M</a>&nbsp; <a href="../vouchercodelist.php?letter=n" class="codesbyletter">N</a>&nbsp; <a href="../vouchercodelist.php?letter=o" class="codesbyletter">O</a>&nbsp; <a href="../vouchercodelist.php?letter=p" class="codesbyletter">P</a>&nbsp; <a href="../vouchercodelist.php?letter=q" class="codesbyletter">Q</a>&nbsp; <a href="../vouchercodelist.php?letter=r" class="codesbyletter">R</a>&nbsp; <a href="../vouchercodelist.php?letter=s" class="codesbyletter">S</a>&nbsp; <a href="../vouchercodelist.php?letter=t" class="codesbyletter">T</a>&nbsp; <a href="../vouchercodelist.php?letter=u" class="codesbyletter">U</a>&nbsp; <a href="../vouchercodelist.php?letter=v" class="codesbyletter">V</a>&nbsp; <a href="../vouchercodelist.php?letter=w" class="codesbyletter">W</a>&nbsp; <a href="../vouchercodelist.php?letter=x" class="codesbyletter">X</a>&nbsp; <a href="../vouchercodelist.php?letter=y" class="codesbyletter">Y</a>&nbsp; <a href="../vouchercodelist.php?letter=z" class="codesbyletter">Z</a></div>
</td>
</tr>
<tr>
<td width="200" valign="top"><?php include('../leftmenu.php');?></td>
<td valign="top" class="centercolumnborder"><table width="480" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#666699" bgcolor="#E9E9EF">
<tr>
<td valign="middle"><form id="addemail" name="addemail" method="post" action="../addtoemail.php">
<span class="normaltxt"><strong><span class="msg"><u><font color="#000000">Get Instant Notification Of New Discounts</font></u><br />
<br />
</span>Full Name :</strong>
<input name="name" type="text" class="normaltxt" id="name" />
</span>
<span class="normaltxt">&nbsp;&nbsp;&nbsp; <strong>Email Address :</strong></span>
<input name="emailaddress" type="text" class="normaltxt" id="emailaddress" />
<input type="image" name="imageField" src="../img/addme.jpg" />
</form> </td>
</tr>
</table>
<br />
<table width="480" align="center" cellpadding="2" cellspacing="0">
<tr>
<td valign="middle"><h1><a href="http://www.findvouchercodes.com" class="vouchercodetitle"><?php echo $row_GetStoreDetails['store'];?> voucher codes</a></h1>
<p class="normaltxt"> We provide you with <a href="http://www.findvouchercodes.com" class="normaltxt"><strong><?php echo $row_GetStoreDetails['store'];?> voucher codes</strong></a>, <a href="http://www.findvouchercodes.com" class="normaltxt"><strong><?php echo $row_GetStoreDetails['store'];?> promotional codes</strong></a>, <a href="http://www.findvouchercodes.com" class="normaltxt"><strong><?php echo $row_GetStoreDetails['store'];?> discount codes</strong></a> and money off vouchers that will save you money on your online purchases.<br />
<br /><?php echo $row_GetStoreDetails['text'];?>
<br />
</p>
</td>
</tr>
</table>
<br />
<table width="480" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" valign="middle" bgcolor="#666699" class="catheader"><?php echo $row_GetStoreDetails['store'];?> Voucher Codes</td>
</tr>
<?php do { ?> <?php
// Title URL String Re-Write
$oldtitle = $row_storecodes['title'];
$newtitle = str_replace(' ','-',$oldtitle);
$oldstore = $row_GetStoreDetails['store'];
$newstore = str_replace(' ','-',$oldstore);
?><tr><?php
$vctitlepage = $row_storecodes['title'].".php";
$coderewrite = str_replace('-',' ',$row_storecodes['title'])
;
?>
<td width="324" height="26" valign="middle" bgcolor="#E8E8EE"><font class="vouchertxt"><strong><a href="<?php echo $vctitlepage;?>" class="vouchertxt"><?php echo $coderewrite; ?></a></strong></font></td>

<td width="148" valign="middle" bgcolor="#E8E8EE" class="vouchertxt"><a href="<?php echo $vctitlepage;?>"><img src="../img/viewcodedetails.jpg" width="143" height="26" border="0" align="absmiddle" /></a></td>
</tr>
<tr>
<td colspan="2" valign="middle" class="copytxt">&nbsp;&nbsp; </td>
</tr>
<?php } while ($row_storecodes = mysql_fetch_assoc($storecodes)); ?>
</table>
<p class="viewstorebyletter">&nbsp;</p></td>
<td width="160" valign="top"><div align="center" class="rightmenu_a">Selected Retailers </div>
<div>
<div align="center">
<?php do { ?>
<a href="../showstore.php?store=<?php echo $row_SelectedRetailers['store'];?>&amp;storeid=<?php echo $row_SelectedRetailers['storeid'];?>"><img src="<?php echo $row_SelectedRetailers['logo'];?>" alt="<?php echo $row_SelectedRetailers['alt'];?>" border="0" /></a><br />
<?php } while ($row_SelectedRetailers = mysql_fetch_assoc($SelectedRetailers)); ?></div>
</div>
</td>
</tr>

<tr>
<td height="38" colspan="3"><div align="center" class="copytxt"><strong>&copy; Copyright <a href="http://www.findvouchercodes.com" class="copytxt">Find Voucher Codes</a> <?php echo date('Y');?></strong></div></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($GetStoreDetails);

mysql_free_result($SelectedRetailers);

mysql_free_result($StoreVoucherCodes);

mysql_free_result($IndexPageNewsItems);
?>

Had to make 2 posts ....

Code For page that creates the page


<?php include('../Connections/fvccon.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?><?php
mysql_select_db($database_fvccon, $fvccon);
$query_StoreList = "SELECT * FROM store";
$StoreList = mysql_query($query_StoreList, $fvccon) or die(mysql_error());
$row_StoreList = mysql_fetch_assoc($StoreList);
$totalRows_StoreList = mysql_num_rows($StoreList);


if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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")) {
mysql_select_db($database_fvccon, $fvccon);
$query_StoreList2 = "SELECT * FROM store WHERE storeid='$_POST[storeid]'";
$StoreList2 = mysql_query($query_StoreList2, $fvccon) or die(mysql_error());
$row_StoreList2 = mysql_fetch_assoc($StoreList2);
$totalRows_StoreList2 = mysql_num_rows($StoreList2);
// create page code
$title = $_POST['title'];
$keywords = $row_GetStoreDetails['mkeywords'];
$store = $row_GetStoreDetails['store'];
$storetext = $row_GetStoreDetails['text'];
$filename = fopen('../'.$row_StoreList2['store'].'/'.$title.'.php', 'a+');
$template = "THE CODE PASTED IN THE ABOVE POST GOES HERE";
fwrite($filename,$template);
fclose($filename);
// end create page code
$insertSQL = sprintf("INSERT INTO vc (vcid, storeid, dateadded, title, code, expires, mkeywords, mdesc, mtitle, launchurl, active) VALUES (&#37;s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['vcid'], "int"),
GetSQLValueString($_POST['storeid'], "int"),
GetSQLValueString($_POST['dateadded'], "text"),
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['code'], "text"),
GetSQLValueString($_POST['expires'], "text"),
GetSQLValueString($_POST['mkeywords'], "text"),
GetSQLValueString($_POST['mdesc'], "text"),
GetSQLValueString($_POST['mtitle'], "text"),
GetSQLValueString($_POST['launchurl'], "text"),
GetSQLValueString($_POST['active'], "text"));

mysql_select_db($database_fvccon, $fvccon);
$Result1 = mysql_query($insertSQL, $fvccon) or die(mysql_error());

$insertGoTo = "voucher-add.php?msg=Operation Completed Successfully";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}


?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FVC Admin</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="850" height="438" border="0" cellpadding="0" cellspacing="10">
<tr>
<td height="80" colspan="2" valign="top"><img src="../img/logo.jpg" width="392" height="80" /></td>
</tr>
<tr>
<td width="160" height="299" valign="top"><div class="catheader">Store</div>
<a href="store-add.php" class="copytxt">Add</a> / <a href="store-edit.php" class="copytxt">Edit</a> / <a href="store-delete.php" class="copytxt">Delete</a><br />
<br />
<div class="catheader">Voucher Codes </div>
<a href="voucher-add.php" class="copytxt">Add</a> / <a href="voucher-edit.php" class="copytxt">Edit</a> / <a href="voucher-delete.php" class="copytxt">Delete</a><br />
<br />

<div class="catheader">News</div>
<a href="news-add.php" class="copytxt">Add</a> / <a href="news-edit.php" class="copytxt">Edit</a> / <a href="news-delete.php" class="copytxt">Delete</a><br />
<br />
<a href="logout.php" class="msg">Logout</a><br />
<br /></td>
<td width="667" valign="top" bgcolor="#DCD8E2" class="normaltxt"><p><strong>Add Voucher Code </strong> </p>
<p align="center"><div class="msg" align="center"><?php echo $_GET['msg'];?></div>

<form id="form2" name="form2" method="get" action="<?php echo $_SERVER['PHP_SELF'];?>">
<p>
<select name="storeid" id="storeid">
<?php
do {
?>
<option value="<?php echo $row_StoreList['storeid']?>"><?php echo $row_StoreList['store']?></option>
<?php
} while ($row_StoreList = mysql_fetch_assoc($StoreList));
$rows = mysql_num_rows($StoreList);
if($rows > 0) {
mysql_data_seek($StoreList, 0);
$row_StoreList = mysql_fetch_assoc($StoreList);
}
?>
</select>
<input type="submit" name="Submit" value="Select Store" />
</p>
</form>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td width="112" align="right" nowrap class="normaltxt"><div align="left"><strong>Date added:</strong></div></td>
<td width="256"><input type="text" name="dateadded" value="<?php echo date('d/m/Y');?>" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="normaltxt"><div align="left"><strong>Title:</strong></div></td>
<td><input type="text" name="title" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="normaltxt"><div align="left"><strong>Code:</strong></div></td>
<td><input type="text" name="code" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="normaltxt"><div align="left"><strong>Expires:</strong></div></td>
<td><input type="text" name="expires" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="normaltxt"><div align="left"><strong>Mkeywords:</strong></div></td>
<td><input type="text" name="mkeywords" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="normaltxt"><div align="left"><strong>Mdesc:</strong></div></td>
<td><input type="text" name="mdesc" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="normaltxt"><div align="left"><strong>Mtitle:</strong></div></td>
<td><input type="text" name="mtitle" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="normaltxt"><div align="left"><strong>Launchurl:</strong></div></td>
<td><input type="text" name="launchurl" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="normaltxt"><div align="left"><strong>Active:</strong></div></td>
<td><select name="active">
<option value="Y" <?php if (!(strcmp("Y", ""))) {echo "SELECTED";} ?>>Yes</option>
<option value="N" <?php if (!(strcmp("N", ""))) {echo "SELECTED";} ?>>No</option>
</select> </td>
</tr>
<tr valign="baseline">
<td align="right" nowrap class="normaltxt"><div align="left"></div></td>
<td><input type="submit" value="Add Voucher"></td>
</tr>
</table>
<input type="hidden" name="vcid" value="">
<input type="hidden" name="storeid" value="<?php echo $_GET['storeid'];?>">
<input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
<p>&nbsp;</p></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($StoreList);
?>



if anyone would like me to email them certain files .. again please pm me
thanks guys this is very very urgent as in if its not solved today i could lose my job so $100 to whoever solves it

thanks

but the php in the template is messed up
for example variable names get deleted
so i would have :

= '';

etc the highlighted part is not clear! could you explain it more?

yeah for example

i have somewhere in teh template variable
<?php do { ?> <?php
// Title URL String Re-Write
$oldtitle = $row_storecodes['title'];
$newtitle = str_replace(' ','-',$oldtitle);
$oldstore = $row_GetStoreDetails['store'];
$newstore = str_replace(' ','-',$oldstore);
?><tr><?php
$vctitlepage = $row_storecodes['title'].".php";
$coderewrite = str_replace('-',' ',$row_storecodes['title'])
;
?>

all of the variable names are blank when the page is created
example
$oldtitle = $row_storecodes['title'];
would become
= '';

its the formatting of the code inside $template = " thats causing the problems

I would create the file and write to it something like this

$fp = fopen("$store/index.php","w+");
fwrite($fp,'<?php include(\'template.php\'); ?>');
fclose($fp);

Just store your template in its own file and just write php directly to the index file of the folder.

hi

have tried that not working

the file is being created as before but no php is being passed along

yeah i ammended that :)

still the same
can i email you the 2 files ?

anyone else got any ideas ?
really really desperate for this to be fixed

Hi enclose all your php code inside a nowdoc (http://in2.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc)

Something like this

echo <<<'EOT'
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should not print a capital 'A': \x41
EOT;

which outputs

My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should not print a capital 'A': \x41

Hope that works!

totally new to me lol

will have a look at it and reply asap

A really good start would be if you could show everyone what exactly you are trying to input.

I'm guessing it's something like 'Aerospace' mentioned ...



$fp = fopen("$store/index.php","w+");
fwrite($fp,'<?php include(\'template.php\'); ?>');
fclose($fp);


Ask yourself ...

- Are you able to create a file?
- Are you able to write plain text to that file?

- If yes, then are you putting any conflicting chars in the string?
-- Is the page returning an error
--- If so, what's the error?

If it's simply putting


= ''

.. then are you posting variables into the file? Vars in double quotes will be interpreted by php.

e.g.


$template = " $var = ''; ";

.. will output


= '';

So, use single quotes to encase the template var


$template = ' $var = ""';

Will output


$var = "";

.. If you are still having problems then look at the writing method you are using.

If you still can't find a solution .... Just give me a BUZZ ;-)

Bye for now.










privacy (GDPR)