PHP - Simple Php Print Vs Echo Question.
I set up a form that you can type html code into. When you click submit it sends the form data to a php script that receives the data and then prints it. Basically im trying to accomplish something similar to this http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro. I have tried to print the html code using echo and print_r. The problem is that it is not displaying correctly. For instance if i were to type in Code: [Select]
<body bgcolor="FFCC00"> Nothing would happen. Most of the html displays correctly. What is the reason behind this? Do i need to use a different command to print the form variable? Or do i need to save it as an html document then display it? Similar TutorialsOK, have no idea what's going on... I've done this a million times... why wont this output!?? I must have a major brain meltdown and dont know it yet!!! Code: [Select] <?php // this echoes just fine: echo $_POST['testfield']; // but this wont echo: echo if (isset($_POST['testfield'])) { $_POST['testfield'] = $test; } echo $test; /// or even this DOESNT echo either!: $_POST['testfield'] = $test; echo $test; ?> Hi, I am trying to get the form field to echo a php variable. The problem is that the form is 'Printed' via php. print "<td width=\"300\" valign=\"top\"><input type=\"text\" name=\"usr\" value=\"i.e. JBloggs \" onfocus=\"if(!this._haschanged){this.value=''};this._haschanged=true;\" tabindex=\"1\"></td>"; Instead of the value being i.e. JBloggs have it echo the $name variable. Any input would be appreciated. Should i be using print() or echo() for an xmlhttp.responsetext ? Code: [Select] <?php //================================================================ // Configure connection parameters $connect_string="DRIVER={Sybase SQL Anywhere 5.0}; SERVER=ACMSQL036A; DATABASE=BACKOFF"; $dbuser="DBA" $dbpswd="SQL" //================================================================ // Connect to DB $conn = odbc_connect($connect_string, $dbuser, $dbpswd); // Query $xrefnum = $_GET['ae_xrefnum']; $qry = "SELECT xrefnum, plunum FROM DBA.PLU_Cross_Ref where xrefnum = '$xrefnum'"; // Get Result $result = odbc_exec($conn,$qry); if (!$result) { echo odbc_errormsg($conn); } // Get Data From Result $row=odbc_fetch_array($result); // Show data print($row[plunum]); } // Free Result odbc_free_result($result); // Close Connection odbc_close($conn); //================================================================ ?> i have proof, hold on.
In PHP there are two basic ways to get output: echo and print.
meant there was more ways but they werent basic.
Edited by socialemo, 22 January 2015 - 01:33 AM. Hello guys, I want put one form into echo or print, but in the same time i want use $arrays on form. Take a look here <?php print "<form action="https://www.moneybookers.com/app/payment.pl" method="post" target="_blank"> <input type="hidden" name="pay_to_email" value="me@me.com"> <input type="hidden" name="status_url" value="$mail"> <input type="hidden" name="language" value="GR"> <input type="hidden" name="amount" value="$price"> <input type="hidden" name="currency" value="EUR"> <input type="hidden" name="detail1_description" value="$pack"> <input type="hidden" name="detail1_text" value="$review"> <input type="submit" value="Pay!"> </form>"; ?> but all this make an error. from what i can understand, i cant put second "" ine print Can u help me? Hey guys...I have a php that loads when the user is being taken after making a purchase. On that php file, echo and print are disabled...and I need to send a variable from that php file to flash, doesnt matter is flash, could be other php file, html, anyway... <param name="movie" value="retorno.swf?userId=<?php echo $Referencia; ?>" /> On the example above I am using echo $Referencia...I need some function to substitue echo/print... Any ideas??? Thanks in advance! Hi! I wonder why this code is working: for($i=0; $i<5; print $i++); while this code: for($i=0; $i<5; echo $i++); gives the error PHP Parse error: syntax error, unexpected T_ECHO, expecting ')' After spending some hours at php.net I learned that both calls ('echo' and 'print') are not real functions, but I wonder why they behave so different in the same context?! Also 'tricks' like for($i=0; $i<5; (echo $i), $i++); do not work. Is 'echo' just forbidden in that particular case? Best regards! Ok so its been a while since school and ive forgotton most my php as Ive been more into site building wiht css, html and graphics... <?php $part=part(""); $size=size(""); $qty=qty(""); if (($part=="2") && ($size=="11") && ($qty=="100")) echo "Price quote is $59.00" else if (($part=="2") && ($size=="11") && ($qty=="500")) echo "Price quote is $99.00" ?> my goal is to have a simple form, wiht 3 drop downs qty, size, part are the field names. And depending what options they pick they get a price out put... im missing something so simple, I know it should only take a couple lines of code and simply repeat it wiht else if until you hit the end of all possible options. Can some one please help? Thanks Hi, Im trying to pull an email from an url, and then echo the email as value into a email form-- under the "from" heading. The echo is not working i get blanks. here is the code: <?php $thisurl='$_SERVER['REQUEST_URI']'; $thepart = explode('/', $thisurl); $themail='$thepart[2]'; ?> <form method="post" action="sendit.php"> To: <br><input type="text" name="to" size="44" value="<?php for($i=1; $i<=$lines; $i=$i+1) { $names[$i] = str_replace("<br>", "", $names[$i]); $names[$i] = str_replace("\n", "", $names[$i]); echo $names[$i].';'; } ?>"><br> From: <br><input type="text" name="email" size="44" value="<?php echo '$themail'; ?>" readonly><br> Subject: <br><input type="text" name="subject" size="44" /><br><br> Hello!Can i echo data from 2 or more tables on the same page? Hey guys,
I am using a function that echos out 10 images from my database. I need to have a minimum of 4 echoed images. Some categories have less than 4 images, so I would like to have a default image(s) echoed out if the database has 4 or less images.
Does anyone know how I can do this?
Below is the code I am using now to echo out the 10 images.
Thanks in advance:
<?php $query = mysql_query('SELECT image_id FROM images ORDER BY RAND() LIMIT 10'); $i = 0; class myCounter3 implements Countable { public function count() { static $count = 0; return ++$count; } } $counter = new myCounter3; while ($row = mysql_fetch_array($query)) { if($i % 10 === 0) { } echo '<img src="http://www.mysite.com/'.$row['image_id'].'.jpg" width="300" height="auto"/>'; $i++; } ?> Default Image: <img src="http://www.mysite.com/default.jpg" width="300" height="auto"/> Hey people! I've been setting a coding script for experience and this is my situation: To buy a virtual flower, one needs to have 50 virtual coins. So I first extract the number of coins the person has from the DB. If the user doesn't have the sufficient number of coins, the BUY button will not be available and vice versa. When the BUY button is clicked, I update the database, adding the flower to the user's inventory and subtracting 50 from the total number of coins the user has. This I do in that page itself using if(isset($_POST['submit'])) Now, I need to know how I could check whether the user has at least 50 coins even if the button is available. I hope that you could understand this. I want to do it for validation purposes. Its to prevent the user spending the coins he has in another browser window and then returning to the visible button to click it. I hope that I make sense. Thanks in advance! Regards, Thauwa Hi all - I am a novice when it comes to PHP, but I have managed to use it successfully many times. I have an issue where I can not get a variable to echo when I am calling it from within a file that is using SSI. Here is a basic example that should explain it better. In the /index.php file: Code: [Select] <?php $photo1="photo1.jpg"; $photo2="photo2.jpg"; ?> <?php include('http://www.DOMAIN.com/includes/header.php'); ?> In the /header.php file: <img src="http://www.DOMAIN.com/photos/<?php echo $photo1; ?>"> When I try to echo $photo1 from within the /header.php file it simply does nothing, even though the variable is declared before the call for the include file. If I try to do the echo with the IMG tag from within the /index.php file, it works no problem -but that wont work without a MAJOR site redesign with how things are configured. Question is, why does this not work, and how can I fix it? Huge thanks from this Newb! I'm teaching myself php and mysql -- and my coding is a little rough. But what i'm trying to do is display information from a mysql table in another table on a website. I can do this just fine simply displaying the table, but i want a little something different. I am only displaying one column of the table, instead of displaying it all in one column, i want to display the information in 5 columns. for example..... the table from mysql has names scott, john, james, mary, simon. with the code I have i can make it display like this: scott scott scott scott scott john john john john john james james james james james mary mary mary mary mary simon simon simon simon simon i want it to diplay like this: scott john james mary simon new names will continue down here is my code: <?php require ("connectigb.php"); $result = mysql_query ("SELECT pledgeName FROM pledgewall"); $fields_num = mysql_num_fields($result); echo "<center> <h1>TSA It Gets Better Pledge Wall</h1>"; echo "<table border='1' align='center' style='width:960px;'><tr>"; while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) if ($cell != "") { for ($j=0; $j<5; $j++) { echo "<td>$cell</td>"; } } echo "</tr>\n"; } mysql_free_result($result); echo "</table></center>"; ?> any ideas on what i can do here, i'm sure this is a simply fix. i just haven't come across it yet. thanks for the help in advance. Hello everyone! I am a new user and I have a simple question. How do I set a password for a user to log in to my site with PHP? I have no MySQL database just a iOS code/host app. I know this isn’t secure but only me and my friends are on the site. Any help is appreciated. I can't figure out why im getting an error with this code. if ($notif = mysql_query("SELECT * FROM notifications_1 WHERE recieverid='". $_SESSION['id']."' ORDER BY read ASC, id DESC") or die (mysql_error())); { Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read ASC, id DESC' at line 1 Hi guys, this function below is for card validation, however anycard i enter i get the invalid card number, this is not connected to any gateways, this is just an Luhn card validation demonstration. can you tell me please why i get that? <?php if ($_POST['pay']) { $cardNo = addslashes(strip_tags($_POST['cardNo'])); function luhnCheck($cardNo) { $cardNo = str_replace(" ", "", trim($cardNo)); if(!is_numeric($cardNo) or strlen($cardNo)>19) return false; $skip = $newNum = $total = 0; for($i=0;$i<=(strlen($cardNo)-1);$i++) { if($skip ==0) { $tmpNum = ($cardNo[$i]*2); $total += (strlen($tmpNum)==2 ? (substr($tmpNum, 0, 1)+substr($tmpNum, 1)) : $tmpNum); $skip = 1; }else{ $total += $cardNo[$i]; $skip = 0; } } return (($total % 10) == 0); } /* Example Usage */ if(luhnCheck($_GET['cc'])) { echo("Valid Number."); }else{ echo("Invalid Number."); } } ?> <form name="confirm" method="post" action=""> <input type="text" name="cardNo"> <input type="submit" name="pay" value="Pay Now"> </form> I know it could be a issue with this line if(luhnCheck($_GET['cc'])) { but im wondering where should and how put this cc in my form? regards if someone can help me out with this, its quite simple but I can't seem to get it to work.. Basically, this is the code I have for now, the issue is if I have 0 product or items, I don't want the sorting option to show up on the page, from the code below, what line can I add tosay that if there is no products in a category, not to show the SORT feature. thanks in advance if anyone can help. {if isset($orderby) AND isset($orderway)} <!-- Sort products --> {if isset($smarty.get.id_category) && $smarty.get.id_category} {assign var='request' value=$link->getPaginationLink('category', $category, false, true)} {elseif isset($smarty.get.id_manufacturer) && $smarty.get.id_manufacturer} {assign var='request' value=$link->getPaginationLink('manufacturer', $manufacturer, false, true)} {elseif isset($smarty.get.id_supplier) && $smarty.get.id_supplier} {assign var='request' value=$link->getPaginationLink('supplier', $supplier, false, true)} {else} {assign var='request' value=$link->getPaginationLink(false, false, false, true)} {/if} <form id="productsSortForm" action="{$request|escape:'htmlall':'UTF-8'}"> <select id="selectPrductSort" onchange="document.location.href = $(this).val();"> <option value="{$link->addSortDetails($request, $orderbydefault, $orderwaydefault)|escape:'htmlall':'UTF-8'}" {if $orderby eq $orderbydefault}selected="selected"{/if}>{l s='--'}</option> {if !$PS_CATALOG_MODE} <option value="{$link->addSortDetails($request, 'price', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'price' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Price: lowest first'}</option> <option value="{$link->addSortDetails($request, 'price', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'price' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Price: highest first'}</option> {/if} <option value="{$link->addSortDetails($request, 'name', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Product Name: A to Z'}</option> <option value="{$link->addSortDetails($request, 'name', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Product Name: Z to A'}</option> {if !$PS_CATALOG_MODE} <option value="{$link->addSortDetails($request, 'quantity', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'quantity' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='In-stock first'}</option> {/if} </select> <label for="selectPrductSort">{l s='Sort by'}</label> </form> <!-- /Sort products --> {/if} I've seen this, Code: [Select] <?php } ?> in a lot of scripts at the very end of the script. What does this piece of code do? Hello there fellow programmers, I was just wondering if there was any difference between doing this: Code: [Select] echo "Say Something Here"; and this Code: [Select] echo "Say "; echo "Something "; echo "Here"; Thank you in advance. Notice: I am aware of the fact that they will output the same thing, my question is regarding resources. |