PHP - Content Retrieved From Database Different
Hi Guys,
I have the following code that I'm getting from my database. This is how it appears in the DB. Code: [Select] <div id="reply_flash"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td style="font-family: Arial; font-size: 14px; line-height: 19px; text-align: left; color: rgb(102, 102, 102);"> <br> <div style="font-family: Georgia; font-size: 19px; line-height: 20px; color: rgb(88, 43, 0); font-weight: normal; text-align: left;">This is a heading</div> <p>This is some text in this area.</p> <a href="#"><strong>Read more</strong></a> </td> </tr> </table> </div> When the user goes to edit the page, I'm retrieving the above from the database: http://www.mysite.com/newsletter/edit/56 Code: [Select] // Controller to handle the request public function edit() { $id = $this->uri->segment(3); $data['get_newsletter'] = $this->Newsletter_model->get_newsletter($id); $this->load->view('header'); $this->load->view('newsletter/edit', $data); $this->load->view('footer'); } // View to display the request foreach($get_newsletter as $row) { $code = $row->code; $newsletter_id = $row->id; } echo $code; Now, when I echo the code below. It appears in the html as Code: [Select] <div id="reply_flash"> </div> // CLOSING THE DIV AND PUTTING THE TABLE OUTSIDE <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td style="font-family: Arial; font-size: 14px; line-height: 19px; text-align: left; color: rgb(102, 102, 102);"> <br> <div style="font-family: Georgia; font-size: 19px; line-height: 20px; color: rgb(88, 43, 0); font-weight: normal; text-align: left;">This is a heading</div> <p>This is some text in this area.</p> <a href="#"><strong>Read more</strong></a> </td> </tr> </table> </div> As you can see, when it's being retrieved and being displayed on the webpage, the div is being closed and the table appears outside it. Have no isdea what is going on. Similar TutorialsHey--New to the forum, and php. I have a drop-down list populated by a MySQL database. Submitting that selection retrieves php scripts which I run using eval(). One of them is a form. The scripts evaluate fine, but when I submit the second form, it disappears and I get a resource id where the "result" script was. The resource ids change between 3 and 4 when I refresh the page. Any hints on what I'm doing wrong? Here is the main script: <?php $host="localhost"; $username="root"; $password="root"; $con = mysql_connect($host,$username,$password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("calculators", $con); $result = mysql_query("SELECT * FROM calculator"); while($row = mysql_fetch_array($result)) { echo "<option type='text' " . "value='" . $row['Title'] . "'>" . $row['Title'] . "</option>"; } echo "</select>"; echo "<br>"; echo "<input type='submit' name='submit1'>"; echo "</form>"; $title = mysql_real_escape_string($_GET['Title']); $result = mysql_query('SELECT * FROM calculator WHERE Title = "' . $title . '"'); while($row = mysql_fetch_array($result)) { $header = $row['Header']; $calculator = $row['Calculator']; $result = $row['Result']; $formula = $row['Formula']; $reference = $row['Reference']; } eval('?>' . $header . '<?php '); echo "<h2>Calculator</h2>"; eval('?>' . $calculator . '<?php '); echo "<h2>Result</h2>"; eval('?>' . $result . '<?php '); echo "<h2>Formula</h2>"; eval('?>' . $formula . '<?php '); echo "<h2>Reference</h2>"; eval('?>' . $reference . '<?php '); mysql_close($con); ?> Thanks, Davis Hi guys, I was just wondering if anyone could help me. I've got a My_SQL database containing articles, a summary for the article and a date. I have a basic CMS system set-up, but I want to create a script that when users sign up to a mail list it forwards the summary and dates of the articles database. If that makes sense? But I only want it to forward the most recent 5 rows. I'm pretty new to PHP and I've been mostly following tutorials thus far, but this is quite specific. Thanks in advance! The first page is used to submit data to second page (and also show errors if there are any with the data submitted). The second page should be retrieving the posted data and assigning that data to session should it need to refresh back to the first page to show errors. The session data is used to repopulate the form. Right now I'm typing test into the review_name variable and when the page redirects back to the form to display the error messages, that field is not populated with "test". Code: [Select] $product_id=$_GET['product']; session_start(); $error=$_SESSION['error']; $content.='<div class="product_information_text review_form"> <div class="review_header">Write a Review for '.$product_name.'</div> <form action="./review_process.php?product='.$product_id.'&p=php" method="POST"> <p class="form_item"><label>Name:</label> <input type="text" name="review_name" size="30"'; if(isset($_SESSION['review_name'])){$content.=' value="'.$_SESSION['review_name'].'"';} $content.=' />'; if($error[0]=="1"){$content.=' <span class="red">This field is required.</span>';} $content.=' </p> <p class="form_item"><label>E-Mail:</label> <input type="text" name="review_email" size="30"'; if(isset($_SESSION['review_email'])){$content.=' value="'.$_SESSION['review_email'].'"';} $content.=' />'; if($error[2]=="1"){$content.=' <span class="red">This field is required.</span>';} $content.=' </p> <p class="form_item"><label>Location:</label> <input type="text" name="review_location" size="30"'; if(isset($_SESSION['review_location'])){$content.=' value="'.$_SESSION['review_location'].'"';} $content.=' />'; if($error[3]=="1"){$content.=' <span class="red">This field is required.</span>';} $content.=' </p> <p class="form_item"><label>Describe Yourself:</label> <input type="text" name="review_describe" size="30"'; if(isset($_SESSION['review_describe'])){$content.=' value="'.$_SESSION['review_describe'].'"';} $content.=' />'; if($error[4]=="1"){$content.=' <span class="red">This field is required.</span>';} $content.=' </p> <p class="form_item"><label>Review Title:</label> <input type="text" name="review_title" size="30"'; if(isset($_SESSION['review_title'])){$content.=' value="'.$_SESSION['review_title'].'"';} $content.=' />'; if($error[1]=="1"){$content.=' <span class="red">This field is required.</span>';} $content.=' </p> <p class="form_item"><label>Best Use of Product:</label> <input type="text" name="review_best_use" size="30"'; if(isset($_SESSION['review_best_use'])){$content.=' value="'.$_SESSION['review_best_use'].'"';} $content.=' />'; if($error[5]=="1"){$content.=' <span class="red">This field is required.</span>';} $content.=' </p> <p class="form_item"><label>Product Pros:</label> <input type="text" name="review_pros" size="30"'; if(isset($_SESSION['review_pros'])){$content.=' value="'.$_SESSION['review_pros'].'"';} $content.=' />'; if($error[6]=="1"){$content.=' <span class="red">This field is required.</span>';} $content.=' </p> <p class="form_item"><label>Product Cons:</label> <input type="text" name="review_cons" size="30"'; if(isset($_SESSION['review_cons'])){$content.=' value="'.$_SESSION['review_cons'].'"';} $content.=' />'; if($error[7]=="1"){$content.=' <span class="red">This field is required.</span>';} $content.=' </p> <p class="form_item"><label>Product Rating:</label><br /> <div class="rating_radio"><input type="radio" name="review_product_rating" value="1"'; if(isset($_SESSION['review_product_rating']) && $_SESSION['review_product_rating']=="1"){$content.='checked';} $content.=' /> <br />1</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="2"'; if(isset($_SESSION['review_product_rating']) && $_SESSION['review_product_rating']=="2"){$content.='checked';} $content.=' /> <br />2</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="3"'; if(isset($_SESSION['review_product_rating']) && $_SESSION['review_product_rating']=="3" || !isset($_SESSION['review_product_rating'])){$content.='checked';} $content.=' /> <br />3</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="4"'; if(isset($_SESSION['review_product_rating']) && $_SESSION['review_product_rating']=="4"){$content.='checked';} $content.=' /> <br />4</div> <div class="rating_radio"><input type="radio" name="review_product_rating" value="5"'; if(isset($_SESSION['review_product_rating']) && $_SESSION['review_product_rating']=="5"){$content.='checked';} $content.=' /> <br />5</div> <div class="worst">(Worst)</div><div class="best">(Best)</div> </p> <p> </p> <p class="form_item"><label>Comments on Product:'; if($error[7]=="1"){$content.=' <span class="red">This field is required.</span>';} $content.=' </label><br /> <textarea name="review_text" rows="10" cols="60">'; if(isset($_SESSION['review_text'])){$content.=$_SESSION['review_text'];} $content.='</textarea> </p> <p><input type="submit" value="Submit" name="Submit" /></p> </form> </div> '; session_unset(); session_destroy(); Code: [Select] session_start(); $product_id=$_GET['product']; $review_name=$_POST['review_name']; $_SESSION['review_name']==$review_name; $review_name = stripslashes($review_name); $review_name = mysql_real_escape_string($review_name); if($review_name==""){ $error0=1; } else{ $error0=0; } $review_title=$_POST['review_title']; $_SESSION['review_title']==$review_title; $review_title = stripslashes($review_title); $review_title = mysql_real_escape_string($review_title); if($review_title==""){ $error1=1; } else{ $error1=0; } $review_email=$_POST['review_email']; $_SESSION['review_email']==$review_email; $review_email = stripslashes($review_email); $review_email = mysql_real_escape_string($review_email); if($review_email==""){ $error2=1; } else{ $error2=0; } $review_location=$_POST['review_location']; $_SESSION['review_location']==$review_location; $review_location = stripslashes($review_location); $review_location = mysql_real_escape_string($review_location); if($review_location==""){ $error3=1; } else{ $error3=0; } $review_describe=$_POST['review_describe']; $_SESSION['review_describe']==$review_describe; $review_describe = stripslashes($review_describe); $review_describe = mysql_real_escape_string($review_describe); if($review_describe==""){ $error4=1; } else{ $error4=0; } $review_best_use=$_POST['review_best_use']; $_SESSION['review_best_use']==$review_best_use; $review_best_use = stripslashes($review_best_use); $review_best_use = mysql_real_escape_string($review_best_use); if($review_best_use==""){ $error5=1; } else{ $error5=0; } $review_pros=$_POST['review_pros']; $_SESSION['review_pros']==$review_pros; $review_pros = stripslashes($review_pros); $review_pros = mysql_real_escape_string($review_pros); if($review_pros==""){ $error6=1; } else{ $error6=0; } $review_cons=$_POST['review_cons']; $_SESSION['review_cons']==$review_cons; $review_cons = stripslashes($review_cons); $review_cons = mysql_real_escape_string($review_cons); if($review_cons==""){ $error7=1; } else{ $error7=0; } $review_product_rating=$_POST['review_product_rating']; $_SESSION['review_product_rating']=$review_product_rating; $review_product_rating = stripslashes($review_product_rating); $review_product_rating = mysql_real_escape_string($review_product_rating); $review_text=$_POST['review_text']; $_SESSION['review_text']==$review_text; $review_text = stripslashes($review_text); $review_text = mysql_real_escape_string($review_text); if($review_text==""){ $error8=1; } else{ $error8=0; } $review_show="n"; date_default_timezone_set('US/Eastern'); $review_date = date("F j, Y, g:i a T"); $error="".$error0."".$error1."".$error2."".$error3."".$error4."".$error5."".$error6."".$error7."".$error8.""; if($_GET['p']=="php"){ if($error!=="000000000"){ $_SESSION['error']=$error; //header("Location: ./store.php?product=".$product_id."&write=review"); echo $_SESSION['review_name']; } else{ $sql="INSERT INTO $tbl_name3 (product_id, review_show, review_title, review_email, review_name, review_location, review_date, review_describe, review_best_use, review_pros, review_cons, review_product_rating, review_text) VALUES ('$product_id', '$review_show', '$review_title', '$review_email', '$review_name', '$review_location', '$review_date', '$review_describe', '$review_best_use', '$review_pros', '$review_cons', '$review_product_rating', '$review_text')"; mysql_query($sql); header("Location: ./store.php?product=".$product_id."&reviews=thankyou"); } } On this second page echo $_SESSION['review_name']; returns nothing, when changed to $_SESSION['review_product_rating']; it returns the rating I selected in the form. I'm probably missing something obvious here. Hi! I am trying to implement the comment feature. After a user selects a recipe from the search results (http://razor.ischool.utexas.edu/~nem/project/index.php scroll down to choose a recipe from the search results), the recipe page is displayed. The user may leave a comment at the bottom of the recipe page if she wishes to. The comment would be recorded in a mysql table and be displayed along with other comments for this particular recipe. The problem is that when the user has entered the comment and name and hits "Add my comment", this error appears: Notice: Undefined index: id in /.../recipeText_w.php on line 57 error retrieving proteins data While I understand it happens because the recipe Id ($_GET['id']) becomes unavailable after the comment and name are submitted, I am not sure how to make the recipe ID available again so that the same recipe page is displayed. The script is attached. I will appreciate your advice. I'm trying to modify code from a book called "PHP with MySQL" where data is read from a MySQL db, edited via a form and written back. It's all technically working but the data is written to the screen from left to right as follows (where the top row is the heading and the second row is the data retrieved from the database in an edit box.): First Name | Last Name | <David> | <Beckham> | I have tons of fields (but only have firstname/lastname in the script for now), so the headings scroll left to right on the screen and I find it really annoying. I'd like things to go top-to-bottom so it looks like this: First Name | <David> Last Name | <Beckham> I've been playing around with the code and trying to add <tr>'s here and there but I can't get it. At best, it looks like this: First Name Last Name <David> <Beckham> I'm hoping it's something simple, but I just can't see it. Any help would be appreciated... the full code is below Code: [Select] # cat editrecord.php <html> <head> <style> body {font-family:arial;} .error {font-weight:bold; color:#FF0000;} </style> <title>Edit Contact Records</title> </head> <body> <h2>Edit Contact Records:</h2> <? //connect to the database include("dbinfo.php"); $link = mysqli_connect($server, $username, $password, $database); // has the form been submitted? if ($_POST) { foreach($_POST as $k => $v) { $v = trim($v); $$k = $v; } // build UPDATE query $update = "UPDATE contact_records SET firstname='$firstname', lastname='$lastname' WHERE Id=$id"; // execute query and check for success if (!mysqli_query($link, $update)) { $msg = "Error updating data"; } else { $msg = "Record successfully updated:"; // write table row confirming data $table_row = ' <tr> <td>' . $firstname . '</td> <td>' . $lastname . '</td> </tr>'; } // if not posted, check that an Id has been passed via the URL } else { if (!IsSet($_GET['id'])) { $msg = "No customer selected!"; } else { $id = $_GET['id']; //build and execute the query $select = "SELECT firstname, lastname FROM contact_records where id=$id"; $result = mysqli_query($link, $select); // check that the record exists if (mysqli_num_rows($result)<1) { $msg = "No customer with that ID found!"; } else { // set vars for form code $form_start = "<form method=\"post\"action=\"" . $_SERVER['PHP_SELF'] . "\">"; $form_end = ' <tr> <td colspan="2"><input type="submit" value="Submit changes" /></td> <td colspan="3"><input type="reset" value="Cancel" /></td> </tr> </form>'; // assign the results to an array while ($row = mysqli_fetch_array($result)) { $firstname = $row['firstname']; $lastname = $row['lastname']; // write table row with form fields $table_row = ' <tr> <td><input type="text" name="firstname" value="' . $firstname . '" size="10" /></td> <td><input type="text" name="lastname" value="' . $lastname . '" size="10" /></td> </tr>'; } // end 'if record exists' if } //end 'if ID given in URL' if } // end 'if form posted' if } // close connection mysqli_close($link); // print error/success message echo (IsSet($msg)) ? "<div class=\"error\">$msg</div>" : ""; ?> <table border="1" cellpadding="5"> <!-- Show start-of-form code if form needed --> <? echo (IsSet($form_start)) ? $form_start : ""; ?> <input type="hidden" name="id" value="<? echo $id ?>" /> <tr> <th>First Name</th> <th>Last Name</th> </tr> <!-- Show appropriate table row code (none set if there were errors) --> <? echo (IsSet($table_row)) ? $table_row : ""; ?> <!-- Show end-of-form code if we are displaying the form --> <? echo (IsSet($form_end)) ? $form_end : ""; ?> </table> <br /><a href="records.php">Back to customer list</a> </body> </html> Before I pull my hair out, can I: form1.html Retrieve 1 record, 5 columns from the db Display that data in a form Allow the user to change any of the column data on the form Use form action update.php, method post update.php use $_POST to capture variables update db My main concern is if the retrieved data will be displayed on the form. Thanks Hi, I have the following script and am using it to display the members username. Ideally I would like the result to be displayed in between the <h2></h2> tags next to Welcome but no matter what I try it wont work. However the information is displayed in the first part of the script. I have indicated the part that correctly displays the information, but how do I display it elsewhere in the page? Code: [Select] <?php session_start(); // This checks to make sure the session variable is registered // WARNING: DO NOT DELETE THE FOLLOWING LINE OF TEXT if( isset($_SESSION['username']) && isset($_SESSION['sid'])) { // You are free to edit the following code to suit your requirements include_once("../../data/server.php"); include_once("../../lib/userdata.php"); // THIS BIT WORKS AND DISPLAYS THE USERNAME $data = mysql_query("SELECT * FROM members") or die(mysql_error()); Print "<table border cellpadding=3>"; while($info = mysql_fetch_array( $data )) { Print "<tr>"; Print "<th>Username:</th> <td>".$info['username'] . "</td> "; //////////////////////////////////////////// PRINT <<<HOME <!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>$siteName</title> <link rel="stylesheet" href="../../userstylesheet.css" type="text/css" /> </head> <div id="page"> <img alt="" src="../../images/leftCurve" height="6" width="6" id="left" /> <img alt="" src="../../images/rightCurve.gif" height="6" width="6" id="right" /> <div id="pageName"> <h1>$siteName</h1> </div> <div id="pageNav"> <div id="sectionLinks"> <a href="index.html">Home</a> <a href="register.html">Register</a> <a href="login.html">Login</a> <a href="search.html">Search</a></div> </div> <div id="content"> <div class="feature"> <h2>Welcome </h2> <p>This is the demonstration home.html template. You are free to edit this or any of the other templates to suit your own needs. </p> <p>This is the first page your member will see once they have logged in. </p> <p>For any information please visit our site http://www.membersitemaker.co.uk. User guides will be added shortly and the forum will soon be full of help. </p> </div> </div> <div id="information"> <a href="#">About Us</a> | <a href="#">Site Map</a> | <a href="#">Privacy Policy</a> | <a href="#">Contact Us</a> | ©2003 $siteName </div> </div> </body> </html> HOME; } // WARNING: DO NOT DELETE THE REST OF THE CODE BELOW } else { // This will redirect the user to the login page if the session variables do not exist header( "Location: ../../../login.html" ); } ?> Many Thanks Paul Hello,
I have managed to find, retrieve and save a file using CURL. But I am having to hard code the file extension, is there a way to find the file extension automatically? (it seems the file extension isn't within the download URL)
(also, is there a way of getting the file name so I can save it as the same filename - that would be great)
Thanks for your help,
Stu
p.s. I've tried the pathinfo($url) function, but that gets information out of the download URL rather than the download file.
$url="http://webmail.WEBSITE.com/src/redirect.php"; $cookie="cookie.txt"; $postdata = "login_username=USERNAME&secretkey=PASSWORD&js_autodetect_results=0&just_logged_in=1"; # get the cookie $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $result = curl_exec ($ch); curl_close($ch); $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //read cookies from here curl_setopt($ch, CURLOPT_URL, "http://webmail.WEBSITE.com/src/right_main.php"); curl_setopt($ch, CURLOPT_HEADER, 0); $result = curl_exec($ch); curl_close($ch); # download file $source = "http://webmail.WEBSITE.com/src/download.php?mailbox=INBOX&passed_id=6475&startMessage=1&override_type0=text&override_type1=html&ent_id=2&absolute_dl=true"; $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //read cookies from here curl_setopt($ch, CURLOPT_URL, $source); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSLVERSION,3); $data = curl_exec ($ch); $error = curl_error($ch); curl_close ($ch); # !!! The line below needs to be automated !!! $destination = "./files/test.html"; $file = fopen($destination, "w+"); fputs($file, $data); fclose($file); Edited by stubarny, 17 June 2014 - 04:46 PM. so ik you cna get a search box to search items or text in a database, but what i want to know is how to manually insert text and images into it example image (imagine its an image) text name - text price how would i do this? Lets say you have a database which is packed with content. How can this be used for SEO purposes? Does Google follow all the links on your site and read the echo and indexing that information. Or does the content in a database need to converted into HTML for Google to be able to read it? I tried using Google Custom Search however it did not display anything in my database. If Google crawled my site and ranked it and then carried out the search using Google Custom Search would it then display using Google Custom Search? I have created an input field on a website for people to subscribe by their email address. The email address is stored in a database. I am using PHPMyAdmin. The email address is successfully working, but I want to prevent duplicate email address to be stored, however, I am having an error. Here are my codes: HTML codes: Code: [Select] <form action="index.php" method="post"> <input type="text" size="25" placeholder="Your email address..." name="enter"/> <input class="submit" type="submit" value="Subscribe" name="subscribe"/> <br/> PHP with Query codes: Code: [Select] <?php if ( $_SERVER['REQUEST_METHOD'] == "POST" ) { $ee = htmlentities($_POST['enter']); if (!preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/',$ee) || empty($ee)){ echo '<p class="fail">Failed...Try again!</p>'; } else { @mysql_connect ('localhost', 'root', '') or die ('A problem has occurred, refresh the page and try again!'); @mysql_select_db ('links') or die ('A problem has occurred, refresh the page and try again!'); $duplicate = "SELECT * FROM `email` WHERE `emailaadress` = '{$ee}'"; $query = "INSERT INTO email (id, emailaddress) VALUES('NULL', '.$ee')"; $result = mysql_query($duplicate); if ( mysql_num_rows ( $result ) > 1) { /* Username already exists */ echo 'Username already exists'; } else { mysql_query($query); echo '<p class="success">Successfully subscribed!</p>'; } } } ?> Error I am having: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\softwareportfolio\index.php on line 68 Can someone help me? Thank Hi, I am hoping I have posted my current problem in the right part of this forum. As it relates to the php code, I presume this is the right place, although it also relates to a mysql database I have too. Ok, here is my problem.... I have two websites, one is a non members site and one is a paid members area site. I had a directory style script made for the non members site and want to use the same script within the members site. I paid for the script to be made and set up, which cost me quite a bit, hence the reason I am copying it all over to my other site too. The script displays thumbnials from the database, 4 across and 3 down (total of 12 thumbs per page), each linking to a URL and each thumb has a title. On the left of the webpage is categories, which when clicked, shows thumbs relating to that specific category, or all etc. The CMS forms allow us to add categories etc. Ok, now my problem is this.. I backed up the original database and created a new database on the members site where I also want this functionality. I copied all the scripts over then chenged the content of the database. On the members site I only want it to display three categories, All, Photos and Videos. So this is quite simple compared to the first site. All seemed to display fine, until I moved all the scripts into the members folder (which is accessed via ccbill). The page displays ok, but it just states "No updates found" as in, no content in the database is found. The base url in the configuration script is set to the top domain, but I have renamed the folders where the thumbs are saved to members/thumbs, but still it isnt working. I also want to change the folder name from its original name of www.domain.com/sites to the new domain.com/updates but nothing works when I try to change it. If anyone can help me out with this, I would be extremely grateful, as the workings of this script are all there, and it seems pointless having to spend hundreds on a new script to be made when the functionality is already there, but just not working right. Thanks so much! I am having a big problem in MySQL and a part in my PHP coding as well. I created a registration form, where the user will have to fill his names, email address, choose a username and so on. I do not want duplicate email address and username in my database, thus, if a user choose either an email address or a username which has already taken, he will be notified. To prevent this duplication, I have set both the email address and username fields as UNIQUE KEY in MySQL. My problems a Even by setting both the username and email address fields as UNIQUE KEY, it is not working as I can register using the same email address or username. How to solve this? I have coded also to prevent this problem of duplicate so that the user will be notified to choose another email or username, but I am having a warning. My PHP codes: Code: [Select] <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['fname']) && isset($_POST['lname'])&& isset($_POST['emailr']) && isset($_POST['user']) && isset($_POST['pass'])) { //Assignng variables $firstname = mysql_real_escape_string($_POST['fname']); $lastname = mysql_real_escape_string($_POST['lname']); $email = mysql_real_escape_string($_POST['emailr']); $uname = mysql_real_escape_string($_POST['user']); $pwd = mysql_real_escape_string($_POST['pass']); $pmd= md5($pwd); //Database $connect = mysql_connect('localhost', 'root', '') or die ('Connection Failed'); mysql_select_db('registration', $connect) or die ('Connection Failed'); //Registration codes if (empty($firstname) || empty($lastname) || empty($email) || empty($uname) || empty($pmd)) { echo '<p class="error">All fields are required to fill!</p>'; return false; } elseif (strlen($firstname) && (strlen($lastname) < '2')) { echo '<p class="error">Invalid first name or last name!</p>'; return false; } elseif (filter_var($firstname, FILTER_VALIDATE_INT) || (filter_var($lastname, FILTER_VALIDATE_INT))) { echo '<p class="error">First name or last name cannot be integers!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Email address not valid!</p>'; return false; } elseif (strlen($uname) && (strlen($pmd) < '6' )) { echo '<p class="error">Username or password must be minimum 6 characters!</p>'; return false; } else { $query = "INSERT INTO login (id, firstname, lastname, emailaddress, username, password) VALUES('', '$firstname', '$lastname', '$email', '$uname', '$pmd')"; mysql_query($query, $connect); if (mysql_num_rows(mysql_query("SELECT * FROM login WHERE emailaddress = '$email' username = '$uname'"))) { echo '<p class="fail">This email or username is already taken!</p>'; } } } } ?> The warning message I am getting: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\miniimagehosting\register.php on line 44 <?php require_once('init.php'); $results = $db->prepare('SELECT file_location, file_type, file_size, id as media_id WHERE id = ? LIMIT 1;'); $results->execute(array($_GET['id'])); while ($row = $results->fetch()) { header('Content-Type: ' . $row['file_type']); header('Content-Length: ' . $row['file_size']); $media_ins = $db->prepare('UPDATE media SET total_clicks = total_clicks + 1 WHERE id = ?'); $media_ins->execute(array($row['id'])); readfile($row['file_location']); }For some reason, putting the header('Content-Type....') causes the UPDATE statement to trigger twice increasing the total_clicks by 2. Commenting out the content-type line causes a single update to occur. init.php contains nothing more than session_start and the database connection. When i comment-out the content-type line the page is blank with no errors or messages. I'm not sure why this is occurring. Hello - I'm opening my website up to visitors for free, and trying to bypass a login screen to go straight into the data content that was appearing after a user logged in. I have an index.php file that included the following code at the beginning: <?php session_start(); include("database.php"); include("login.php"); include("/vservers/skyranks/db_connect.php"); ?> <?header("Cache-control: private"); ?> <html> I deleted the "include("login.php"); line, and was successful at bypassing the username and login screen. However, the page that is supposed to display the data content is incomplete. In fact, it only displays my company's logo. Any ideas as to why the data content is not showing up? Thank you for any help with this, as my php is quite novice at this point. Regards - Joe I've been working on developing a CMS blog and now I'm trying to create a slideshow wit Bootstrap Carousel on the homepage to present the dynamic content (images + text) using the data from table 'posts'. I tested this code, and it only presents one post. I mean, It's not possible to go to the next slide. I want to show all the posts on the slides. *The DB connection is already on the includes. The connection was written on a small file called DB.php Home.php <header> <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li> <li data-target="#carouselExampleIndicators" data-slide-to="1"></li> <li data-target="#carouselExampleIndicators" data-slide-to="2"></li> </ol> <div class="carousel-inner" role="listbox"> <?php // The default SQL query $sql = "SELECT * FROM posts ORDER BY id desc"; $stmt = $ConnectingDB->query($sql); while ($DataRows = $stmt->fetch()) { $Id = $DataRows["id"]; $PostTitle = $DataRows["title"]; $Image = $DataRows["image"]; $PostText = $DataRows["post"]; ?> <!-- Slide --> <div class="carousel-item active" style="background-image: url('uploads/<?php echo $Image; ?>')"> <div class="carousel-caption"> <div class="card-body black"> <h3 class="large-mistral-white"><?php echo $PostTitle; ?></h3> <p class="small-times-white"><?php echo $PostText; ?></p> </div> </div> </div> <?php } ?> </div> <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </header> DB.php <?php $DSN='mysql:host = localhost; dbname=everybody_blog'; $ConnectingDB = new PDO($DSN,'root',''); ?>
Hi. Maybe a tricky question? How do I reflect the content of a column from a database table in a roll down select menu in the browser? Let's say that the content of the table column is: Anna Michael These names should be reflected in this select menu like this: <select name="friends"> <option value="Choose a name">Choose a name</option> <option value="Anna">Anna</option> <option value="Michael">Michael</option> So visitors can choose a name, and thereby turn it into a variable, for reuse in the database. Best regards Morris Hi, I will start off trying to explain what I am trying to make the best I can. What I want to create is a script that gets the gold value from this website: http://www.lbma.org.uk/pages/index.cfm?page_id=46&title=current_statistics and then save it to a variable which I will use to calculate values of different gold karats. Here is the content in bold I need on the website I linked: Quote LONDON GOLD FIXING USD GBP EUR AM 1588.00 1005.127 1251.083 PM 1589.50 1004.741 1249.803 So what help do I need? Well, I don't expect you to figure out the calculating part for me but some help how to get that content pointed out above and save it to a variable is what I would appreciate getting some help with. I don't know much PHP, only some and I have been trying to figure this out for a day now without any success. I suppose php get contents and/or curl should be used here but I don't know how really. I would very much appreciate the help I can get on this. Thank you! At the moment I am creating a search function for my website. The approach I have in mind is a pseudo-PHP database. To give an example: A HTML form will submit the results to a PHP file. HTML FORM - Colour: Black PHP RESULT PAGE - if ($_POST['color'] == 'Black') {readfile("./products/black/*.html");} HTML FORM - Price: <$50 PHP RESULT PAGE - if ($_POST['Price'] == '<$50') {readfile("./products/less50/*.html");} The problem here is if there is an item that is black and costs less than $50, then its going to be listed twice. There is probably some code I can write to ommit the listing of duplicate entries, but it is probably going to be messy, so I am wondering if its better to use a centralized MySQL database, rather than a pseudo-PHP database? I've never used MySQL and don't know much about it and this is my first real attempt at using PHP. hello everyone, I am about to start coding my pages to display results from a database but before i do i want to know information about the following : Is it best to upload images to a database?and display them accordingly? or is it best to use images from a directory? What is most commonly used and or more reliable? Another topic i have trouble finding information on is actually positioning the output from you mysql database, is this practice done with tables?fields and rows? What is this method called? And is there more then one way to go about controlling result layout on your page? Sorry about the 1001 questions , but i am unable to find a clear answer on the topic ..especially question two . Thanks in advance. |