PHP - Load Script From Db Problem With Eval()?
hi everyone
i've just finnished a lynda.com course and began coding my own site.. i want to be able to put the script it self in the database. Then from read and execute the script from content.php BUT i get this error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\content.php(35) : eval()'d code on line 1 Call Stack so far it's has been fairly easy to correct the errors, but this one i don't know how to handle.. can anyone give me a hint where I've mistaken The script i put in the database if (!isset($_GET['category'])) { $query = "SELECT * FROM links ORDER BY category ASC"; $result = mysql_query($query); echo "<table border=\"0\" width=\"100%\"> <tr> <td> <ul>"; while ($row = mysql_fetch_assoc($result)) { echo "<li><a href=\"links.php?content=links&category=" . $row['category'] . "\">" . $row['category'] . "</a></li>"; } echo "</ul> </td> </tr> </table>"; } if (isset($_GET['category'])) { $linkcat = $_GET['category']; $query = "SELECT * FROM links WHERE category='{$linkcat}' ORDER BY title ASC"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo "<table border=\"0\" width=\"100%\" height=\"160\"> <tr> <td colspan=\"3\" align=\"center\" valign=\"top\"> <h1><a href=\"" . $row['address'] . "\">" . $row['title'] . "</a></h1> </td> </tr> <tr> <td colspan=\"3\" align=\"center\" valign=\"middle\"> <p>" . $row['description'] . "</p> </td> </tr> <tr> <td align=\"left\" valign=\"bottom\" style=\"float:right\"><a href=\"profile.php?username=" . $row['author'] . "\">" . $row['author'] . "</a></td> <td align=\"center\" valign=\"bottom\"><p>" . $row['votes'] . "</p></td> <td align=\"right\" valign=\"bottom\" style=\"margin-right:10;\"><p>" . $row['clicks'] . "</p></td> </tr> </table> <br /> <hr /> <br />"; } } content.php <?php require_once('includes/connection.php'); ?> <?php $content = $_GET['content']; $query = "SELECT * FROM pages WHERE page_name='{$content}'"; $result = mysql_query($query); if (!$result) { echo "Could not successfully run query from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } $row = mysql_fetch_assoc($result); $str = $row['content']; eval("\$str = \"$str\";"); echo $str; ?> Thank you in advance Dokter G Similar TutorialsThe following code does what I want it to, but after it's done doing it, it won't stop loading. I believe it is because of the while loops (while(1) { ... } and while($data = ...) { ... }). I need while($data = ...) to read the data from the fsockopen. Thanks in advance function ircConnect($server, $port, $channel, $nick, $pass, $name, $msg) { set_time_limit(15); //If we put set_time_limit(0), the page won't timeout and never stops loading (The script works, that I'm aware of) $fp = fsockopen($server, $port); if(!$fp) die($php_errormsg); if(empty($php_errormsg)) { $error = "None!"; } else { $error = $php_errormsg; } echo "<table border='1' bordercolor='#FFCC00' style='background-color:#FFFFCC' width='400' cellpadding='3' cellspacing='3'>"; echo "<tr><td>Server</td><td>Port</td><td>Channel</td><td>Nick</td><td>Password</td><td>Error</td></tr>"; echo "<tr><td>$server</td><td>$port</td><td>$channel</td><td>$nick</td><td>$pass</td><td>$error</td></tr>"; echo "</table>"; fputs($fp, "USER aBot testchan.org TestchanIRCBot :TheBot\n"); fputs($fp, "PASS $pass\n"); fputs($fp, "NICK $nick\n"); fputs($fp, "JOIN $channel\n"); fputs($fp, "PRIVMSG $channel :$msg, my name is $nick!\n"); while($data = fgets($fp, 128)) { $ex = explode(' ', $data); echo nl2br($data); flush(); if($ex[0] == "PING") fputs($fp, "PONG " . $ex[1] ."\n"); } } http://i.imgur.com/E6j79.jpg Hi, I am wanting to create a random fact script for a small website project. The idea is when the user loads a page a random fact will appear at the top ( I guess from an array of strings I will make?) Can anyone recommend the most efficient and easiest way to go about this please? Hello there, I have a script which uses the LOAD DATA LOCAL INFILE command see below: <?php //connect to your database mysql_connect("localhost", "xxx", "xxx"); //(host, username, password) //specify database mysql_select_db("xxx") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "LOAD DATA INFILE '/public_html/admin/files/test-jp-stock.csv' INTO TABLE 'jpaero_stocksearch' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 LINES"; if(mysql_query($query)){ echo ">> New Stock Data has now been uploaded. Database is now live and searchable.";} else{ echo "Upload failed. Please contact support.";} ?> Initially I uploaded the csv file through phpmyadmin and everything worked fine - so I then used the SQL generated inside my script, changing the location to where the file actually is - however now nothing happens at all. Any ideas on whats gone wrong, gratefully received! Thanks, Hi,
In reference to my first attached image, I have a form which displays two SELECT/drop-down fields (labeled "Store Name" and "Item Description".....and both of which pull-in values from two separate lookup/master tables, in addition to providing an additional option each for "NEW STORE" and "NEW ITEM").
Now, when first-run, and/or if "NEW STORE" and "NEW ITEM" are not selected from the drop-down's then the two fields in green ("New Store Name" and "New Item Name" are hidden, by means of the following code:
<div class="new-store-container" id="new-store-container" name="new-store-container" style="display:none;"> <div class="control-group"> <div class="other-store" id="new_store_name"> <?php echo standardInputField('New Store Name', 'new_store_name', '', $errors); ?> </div> </div> </div>Conversely, if "NEW STORE" and/or "NEW ITEM" are selected from the two drop-down's then one (or both) of the "New Name" fields are unhidden by means of the following two pieces of code, one PHP and the second JS: <select class="store-name" name="store_id" id="store_id" onclick="toggle_visibility('store_id','new-store-container')"> <?php echo $store_options; ?> <?php if($values['store_id'] == "OTH") { echo "<option value='OTH' selected> <<<--- NEW STORE --->>> </option>"; } else { echo '<OPTION VALUE="OTH"> <<<--- NEW STORE --->>> </OPTION>'; } ?> </select> function toggle_visibility(fieldName, containerName) { var e = document.getElementById(fieldName); var g = document.getElementById(containerName); if (e.value == 'OTH') { if(g.style.display == 'none') g.style.display = 'block'; else g.style.display = 'none'; } }All of that is working just fine. The problem I'm having is that when I click the "Create" button, after having left any one of the form fields blank, the two "New Name" fields are hidden again, which I don't want to happen i.e. I want them to remain visible (since the values of "store_id" and/or "item_id" are "OTH"), so that the user can enter values into one or both of them, without havng to click on the drop-down a second time in order to execute the "on-click" code. The second attached image shows how the fields are hidden, after clicking "Create". How can I achieve that? It would be greate if someone could cobble-up the required code and provide it to me, since I'm relatively new to this. Thanks much. Snap1.png 26.14KB 0 downloads Snap2.png 149.47KB 0 downloads hi i have this code: Code: [Select] <script type="text/javascript"> $(document).ready(function() { function doAjax(url) { $("#customForm").submit(function() { var formdata = $("#customForm").serializeArray(); $.ajax({ url: url, type: "post", dataType: "json", data: formdata, success: function(data, data1) { switch (data.livre) { case 'tituloLivre': $("#msgbox2").fadeTo(200, 0.1, function() { $(this).html('Titulo Livre').fadeTo(900, 1); }); break; default: $("#msgbox2").fadeTo(200, 0.1, function() { $(this).html('Active a sua conta e pode efectuar o login!').fadeTo(900, 1, function() { $('#conteudo').load('dojo/test_Slider.php'); }); }); break; } } }); return false; }); } doAjax('sent.php'); doAjax('dojo/test_Slider.php'); }); </script> and test_Slider.php Code: [Select] <?php include ('includesMy.php'); $form = $_POST['item']; $oferta = $form['oferta']; var_dump($oferta); echo json_encode ($oferta); ?> i should load the php file with ajax influence, but when i made load (test_Slider.php) obviously i get null because is independent of ajax call. My question is, how can i load a whole php file that is changed by ajax call ? (json return is not the solution because i have much more content, like graphics elements in test_Slider.php) Hello there, I have a issue. My issue is that I parse PHP code executed by people via a command like so !php echo("hello there"); would output "hello there". Here is my command: case ':!php': $message = ""; for($i=4; $i <= (count($this->ex)); $i++) { $message .= $this->ex[$i]." "; } ob_start(); @eval($message); $output = ob_get_contents(); fputs($this->socket,"PRIVMSG #volt :{$output}\r\n"); ob_end_flush(); break; $message contains the code to be executed. But the problem is it won't return more than one line. I really want it to be able to output multiple lights from eval E.G if someone where to output a item that is split up into multiple lines. Does anybody know how to accomplish this? Well from the fantastic response on my last post (0 replies, 80+ views), I've decided to browse A LOT of articles on how to do what I need to do. And, well I got it down to the function in PHP as Eval. I have my code set up like this: Code: [Select] $query="SELECT * FROM info"; $results = mysql_query($query); while ($row = mysql_fetch_assoc($results)) { $x = $row['pointtext']; echo $x; } As you can see this, this is a simple query to grab all the rows under pointtxt. I have only 1 at the moment which is to text it, and it echo's it fine! It echo's this: Code: [Select] Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'verdana.ttf', "text to write"); This is a PHP script for TEXT-TO-IMAGE. SO then considering the echo worked, I used this code: Code: [Select] $query="SELECT * FROM info"; $results = mysql_query($query); while ($row = mysql_fetch_assoc($results)) { $x = $row['pointtext']; header("Content-Type: image/jpeg"); $im = ImageCreateFromPng("test.png"); $black = ImageColorAllocate($im, 255, 255, 255); $start_x = 10; $start_y = 20; eval($x); Imagejpeg($im, '', 100); ImageDestroy($im); } And as you can imagine, it doesn't work. As I said in my 2 day old topic, I want it to have the ability to put more text onto the image and save it. So, do I get help this time? PLEASE. Does the eval function not support the TEXT TO IMAGE got an error in the script. What, please at least answer this time. _______ Also forgot to mention that how the script doesn't work, is it displays the picture fine, but it doesn't place any text onto it. Or any I can see with the set coords. im got php code witch is there Code: [Select] <?php /* Hello World (helloworld.php) */ //Required for Active Members / Last 24 Active Members Plugins define('SCRIPTNAME', 'test.php'); //Load templates for this page to avoid extra usage of SQL queries. $LoadTemplatelist = array('test'); //Init require('./library/init/init.php'); //Set Page Title $Page_Title = get_phrase('test'); //Create & Add Breadcrumb AddBreadcrumb(array ( get_phrase('navigation_home') => $TSUE['TSUE_Settings']->settings['global_settings']['website_url'].'/?p=home&pid=1', get_phrase('test_home') => $TSUE['TSUE_Settings']->settings['global_settings']['website_url'].'/?p=test&pid='.PAGEID )); //Get Page Template $test = ''; $query = mysqli_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB); $sql = mysqli_query($query, "SELECT `filename`, `tid`, `info_hash`, `name`, `description`, `cid`, `size`, `added`, `leechers`, `seeders`, `times_completed`, `owner`, `options`, `nfo`, `sticky`, `flags`, `mtime`, `ctime`, `download_multiplier`, `upload_multiplier` FROM `tsue_torrents`, `tsue_attachments` WHERE `content_type`='torrent_images' AND `content_id` = `tid` LIMIT 0, 10"); while ($row = mysqli_fetch_array($sql)) { $test_row = ''; $description= $row['description']; $name= $row['name']; $leechers= $row['leechers']; $owner= $row['owner']; $filename= $row['filename']; $nunx= $row['tid']; $seeders= $row['seeders']; eval("\$test_row = \"".$TSUE['TSUE_Template']->LoadTemplate('test_row')."\";"); $test .= $test_row; } eval("\$test = \"".$TSUE['TSUE_Template']->LoadTemplate('test')."\";"); //Print HTML Output PrintOutput($test, $Page_Title); ?> any chance to call that code to other template? Code: [Select] <!DOCTYPE html> <html id="TSUE" lang="{$TSUE['TSUE_Language']->content_language}"> <head> <noscript><meta http-equiv=refresh content="0; URL={$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/?noscript=1" /></noscript> <base href="{$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/" /> <title>{$Page_Title}</title> <meta charset="{$TSUE['TSUE_Language']->charset}" /> <meta name="description" content="{$TSUE['TSUE_Settings']->settings['global_settings']['website_description']}" /> <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=3.0, user-scalable=1" /> <link rel="stylesheet" href="{$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/style.php?l=style,fancybox,jqueryTools,forums,fileuploader,tinymce_ui,thread_prefixes,comments,downloads,image_gallery" type="text/css" media="screen" /> <link rel="Shortcut Icon" href="{$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/favicon.ico" type="image/x-icon" /> </head> <body> {$newAnnouncement} <!-- start #wrap --> <div id="wrap"> <div class="over_header"> <div id="header"><div class="content">{$languageSelect}</div> {$Navigation} </div> </div> <!-- start #inner --> <div id="inner"> {$test} {$breadcrumb} {$SubNavigation} <div id="plugins"> {$sidebar} <div id="content" class="mainContent {$contentWidthClass}">{$warningHTML} {$PluginsHTML} {$Output}</div> </div> </div> <!-- end #inner --> <!-- start #footer --> <div id="footer"> <div class="footer_top"></div> <div class="footer_mid"> <div id="panel"> <p> None of the files shown here are actually hosted on this server. The links are provided solely by this site\'s users. The administrator of this site cannot be held responsible for what its users post, or any other actions of its users. You may not use this site ({1}) to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms.', This site is best viewed with <a href="https://www.mozilla.com/en-US/firefox/" title="Get Firefox - The Browser, Reloaded."><b>FireFox</b></a> and with 1280*1024 in resolution. Recommended BitTorrent client\'s: <a href="https://www.utorrent.com/download.php" title="Get uTorrent"><b>uTorrent</b></a> - <a href="http://pingpong-abc.sourceforge.net/download.php" title="Get ABC"><b>ABC</b></a> </p> </div> <p class="slide"><a href="#" class="btn-slide">Disclaimer</a></p> </div> <div class="footer_btm"> <div class="wrap"> <!-- Warning: Please note that you are not permitted to remove the TSUE branding / copyright unless you have purchased the branding-free option: htt://templateshares-ue.net/purchase/ --> <p>Powered by Templateshares Ultimate Edition {$TSUE['TSUE_Settings']->settings['global_settings']['tsue_version']} © Copyright 2011 <a href="http://www.templateshares-ue.net">www.templateshares-ue.net</a></p> <!-- Warning: Please note that you are not permitted to remove the TSUE branding / copyright unless you have purchased the branding-free option: htt://templateshares-ue.net/purchase/ --> </div> </div> </div> <!-- end #footer --> </div> <!-- end #wrap --> <script type="text/javascript"> //<![CDATA[ {$main_javascript} //]]> </script> {$loadjavascriptsCache} <script type="text/javascript" src="{$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/js/tiny_mce/tiny_mce_gzip.js"></script> <script type="text/javascript"> tinyMCE_GZ.init ({ plugins : '-inlinepopups,-smilies,-quote,-tsuecode,-autoresize', themes : 'tsue', languages : '', disk_cache : true, debug : false }); </script> <script type="text/javascript"> //<![CDATA[ {$tinymce_init} //]]> </script> <img src="{$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/cron.php?rq={$TIMENOW}" alt="" width="1" height="1" /> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery(".btn-slide").click(function(){ jQuery("#panel").slideToggle("slow"); jQuery(this).toggleClass("active"); return false; }); }); </script> </body> </html> as u see im trying to call it {$test} but its dont work im get error Code: [Select] [29-Jan-2012 13:43:46] PHP Notice: Undefined variable: test in /home/admincom/public_html/tsue/library/functions/functions_global.php(0) : eval()'d code on line 24 Thanks Hi. I'm using SimpleImage.php to do some basic image manipulation. The code is here http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php, but I don't think all the details are important. Basically, I'm trying to read and image and save it with a different name. I'm really new with this stuff, so it's probably something simple. Anyway, here is the code throwing the error, $image_info = getimagesize($filename); where $filename is a string containing the path to the image I want to load, e.g. $filename="images/picture.jpg"; It's throwing a "Read Error!" I know that the path is correct. In fact I first check if the file is there using is_file($filename); and it returns true. I'm guessing that maybe php does not have "permission" to read this file. The permissions for the file are -rw-r--r-- 1 www-data www-data 80211 2011-04-20 16:19 picture.jpg Looks like everyone has "read" permission, so I don't see what the problem is. Also, the permissions of the folder and all parent folders are 777. Not sure what the problem is. I might be way off by guessing that it is a permissions problem. Any help would be great. Thanks. Also, I was wondering if there is a way for this forum to email me whenever there is a reply to my posts. I can't seem to find the option anywhere. hi i know eval is not best way to run php code via database but its required to me. What is happening i am reading a feed and if i use eval it just repeat same rss links but if i put a direct code it show proper feed. here is my code which works proper $xml = simplexml_load_file($feedurl); foreach ($xml->channel->item as $item) { echo $item->title . "\n"; echo $item->link . "\n"; } results of above code are fine. Code: [Select] Feed one title feed one link feed two title feed two link feed three title feed three link and so on for 10 times as 10 feeds are available...... But if i use eval my database contains <?php echo $item->title . "\n"; echo $item->link . "\n"; ?> and i run it like this $xml = simplexml_load_file($feedurl); foreach ($xml->channel->item as $item) { eval('?>' . $fromadatabase['code'] . '<?php '); } and i get this results Code: [Select] Feed one title feed one link Feed one title feed one link Feed one title feed one link and so on...... means it just repeat first feed for 10 times Thanks for any help. Basically I am making a class which displays a set of data. Now sometimes the data returned from the database will be a unix time stamp so this needs to be displayed in a correct form. For this I use str_replace $replace - below this will contain a way of converting the data Replace is defined by: $replace = 'date(\'d-m-y\',$row_data[\'lastupdate\'])'; $row.= str_replace('{data}',eval($replace),'<td>{data}</td>'); This just gives me Parse error: syntax error, unexpected $end in C:\xampp\htdocs\z\src\lib\lib.table.php(348) : eval()'d code on line 1 Is this possible at all? I am working on a very simple templating engine and I ran into a problem. Here's the basic template.class.php file <?php class Template { public $template; function load($filepath) { $this->template = file_get_contents($filepath); } function replace($var, $content) { $this->template = str_replace("#$var#", $content, $this->template); } function publish() { eval("?>".$this->template."<?"); } } ?> That is called in whatever model I am using, like this: public function createTemplate() { $templatePath = TEMPLATE_PATH . strtolower(__CLASS__) . ".php"; require_once (APPLICATION_PATH . 'libraries/template.class.php'); $template = new Template; $template->load($templatePath); $template->replace("productid", $this->product_id); $template->replace("price", $this->price); $template->replace("sidebar_message", $this->sidebarmsg); $template->publish(); } My problem is that my template.php ($templatePath) file uses include() to bring in the sidebar, head and footer. Any values that I passed to the template which are in the sidebar, header or footer are not evaluated. They just show their placeholders like #sidebar_message#... Is there another way to do this and publish the template so that they are evaluated properly? I have multiple servers and I'm trying to have a user connect to the right server based on their 'assigned' server. So, I need to use different variable names based on that in an include file earlier in the main script, I have... Code: [Select] $hostSignIn0001="server1"; $userSignIn0001="xxx1"; $passwordSignIn0001="yyy1"; $dbnameSignIn0001="zzz1"; $hostSignIn0001="server2"; $userSignIn0001="xxx2"; $passwordSignIn0001="yyy2"; $dbnameSignIn0001="zzz2"; in the main script, I have a variable that has the assigned server and I want to use the right connection variables based on this. I could use eval to turn $hostSignIn into $hostSignIn0001 (and so forth for the other variables) and then it would pull the right info, but I'm looking for an alternative way to do this since I'd like to exclude eval from functioning in my scripts using php.ini. Is there an alternative way to do this without using eval? Code: [Select] if (!$cxnSignIn = mysqli_connect($hostSignIn, $userSignIn, $passwordSignIn, $dbnameSignIn)) { exit; } Thanks. Hello guys i used the eval function but it does not echo anything back in the while loop ..the $new_string function contains "preg_split("/\.\(.*\)\.\(.*\)/", $file);", same as $parts..i need some guidance, thanks! <?php //"$DOCUMENT_ROOT"."new/"; $current_dir = 'C:\xampp\htdocs\Audit_Reports'; //Put in second part, the directory - without a leading slash but with a trailing slash! $dir = opendir($current_dir); // Open the sucker $newArgument = $_POST[argument]; $newArgument1 = $_POST[argument1]; $string ='preg_split("/\.\(.*\)\.\(.*\)/", $file);'; $new_string = preg_replace("#\/\\\.\\\\\(\.\*\\\\\)#","/\.\\($newArgument\)",$string); $new_string = preg_replace("#\\\.\\\\\(\.\*\\\\\)#","\.\\($newArgument1\)", $new_string); echo ("<p><h1>List of Audit Reports:</h1></p><hr><br />"); while ($file = readdir($dir)) // while loop { $parts = preg_split("/\.\(CLIENT\)\.\(.*\)/", $file); // $part = eval($new_string); if (is_array($parts) && count($parts) > 1) { // does the dissected array have more than one part $extension = reset($parts); // set to we can see last file extension if ($extension == "Audit_Report" OR $extension == "audit_report") // is extension ext or EXT ? echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; // If so, echo it out else do nothing cos it's not what we want } } echo "<hr><br />"; closedir($dir); // Close the directory after we are done ?> The below codes are done in a while loop Result:ArrayArrayArrayArrayArrayArrayArrayArrayArrayArra yArrayArray $parts = preg_split("/\.\(A\)\.\(A\)/", $file); echo $parts; Result:No Output $part = eval($new_string); echo $part; So i need to dynamically call a function in my object, depending on certain parameters. Currently, I'm doing this: Code: [Select] <?php $myObject = new Object_Class; $the_function_to_call = "do_something"; // this is not really a static variable; it changes each time the script loads. eval("\$myObject->". $the_function_to_call ."();"); // run $myObject->do_something(); ?> This works fine but I'd rather not use eval() if I can help it. Is there an easy way to do this that I'm just missing? I'm having a problem and need an answer to why its happening and how to prevent it. Scenario: I begin load my home page which starts with a session_start(); .... Before it FULLY completes loading I try to navigate to another page and BOOM, that page will not load and any other page that begins with session_start(); will not load unless I close and restart the entire browser or wait about 10 minutes.... I will note my website makes ajax calls every 5 seconds or so, but I use setTimeout for them. Any help??? Thanks ahead! Hello dear Community, i have a large document - and i want it to parse it and spit out only this part: schule.php?schulnr=80287&lschb= Question: How to i parse the stuff!? Well i try it with FireBug and FirePath (the Xpath-tool) i do it like the following: * Load the document into my browser, if possible * start Firebug extension/add-on * run the FirePath extension * and run the xpath //a[contains(@href, "schule")]/@href * then i click "Eval" button. i find 2030 results - that are marked - how do i get them out of the firebug - to work with them?! If i have to be more precise - please let me know!! Perhaps i have to write more - and to add more information See the screenshot - here http://img259.imageshack.us/img259/7360/sceenshoteval5.jpg how can i copy and paste the results - in order to do further processing from thereon. look forward to hear from you regards Previously, the PHP codebase I was using was that written by others, and I used their code to tinker with so I could get an understanding how PHP works. Now that I am comfortable using PHP, I have written my own short PHP script from scratch with the aim of it seeing my newsletter system functioning at minimal, for the first time. The newsletters system is made with HTML/PHP/MySQL. I am having a problem with the PHP side of things where I am getting an error: Quote PHP Parse error: syntax error, unexpected T_IF on line 50 ... which is: Code: [Select] if $_POST['action'] == 'Register' { I am hoping someone that knows allot about PHP could take a look at my code and see whats wrong with it? PHP code within confirm.html: Code: [Select] <?php $link = mysql_connect('localhost', 'testusr', 'testpw'); mysql_select_db('testdb', $link); $email = $_POST['e-mail']; $query = if $_POST['action'] == 'Register' { if $_POST['newsletter'] == 'Mens' { "INSERT INTO newsletters(mens) VALUES('$email')"; } elseif $_POST['newsletter'] == 'Mens & Womens' { "INSERT INTO newsletters(mensandwomens) VALUES('$email')"; } elseif $_POST['newsletter'] == 'Womens' { "INSERT INTO newsletters(womens) VALUES('$email')"; } ;} mysql_query ($link, $query); mysql_close($link); ?> HTML FORM code within index.html: Code: [Select] <FORM action="confirm.html" method="post"> <DIV> <SPAN class="input"> Action: <SELECT name="action"> <OPTION>Register</OPTION> <OPTION>Unregister</OPTION> </SELECT>    E-mail: <INPUT name="e-mail" type="text"></INPUT>    Newsletter: <SELECT name="newsletter"> <OPTION>Mens</OPTION> <OPTION>Mens & Womans</OPTION> <OPTION>Womens</OPTION> </SELECT>    <INPUT class="submit" type="submit" value="Submit"> </SPAN> </DIV> </FORM> here is the basic script . i use this script for edit html or text file. <?php $action=$_POST['action']; $textarea=$_POST['textarea']; if($_GET['p']){ $page=$_GET['p']; } // Assume your text pages are called, p1.db or p2.db, etc. $url = "p".$page.".html"; if (file_exists($url)) { // do nothing } else { $url = "p0.txt"; } // where to go back to after the edit ... $return="page.php?p=$page"; // Get page $data = implode("", file($url)); if($action=="save"){ $newtext=stripslashes($textarea); $newtext = str_replace("<?", "", $newtext); $newtext = str_replace("?>", "", $newtext); $newtext = nl2br($newtext); //echo "page: $url<br><br>\n"; //echo $newtext; $fh = fopen($url, 'w') or die("can't open file"); fwrite($fh, $newtext); fclose($fh); header ("location: edit.php?p=$page"); } else{ echo" <html> <head><title>Simple Text Editor</title> <style> body,html{ margin:0px auto; width:700px; text-align:center; } #content{ margin:0px auto; width:700px; } #middle h1 { color: transparent; font-family:georgia; font-size:12pt; margin:0; color: #dF9100; padding:10px 0px 15px 0px; text-align:left; } </style> <body> <div id='content'> "; $ta=br2nl($data); echo" <a href='$return'><-- Return to Page</a><br /><br /> Make Changes and click \"Save Changes\" at the very bottom ...<br /> <form action='edit.php' method='post'> <input type='hidden' name='action' value='save'> <input type='hidden' name='p' value='$page'> <input type='hidden' name='n' value='$n'> <textarea name='textarea' rows='25' cols='80'>$ta</textarea> <br /> <input type='submit' name='submit' value='Save Changes'> </form> <div id='middle' style='width:680px; text-align:left; padding-left:20px; border:1px solid #ccc;'> </div> </div> </body> </html> "; } function br2nl($str) { return preg_replace('=<br */?>=i', "", $str); } ?> __________________ the script is running fine. but when i intregate tinymce with the script.. <!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=utf-8" /> <title>abeer cms</title> <script type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script> <script type="text/javascript"> tinyMCE.init({ // General options mode : "textareas", theme : "advanced", plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager", // Theme options theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect", theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : true, // Example content CSS (should be your site CSS) content_css : "css/example.css", // Drop lists for link/image/media/template dialogs template_external_list_url : "js/template_list.js", external_link_list_url : "js/link_list.js", external_image_list_url : "js/image_list.js", media_external_list_url : "js/media_list.js", // Replace values for the template plugin template_replace_values : { username : "Some User", staffid : "991234" } }); </script> </head> <body> <?php $action=$_POST['action']; $textarea=$_POST['textarea']; if($_GET['p']){ $page=$_GET['p']; } // Assume your text pages are called, p1.db or p2.db, etc. $url = "p".$page.".html"; if (file_exists($url)) { // do nothing } else { $url = "p0.html"; } // where to go back to after the edit ... $return="edit.php?p=$edit"; // Get page $data = implode("", file($url)); if($action=="save"){ $newtext=stripslashes($textarea); $newtext = str_replace("<?", "", $newtext); $newtext = str_replace("?>", "", $newtext); $newtext = nl2br($newtext); //echo "page: $url<br><br>\n"; //echo $newtext; $fh = fopen($url, 'w') or die("can't open file"); fwrite($fh, $newtext); fclose($fh); header ("location: edit.php?p=$page"); } else{ echo" <html> <head><title>Simple Text Editor</title> <style> body,html{ margin:0px auto; width:700px; text-align:center; } #content{ margin:0px auto; width:700px; } #middle h1 { color: transparent; font-family:georgia; font-size:12pt; margin:0; color: #dF9100; padding:10px 0px 15px 0px; text-align:left; } </style> <body> <div id='content'> "; $ta=br2nl($data); echo" <a href='$return'><-- Return to Page</a><br /><br /> Make Changes and click \"Save Changes\" at the very bottom ...<br /> <form action='edit.php' method='post'> <input type='hidden' name='action' value='save'> <input type='hidden' name='p' value='$page'> <input type='hidden' name='n' value='$n'> <textarea name='textarea' rows='25' cols='80'>$ta</textarea> <br /> <input type='submit' name='submit' value='Save Changes'> </form> <div id='middle' style='width:680px; text-align:left; padding-left:20px; border:1px solid #ccc;'> </div> </div> </body> </html> "; } function br2nl($str) { return preg_replace('=<br */?>=i', "", $str); } ?> __________________ </body> </html> the script show error message after clicking the save button. the error message is Warning: Cannot modify header information - headers already sent by (output started at c:\wamp\www\edit.php:6) in c:\wamp\www\edit.php on line 78 can any one help regarding this issue? Well this problem has occurred a lot. I try to put ". $_GET['site'] ." or ". $_POST['site'] ." in my script and i get a server errror when trying t access my page ( error connecting the page basically) Here is the part of the script which that is occuring to: Quote if($_GET['step'] == 2) { echo 'Just adding INCLUDE files'; exec('xcopy /X/ / ". $_GET['site'] ." / /e/i', $a, $a1); <---- This line echo '<form action="install.php?step=3&guid='. $my_guid .'" method="post">'; echo '<input type="submit" value="Continue">'; echo '</form>'; } When i try using the $_GET function or $_POST functions in alot of stuff it just shows an server error(error connecting the page on my browser) Someone please help! |