PHP - Separate Db File Or Intern?
What is the most secure way?
Having DB connect script in the beginning of every script you need db for, or Having a database.php script containing the script and then including it to all other php. Similar Tutorials$poststart = "<!-- Begin -->";
$poststop = "<!-- End -->";
$parsedpost1 = explode($poststart, $contenu);
$parsedpost2 = explode($poststop, $parsedpost1[1]);
$contenu = $parsedpost1[0] . $poststart . $newpost . $poststop . $parsedpost2[1];
The above code will set 2 markers and replace whatever inside by $newpost, which is defined elsewhere in the page. But what if $newpost is so long that I'd be more comfortable storing it in a separate file?
How would I go about calling said file on that last line? (I'm referring to the specific syntax.)
Thx
How to do it? I have read some methods but they seem to not work. This is what I have got so far:
<?php Hi, When the user creates a contact, then edits the contact that final edited information is shown in a file called "my data.txt". After this, when I select my php file "save_contact_details.php" the details stored in the text file "my data.txt" are not retrieved. How can I retrieve them? At the moment the issue I'm having is that I see no data when I click on "save_contact_details.php" after I filled in all the contact persons information. Feel free to watch this video I recorded to help you understand what I am talking about. https://streamable.com/rbw6p save_contact_details.php code <html> <body> <?php $myFile=fopen("mydata.txt","r") or exit("Can’t open file!"); // Write each line of text into the text file file fwrite($myFile, $_POST["lastname"]."\r\n"); fwrite($myFile, $_POST["firstname"]."\r\n"); fwrite($myFile, $_POST["address01"]."\r\n"); fwrite($myFile, $_POST["address02"]."\r\n"); fwrite($myFile, $_POST["town"]."\r\n"); fwrite($myFile, $_POST["postcode"]."\r\n"); fwrite($myFile, $_POST["telephone"]."\r\n"); fwrite($myFile, $_POST["email"]."\r\n"); fclose($myFile); ?> <h1>My Contact Details</h1> <p>The contact details that you have submitted are shown below:</p> <table> <tr> <td align="right">Last name: </td> <td><?php echo $_POST["lastname"]; ?></td> </tr> <tr> <td align="right">First name: </td> <td><?php echo $_POST["firstname"]; ?></td> </tr> <tr> <td align="right">Address 01: </td> <td><?php echo $_POST["address01"]; ?></td> </tr> <tr> <td align="right">Address 02: </td> <td><?php echo $_POST["address02"]; ?></td> </tr> <tr> <td align="right">Town / city: </td> <td><?php echo $_POST["town"]; ?></td> </tr> <tr> <td align="right">Post code: </td> <td><?php echo $_POST["postcode"]; ?></td> </tr> <tr> <td align="right">Telephone: </td> <td><?php echo $_POST["telephone"]; ?></td> </tr> <tr> <td align="right">E-mail: </td> <td><?php echo $_POST["email"]; ?></td> </tr> </table> </body> </html>
<html> <body> <?php $myFile=fopen("mydata.txt","r") or exit("Can’t open file!"); // read each line of text from the text file $lastname = fgets($myFile); $firstname = fgets($myFile); $address01 = fgets($myFile); $address02 = fgets($myFile); $town = fgets($myFile); $postcode = fgets($myFile); $telephone = fgets($myFile); $email = fgets($myFile); fclose($myFile); ?> <h1>My Contact Details</h1> <p> The contact details on file are as shown below.<br> Edit the data and save your changes to file. </p> <form action="save_contact_details.php" method="post"> <table> <tr> <td align="right">Last name: </td><td> <?php echo "<input size=\"20\" type=\"text\" name=\"lastname\" value=\"$lastname\">"?> </td> </tr> <tr> <td align="right">First name: </td><td> <?php echo "<input size=\"20\" type=\"text\" name=\"firstname\" value=\"$firstname\">"?> </tr> <tr> <td align="right">Address 01: </td><td> <?php echo "<input size=\"30\" type=\"text\" name=\"address01\" value=\"$address01\">"?> </td> </tr> <tr> <td align="right">Address 02: </td><td> <?php echo "<input size=\"30\" type=\"text\" name=\"address02\" value=\"$address02\">"?> </td> </tr> <tr> <td align="right">Town / city: </td><td> <?php echo "<input size=\"20\" type=\"text\" name=\"town\" value=\"$town\">"?> </td> </tr> <tr> <td align="right">Post code: </td><td> <?php echo "<input size=\"10\" type=\"text\" name=\"postcode\" value=\"$postcode\">"?> </td> </tr> <tr> <td align="right">Telephone: </td><td> <?php echo "<input size=\"15\" type=\"text\" name=\"telephone\" value=\"$telephone\">"?> </td> </tr> <tr> <td align="right">E-mail: </td><td> <?php echo "<input size=\"50\" type=\"text\" name=\"email\" value=\"$email\">"?> </td> </tr> <tr> <td> </td> <td colspan="2" align="left"><input type="submit" value="Save Changes"></td> </tr> </table> </form> </body> </html> create contact html code <html> <body> <h1>The contact details</h1> <p>Please enter your contact details:</p> <form action="save_contact_details.php" method="post"> <table> <tr> <td align="right">First name: </td> <td><input size="20" type="text" maxlength="15" name="firstname"></td> </tr> <tr> <td align="right">Last name: </td> <td><input size="20" type="text" maxlength="15" name="lastname"></td> </tr> <tr> <td align="right">Address line 1: </td> <td><input size="30" type="text" maxlength="50" name="address01"></td> </tr> <tr> <td align="right">Address line 2: </td> <td><input size="30" type="text" maxlength="50" name="address02"></td> </tr> <tr> <td align="right">Town / city: </td> <td><input size="20" type="text" maxlength="20" name="town"></td> </tr> <tr> <td align="right">Post code: </td> <td><input size="10" type="text" maxlength="10" name="postcode"></td> </tr> <tr> <td align="right">Telephone: </td> <td><input size="15" type="text" size="20" maxlength="15" name="telephone"></td> </tr> <tr> <td align="right">E-mail: </td> <td><input size="50" type="text" maxlength="50" name="email"></td> </tr> <tr> <td> </td> <td colspan="2" align="left"><input type="submit" value="Submit"></td> </tr> </table> </form> </body> </html>
Hi, I have a separate form created using Dreamweaver that calls a separate php script when the Submit button is clicked. Currently I am able display form validation messages in a new html page. If the user leaves fields blank, I would like the messages to appear on the form itself instead of in a new page. How do you make the messages from the php form validation code display into the calling html form? I know I could just do this with Dreamweaver but I would like to learn to do this using php. It might be easier to embed the code within the html page but I was thinking that using the separate script would be more secure. My form can be found here. Validation is working but opens a new page: http://www.tallfirshoa.com/adform.htm Thanks! Rob Hi.. been a while since I have touched php and need some help. What I am trying to do is have my links pull text from separate php files, and load them into main table. Here is my old php code..used to work.. I had my index.php with my website template on it. In the table I want my info to appear i put this code. <?php /* START MAIN AREA HERE */ if($news) include("news.php"); elseif($bio) include("bio.php"); elseif($draw) include("draw.php"); elseif($pic) include("pic.php"); else include("news.php"); /* END HERE */?> My link looks like this. <A HREF="?news=x" ONMOUSEOVER="changeImages('home', 'images/home-over.gif'); return true;" ONMOUSEOUT="changeImages('home', 'images/home.gif'); return true;"> <IMG NAME="home" SRC="images/home.gif" WIDTH=69 HEIGHT=31 BORDER=0 ALT=""></A> Any help much appreciated! For example if $names has a value of "Mark/Ben/James/Tom" how would I separate it to give each name its own variable, e.g $name1, $name2, $name3
Thanks,
Hi all, I'm currently working on a webpage that dynamically shows tables of sales for products. I'm using SQL to store 2 tables, one containing product info (name, price etc.) and one containing sales for each product. One on of my web pages I want to show the product name and sales for a single year. This would involve ripping the product name from my product table and the sales and year from my sales table. Is this possible in one query? $Query= "select name from productTable and sales, year from salesTable where year = $desiredyear; Obviously I know this is wrong because it isn't working but am I even on the right lines? Thank you. Or is the ORM the only mapper? here is my code $query = "SELECT * from links ORDER BY field_4 DESC"; // assumes that your date column is a DATE data type so that ordering by it will sort the dates $result = mysql_query($query); // check if the query executed without error and if it returned any rows here... // retrieve and process the data from the query $last_date = ''; // initialize to a value that will never exist as data while($row = mysql_fetch_assoc($result)){ // test for a new date and output the date heading if($last_date != $row['field_4']){ echo "<p><font face='Arial, Helvetica, sans-serif'>"; echo $row['field_4'] . "<br />"; echo "</font></p>"; $last_date = $row['field_4']; // remember the new date } // output the data (under each date heading) echo "<img src=" . $row['field_1'] . " border=0>"; echo "<a href='" . $row['field_3'] . "'>"; echo $row['field_2'] . "</a><br />"; } mysql_close($con); i would like set the data under each heading to be ordered by a different column, how do i do so? I've been cracking at this for the part of 2 days now, and I cannot get my regex to work properly in my script. /^[A-Za-z][\w\-',.]*(?<![^A-Za-z][\w\-\'\,\.])$/i The above is for a last name field, and it needs to be able to accept: Roberts, Jr. (as an example)... As you can see in my regex, I am allowing all of these characters.. And it's still not validating it. You can test to see what I mean he <?php $last_name = "Roberts, Jr."; if (!preg_match("/^[A-Za-z][\w\-',.]*(?<![^A-Za-z][\w\-\'\,\.])$/i", $last_name )) { echo "Sorry no dice!"; } ?> I am trying to split some strings up by commas with preg_split but I keep on getting the error: "No ending delimiter ',' found" Here is my Code: $links = preg_split(',', $links); $titles = preg_split(',', $titles); $images = preg_split(',', $images); Thanks, Alex ok i think and hope this will be my last issue with this site. i have two forms on the same contact page, but right now theyre using the same error label. this means if ONE has an error, both forms show as that same error. id like to somehow separate this and give each one its own label. i tried doing like error[2] for the 2nd button instead of error[] but then i didnt know what to change the actual "error label" to. do i changed the "$errors = array();" part? to create a second label? i tried to google on it and couldnt figure it out. thanks a million to anyone who even reads <?php if (isset($errors)) { foreach ($errors as $error) { echo("<p>$error<p>\n"); } } ?> so my question basically is, how do i use this code below to create a second error case AND label please!! <?php if ($_POST['send']) { $errors = array(); if ($_POST['captcha'] != $_SESSION['captchacode']) { $errors[] = "You didn't enter the correct letters!"; } + <?php if (isset($errors)) { foreach ($errors as $error) { echo("<p>$error<p>\n"); } } ?> I've got a table (tbl_items) that holds a number of items and the individual information for each. Within 'tbl_items' I also have a row labeled 'category_id' in which each item is given a number (ex: 2). I've got a separate table (tbl_items_categories) that only has 2 rows: 'category_id' and 'category_name'. I wasn't sure if a JOIN method would be best for this but what would be the best approach to list all items and within each item, also echo out the name of the category they belong to and not the category_id number? trying to create an array that is separating brackets, semi-colon and space from "mydata" and iterating over to create first and last name's separated into two subs... and then loop those through. so i'd like either change the way i can explode and loop the information... or place the first and second subs and skip the third sub in the array. $str = $_POST["mydata"]; $mores = explode("[];",$str); foreach ($mores as $more) { $datas = explode(" ",$more); if (array_values ($datas) === $datas) $xmlBody .= " <member name='$datas[1], $datas[0]' display='$datas[0] $datas[1]'>Name</member>"; } can someone please assist? much appreciated. I am currently trying to make a line graph out of data using php and javascript. How do I add up the values of a column and separate them by month. For example the database has 74 amount of rows. Then the values from the "views" column get added up and then displayed by month. Code: [Select] <table width="70%" class="linechart"> <thead> <tr> <td></td> <th scope="col">Jan</th> <th scope="col">Feb</th> <th scope="col">Mar</th> <th scope="col">Apr</th> <th scope="col">May</th> <th scope="col">Jun</th> </tr> </thead> <tbody> <tr> <th scope="row">Post Views</th> <td>24324</td> <td>29634</td> <td>15435</td> <td>56545</td> <td>23543</td> <td>2123</td> </tr> </tbody> </table> I don't have any PHP skills at all. In fact I'm probably looking for a script that can help accomplish what I'm asking about. Regardless, I'm having a hard time getting any answers or solutions to this. I would like to make a web form that collects cc#'s from my customers that is PCI Compliant in as simple a manner as possible. 99% of the time my clients are not being charged at all, and the cc is used simply to ensure a service is confirmed. If they were to be charged, I would have to do that manually as no payment gateways currently deposit into banks in the country I am in. One thought I had would be if I could have the cc# either split, or broken up into separate fields and emailed separately. I am told this is PCI Compliant. I would also be fine with the cc# being split between database and email. I know this is possible w/ zen cart, but I have been unable to find any scripts that do this and don't have a need for a shopping cart addition to my site. But, I am aware that zen cart and other shopping cart add ons have options for X's to cover a bunch of numbers in the middle of the string and write that directly to the database. One thing that is a necessity is that the majority of the data input to the form be emailed. So, I'm basically hoping to protect the cc data in the simplest way possible, which I thought would be to break it up. I'll be trashing the cc #'s once I get them. I have no need to file them. I do have a SSL on my server. I am completely open to other suggestions. Is something like this, or another option a possibility? My skills are rudimentary. I taught myself to write some html and also use Dreamweaver to subsidize for what I can't code myself. I apologize if this should be in one of the other forums. I have a list generated from an array by foreach as Code: [Select] foreach ($list_array as $item) { echo "$item<br />"; } This is a long list, how can I separate the list to different pages? I mean the simplest way to do so First, here's some code: Code: [Select] $result = mysql_query("SELECT standard FROM thestandards WHERE id={$theSearch}", $connection); if (!$result) { die("Database connection failed: " . mysql_error()); } while ($row = mysql_fetch_array($result)) { $query = $row[0]; } // echo $testing = nl2br($query); $subStrings = explode('\n', $query); echo $subStrings[0] . "<br />"; // outputs entire query echo $subStrings[1] . "<br />"; // undefined offset echo $subStrings[2] . "<br />"; // undefined offset echo $subStrings[3] . "<br />"; // undefined offset So, the data I'm retrieving from the database is several small paragraphs. I want to take these paragraphs, separate them, and put them into an array. I tried using the explode function with the newline char, but for some reason it doesn't work. I can get it to work if I want to go explicitly add "\n"s in the database everywhere, but that just doesn't seem practical. nl2br doesn't work for what I need, but I find it interesting that this function is somehow able to "see" all the newlines in the query, whereas the explode function cannot. Explode is really what I need, but I've tried '\n', '\r', '\r\n' and nothing works. Thanks for the help. Hi, I'm new to the forum so this could go in the MySQL section but I'm not sure. I am trying to make a page that will list all records from a column in HTML table and have a delete button to remove a specific record. I have got to the part where I have listed the records in a table. Note: Only records from a specific column ('links') are printed. Here is the code: Code: [Select] $con = mysql_connect("localhost","***","***"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("***", $con); $result = mysql_query("SELECT * FROM main"); echo "<table border='1'> <tr> <th>Current links</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['links'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); How would I go about adding a delete button next to each record to delete that specific record? Thanks for any help. Hi all What is the best way to work with times that are stored without there date but with only one date field regarding both times? Thanks |