PHP - New Line In Scripts + Another Simple Question.
Hi all, I have a question. How do I put a new line in a script? I've tried everything.
<?php $con = mysql_connect("localhost","*","*"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $sql="SELECT * FROM People WHERE FirstName='Borko' AND LastName='Borkov'"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Found!"; echo($sql); mysql_close($con) ?> I wrapped it in <html> and so on, <br /> doesn't work. Saved it in html, <br /> still doesn't work and the script doesn't execute. The output I get right now is Quote Found!SELECT * FROM People WHERE FirstName='Borko' AND LastName='Borkov' I want it to display Quote Found! SELECT * FROM People WHERE FirstName='Borko' AND LastName='Borkov' And another question - how can I see what the sql variable is searching for from the browser? For now, as you have seen, I just use the echo($sql) but it doesn't quite cut it - is there a way to see just FirstName and LastName without the whole code? I tried echo($sql [FirstName] [LastName], as you've already guessed it didn't work... A hint would also be greatly appreciated! Any help on these two issues? Similar TutorialsThis may be a stupid question so forgive me if it sounds like a dumb question. I have my own server set up and I was wondering if it was at all possible to have a script running that is hosted on my server, while my PC is off or possibly just without having to load it within my web browser. I have a few scripts I wish to run forever without lagging my old PC. Is there a way to do this? Thanks. P.S All the scripts will be using the file_get_contents function to open HTTP streams, and a few explode functions here and there. Hi All, I'm trying to debug my first few lines of PHP where I have all my "checks" to make sure someone is logged in. I have this code all by itself and it is still not executing. This is the only page that I'm having trouble with. header('Location: login.php?logout=1'); Is there a simple way getting PHP to open a single file and write to a specific line? Like: fwrite (line = 102) {"bla bla bla"}; fclose; Hello -- I'm trying to work through a very simple CMS that I found on the web (just for learning purposes). I need some help understanding this line: <table> <form method="POST" action="account.php?mode=save<?=( isset($_REQUEST['id']) ? "&id={$_REQUEST['id']}" : null )?> <? I understand the Method = "POST", but not the "action = " line. Thanks for any help. PHP = 5.5.14
MySQL = 5.2.17
I've cloned a mysqli_connect() statement in a 'require' file placed in a non-public access location on the server. It's the same format (and location) currently working fine with another application, EXCEPT i changed the database name to what I need to use for this application, AND added the $con= part on the front end to substitute for the commented out $con= line in the example code I'm modifying to insert data into a new MySQL DB Table.
The dB Table is fine and I have Inserted data via myPHPAdmin with no problems. Only two form variables are in the simple PHP script thus far just to test if it will work before proceeding.
I've used pseudonames for the actual /home/.... location and filename, and am now Baffled about the Line 2 Error Message I'm getting (below the code).
<?php require '/home/myusername/domains/mydomain.com/myclonedrequire.php'; //$con=mysqli_connect("example","uid","pwd","my_db"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // escape variables for security $year = mysqli_real_escape_string($con, $_POST['year']); $callsign = mysqli_real_escape_string($con, $_POST['callsign']); $sql="INSERT INTO `lqplogs` (`year`, `callsign`) VALUES ('$year', '$callsign'); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?>ERROR Message: Warning: Unexpected character in input: '\' (ASCII=92) state=1 in (above file & location) on line 2 There are NO '\' characters in any of my files. Here is the simple Form file code: <?php ?> <html: <head><title></title></head> <body> <form action="insert.php" method="post"> YEAR: <input type="text" name="year"> CALLSIGN: <input type="text" name="callsign"> <input type="submit"> </form> </body> </html> <?php ?>Thanks for any assistance! -FreakingOUT Hello everyone I have a question? I run a PHP script loads about 200 calls simultaneously on Linux environment, so my question is what is best way to run a command line As an example php-f example.php or make it through the apache example "curl http://localhost/example.php" Thank you woren hello, I have multiple scripts I am writing for class and the very last script does not seem to be working and most of us are stumped . the first two seem to work fine but I am going to post them too just in case there is something on the previous scripts I am missing that is causing the error. the scripts are suppose to make a table then the final one lists the tables I believe. 1st script Do-Creaable.html ----------------------------------------------------------------------------------------------------------- <html> <title> input page</title> <head><strong> Name and Number of fields</strong></head> <body> <form method ="post" action="do_showfileddef.php"> Table Name: <br> <input type="text" name="table_name"><p> <br> Number of fields:<p> <input type="text" name="num_fields"><p> <input type="submit" value="go to step two"> </form> </body> </html> --------------------------------------------------------------------------------------------------------------------- second script do show_fieldeff.php --------------------------------------------------------------- <? if ((!$_POST['table_name']) || (!$_POST['num_fields'])) { header ("location: show_creatable.html"); exit; } $form_block =" <FORM METHOD=\"POST\"ACTION=\"do_creatable.php\"> <iINPUT TYPE=\"hidden\"NAME=\"table_name\" VALUE\"$_POST[table_name]\"> <TABLE CELLSPACING=5 CELLPADDING=5> <TR> <TH>field name</TH><TH>filed type</TH> <TH>field length</TH></TR>"; for($i =0; $i < $_POST['num_fields']; $i++) { $form_block .=" <tr> <td allign=center><input type=\"text\"name=\"filed_name[]\"size=\"30\"></td> <td align=center> <SELECT NAME=\"field_type[]\"> <OPTION VALUE=\"char\">char</OPTION> <OPTION VALUE=\"date\">date</OPTION> <OPTION VALUE=\"float\">float</OPTION> <OPTION VALUE=\"int\">int</OPTION> <OPTION VALUE=\"text\">textchar</OPTION> <OPTION VALUE=\"varchar\">varchar</OPTION> </SELECT> </td> <TD ALIGN=CENTER><INPUT TYPE=\"text\"NAME=\"field_length[]\" SIZE=\"5\"></td> </tr>"; } $form_block .=" <tr> <td allign=center colspan=3><input type=\"submit\"value=\"create table\"></td> </tr> </table> </form>"; ?> <html> <head> <title> create a Database table:step 2</title> </head> <body> <h1> Define fields for <? echo "$_POST[table_name]"; ?> </h1> <?echo "$form_block";?> </body> </html> ----------------------------------------------------------------------------------------------------------------- third script do_creatable.php _________________________________________________ ____________________________________ $db_name = "testdb"; $connection = @mysql_connect("localhost","root","") or die (mysql_error()); $db = @mysql_select_db($db_name,$connection) or die (mysql_error()); $sql = @"CREATE TABLE $_POST[table_name]("; for ($i =0; $i <count($_POST['field_name']);$i++){ $sql .= $_POST["field_length"][$i] ." ".$_POST['field_type'][$i]; if ($_POST ["field_length"] [$i] !="") { $sql .= "(".$_POST ["field_length"] [$i]."),"; } else { $sql .= ","; } } $sql = substr($sql,0,-1); $sql .=")"; $results = mysql_query ($sql,$connection) or die (mysql_error()); if ($results) { $msg="<P>".$_POST["table_name"]."has been created!</P>"; } ------------------------------------------------------------------------------------------------------------------ some where on that third script is an error but it keeps telling me bad syntax on line one. most of the class is having errors with this script and no one can find the cause its been like 2 weeks now. can someone help me? please bare in mind I am a student and some functions of php I am unfammiliar with Hi, I'm working on a product page and I got it to list all the products in one column of a table, but when I add a second column it just duplicates the first column. What do I need to change? Code: [Select] <?php require_once("functions.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=utf-8" /> <title>Untitled Document</title> <style type="text/css"> td { border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #30C; border-right-color: #30C; border-bottom-color: #30C; border-left-color: #30C; } </style> </head> <body> <form action="" method="post" name="catalog"> <?php DatabaseConnection(); $query = "SELECT * FROM treats"; $result_set = mysql_query($query) or die(mysql_error()); $output = "<table>"; while ($row = mysql_fetch_array($result_set)) { $output .= (" <tr> <td width=\"400px\">" . $row['product_title']."<br /> ".$row['product_Description']."<br />" .$row['price'] . "<br /> Quantity: <input name=\"quantity\" type=\"text\" size=\"2\" /> </td> <td width=\"400px\">" . $row['product_title']."<br /> ".$row['product_Description']."<br />" .$row['price'] . "<br /> Quantity: <input name=\"quantity\" type=\"text\" size=\"2\" /> </td> </tr> "); } $output .= "</table>"; echo $output; ?> </form> </body> </html> 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 Lets say I have: $var=5; What would an output look like to get me: 1<br> 2<br> 3<br> 4<br> 5<br> Im at a complete loss! Thanks! 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. 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 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. what does the # symbol do in php(e.x index.php?cat=1#privacy)? How can i use it? From what i 've seen you use it for changing a whole div without reloading the page like tabs.. 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} Hello to everyone I would like to ask for this simple question.. Im trying to put if and else condition on my php code. However this condition is not working.. Code: [Select] if($file == #3#){ echo "No results found"; }else{ echo "results has been found"; } This variable $file is the result after i used an API.. If the API does not see any results they would return #3# as the result. This means they returned a transaction code of 3 which you can see here http://developer.textapp.net/WebService/TransactionCodes.aspx means that there was nothing to return. The condition does not function well even if i make 3 or #3# as part of the condition. Can you help me guys? thanks Hi. I have an ID in md5 format but in the database its not. I pass the md5 ID to a page and then I am trying to load the correct record via a look up in the database of that ID. Im wondering is this code possible? <?php $query = mysql_query("SELECT * FROM table WHERE ".md5(tableID)." = $ID"); ?> Thanks 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. Hi,
I am trying to convert a php function into perl and need to understand the following line in red :
function pagination($query, $per_page = 10,$page = 1, $url = '?'){ $query = "SELECT COUNT(*) as `num` FROM {$query}"; $row = mysql_fetch_array(mysql_query($query)); $total = $row['num']; $adjacents = "2"; $page = ($page == 0 ? 1 : $page); $start = ($page - 1) * $per_page; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total/$per_page); $lpm1 = $lastpage - 1; $pagination = ""; if($lastpage > 1) { ......................................... What will be the output of this line above in red. Thank you very much. Regards. Tonya 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? |