PHP - Table Doesn't Find The Row.
Ultimate goal is for the query to find the row in the database to avoid the validation and carry on with the rest of the script.
What actually happens is the script runs without any parse errors but it doesn't find the row within mysql. $query = sprintf('SELECT name_id, title, description, price, width, height, depth, quantity FROM art WHERE product_code = "$u"', mysql_real_escape_string($product_code, $db)); $result = mysql_query($query, $db)or die(mysql_error($db)); if (mysql_num_rows($result) != 1) { header('Location: home.php'); mysql_free_result($result); mysql_close($db); exit(); } I've echoed the where variable and the mysql_num_rows($result). the where variable is as expected but the result variable comes out as 0. I've checked my phpadmin and there is a entry in there. This worked fine before I sprinted the table. Any help appreciated. Similar TutorialsOk. I have read everything I could find on how to fix this problem...but nothing seems to work. I have some suspect reasons why I think it doesn't work, but I don't know how to fix it. I read the notice about posting "headers already sent" and nothing in there helped me either. I am at my wits end! I have a form that is contained in a left navigation file that is an "include" file for other pages of the website. Here is the code for the left navigation file: Code: [Select] <?php //process the email if (array_key_exists('send', $_POST)) { $to = 'jliss32@gmail.com'; $subject = 'Form Submission from JudeLaw LLC for Bankruptcy'; //list expected fields $expected = array('name', 'street','city', 'phone', 'email', 'time', 'hearaboutus', 'otherwho', 'who', 'needs', 'question'); //set required fields $required = array('name', 'street', 'city', 'phone', 'email'); //create empty array for missing fields $missing = array(); // assume that there is nothing suspect $suspect = false; // create a pattern to locate suspect phrases $pattern = '/Content-Type:|Bcc:|Cc:/i'; // function to check for suspect phrases function isSuspect($val, $pattern, &$suspect) { // if the variable is an array, loop through each element // and pass it recursively back to the same function if (is_array($val)) { foreach ($val as $item) { isSuspect($item, $pattern, $suspect); } } else { // if one of the suspect phrases is found, set Boolean to true if (preg_match($pattern, $val)) { $suspect = true; } } } // check the $_POST array and any sub-arrays for suspect content isSuspect($_POST, $pattern, $suspect); if ($suspect) { $mailSent = false; unset($missing); } else { // process the $_POST variables foreach ($_POST as $key => $value) { //assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); //if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { array_push($missing, $key); } //otherwise, assign to a variable of the same name as $key elseif (in_array($key, $expected)) { ${$key} = $temp; } } } // validate the email address if (!empty($email)) { // regex to ensure no illegal characters in email address $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/'; // reject the email address if it doesn't match if (!preg_match($checkEmail, $email)) { array_push($missing, 'email'); } } // go ahead only if not suspect and all required fields OK if (!$suspect && empty($missing)) { //set default values for variables that might not exist $hearaboutus = isset($hearaboutus) ? $hearaboutus : 'Nothing selected'; $needs = isset($needs) ? $needs : array('None selected'); //build the message $message = "$name\n\n"; $message .= "$street\n\n"; $message .= "$city\n\n"; $message .= "$phone\n\n"; $message .= "$email\n\n"; $message .= "Best time to reach you? $time\n\n"; $message .= "How did you hear about us? $hearaboutus\n\n"; $message .= "Other: $otherwho\n\n"; $message .= "Referred by: $who\n\n"; $message .= 'What do you need? '.implode(', ', $needs). "\n\n"; $message .= "$question\n\n"; //send it $mailSent = mail($to, $subject, $message); if ($mailSent) { // redirect the page with a fully qualified URL header('Location: http://www.judelawllc.com/contact-thank-you-bk.php'); exit; } } } ?> <div id="sidebarItem1"> <p><a href="http://www.referrallist.com/listing/judelaw-llc.html" target="_blank"><img src="http://www.judelawllc.com/images/martinoLogo.gif" width="216" height="168" alt="Tom Martino Referral List" /></a><br /> <br /> <a href="http://www.bbb.org/denver/business-reviews/60075-112/jude-law-llc-90107441" target="_blank"><img src="http://www.justgoodbusiness.biz/logoonline/getimage.php?bid=90107441&c=blue&h=1" width="187" height="83" border="0" title="Click to verify BBB accreditation and to see a BBB report." alt="Click to verify BBB accreditation and to see a BBB report." /></a></p> <p><img src="http://www.judelawllc.com/images/ColoradoBarAssoc_Logo.jpg" width="180" height="40" alt="Colorado Bar Association" /></p> <p><img src="http://www.judelawllc.com/images/nacba-logo.jpg" width="180" height="35" alt="National Association of Consumer Bankruptcy Attorneys" /></p> <!-- start RatePoint Widget - Please, do not change --> <iframe src="//sitetools.ratepoint.com/widget/36561?style=2&color=3&wide=1&number_of_reviews=1&average_rating=1&rotate_reviews=1&show_links=1" width="200" height="204" scrolling="no" frameborder="0" border="0"> </iframe> <p> <!-- end RatePoint Widget - Please, do not change --> </p> <A class=the_url href="http://ratepoint.com/tellus/36561" target=_blank>Rate us and write a review!</A> </div> <div id="sidebarItem4"> <h1 class="FormFill">Fill out the form below...<br /> Get a Call TODAY!</h1> <div id="sidebarItem4Content"> <?php if ($_POST && isset($missing) && !empty($missing)) { ?> <p class="warning">Please complete the missing item(s) indicated.</p> <?php } elseif ($_POST && !$mailSent) { ?> <p class="warning">Sorry, there was a problem sending your message. Please try again later. If you need immediate assistance, please call(303)757-5833! Thank you.</p> <?php } ?> <form id="contact" method="post" action=""> <p> <label for="name">Name:<?php if (isset($missing) && in_array('name', $missing)) { ?> <span class="warning">Please enter your name</span><?php } ?></label><br /> <input name="name" id="name" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['name']).'"'; } ?> /> </p> <p> <label for="street">Street Address:<?php if (isset($missing) && in_array('name', $missing)) { ?> <span class="warning">Please enter your street address</span><?php } ?></label><br /> <input name="street" id="street" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['street']).'"'; } ?> /> </p> <p> <label for="city">City/State/Zip<?php if (isset($missing) && in_array('name', $missing)) { ?> <span class="warning">Please enter your city/state/zip</span><?php } ?></label><br /> <input name="city" id="city" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['city']).'"'; } ?> /> </p> <p> <label for="phone">Phone:<?php if (isset($missing) && in_array('phone', $missing)) { ?> <span class="warning">Please enter your phone number</span><?php } ?></label><br /> <input name="phone" id="phone" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['phone']).'"'; } ?>/> </p> <p> <label for="email">E-mail:<?php if (isset($missing) && in_array('email', $missing)) { ?> <span class="warning">Please enter your email</span><?php } ?></label><br /> <input name="email" id="email" type="text" class="formbox" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['email']).'"'; } ?>/> </p> <p> <label for="select">Best Time To Reach You?</label><br /> <select name="time" id="time"> <option value="No reply" <?php if (!$_POST || $_POST['time'] == 'No reply') { ?> selected="selected" <?php } ?> >Select one</option> <option value="Any" <?php if (isset($missing) && $_POST['time'] == 'Any') { ?> selected="selected" <?php } ?> >Any</option> <option value="Morning" <?php if (isset($missing) && $_POST['time'] == 'Morning') { ?> selected="selected" <?php } ?> >Morning</option> <option value="Afternoon" <?php if (isset($missing) && $_POST['time'] == 'Afternoon') { ?> selected="selected" <?php } ?> >Afternoon</option> <option value="Evening" <?php if (isset($missing) && $_POST['time'] == 'Evening') { ?> selected="selected" <?php } ?> >Evening</option> </select> </p> <fieldset id="hearaboutus"> <p><strong class="FormText">How did you hear about us?</strong></p> <p> <input name ="hearaboutus" type="radio" value="Google" id="google" <?php $OK = isset($_POST['hearaboutus']) ? true:false; if($OK && isset($missing) && $_POST['hearaboutus'] == 'Google') { ?> checked="checked" <?php } ?> /> <label for="google">Google</label> <input name ="hearaboutus" type="radio" value="Yahoo" id="yahoo" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Yahoo') { ?> checked="checked" <?php } ?> /> <label for="yahoo">Yahoo</label> <input name ="hearaboutus" type="radio" value="Bing" id="bing" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Bing') { ?> checked="checked" <?php } ?> /> <label for="bing">Bing</label> <br /> <input name ="hearaboutus" type="radio" value="Tom Martino" id="tommartino" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Tom Martino') { ?> checked="checked" <?php } ?> /> <label for="tommartino">Tom Martino</label> <input name ="hearaboutus" type="radio" value="Craigslist" id="craigslist" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Craigslist') { ?> checked="checked" <?php } ?> /> <label for="craigslist">Craigslist</label> <br /> <input name ="hearaboutus" type="radio" value="Backpage" id="backpage" <?php if($OK && isset($missing) && $_POST['hearaboutus'] == 'Backpage') { ?> checked="checked" <?php } ?> /> <label for="backpage">Backpage</label> <input name ="hearaboutus" type="radio" value="Facebook" id="facebook" <?php if($OK && isset($missing) && $_POST['hearaboutus'] == 'Facebook') { ?> checked="checked" <?php } ?> /> <label for="facebook">Facebook</label> <br /> <input name ="hearaboutus" type="radio" value="AngiesList" id="angieslist" <?php if($OK && isset($missing) && $_POST['hearaboutus'] == 'AngiesList') { ?> checked="checked" <?php } ?> /> <label for="angieslist">Angie's List</label> <br /> <input name ="hearaboutus" type="radio" value="Other" id="othersite" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Other') { ?> checked="checked" <?php } ?> /> <label for="othersite">Other</label><br /> <label for="otherwho">Please tell us where?</label><br /> <input name="otherwho" type="text" class="formbox" id="otherwho" value="" size="22" <?php if (isset($missing)) { echo 'value="'.htmlentities($_post['otherwho']).'"'; } ?>="<?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['otherwho']).'"'; } ?>" /> <br /> <input name ="hearaboutus" type="radio" value="Referral" id="referral" <?php if ($OK && isset($missing) && $_POST['hearaboutus'] == 'Referral') { ?> checked="checked" <?php } ?> /> <label for="referral">Referral</label><br /> <label for="who">Who referred you?</label><br /> <input name="who" type="text" class="formbox" id="who" value="" size="22" <?php if (isset($missing)) { echo 'value="'.htmlentities($_post['who']).'"'; } ?>="<?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['who']).'"'; } ?>" /> </p> </fieldset> <fieldset id="needs"> <p><strong class="FormText">What do you need?</strong></p> <p> <input type="checkbox" name="needs[]" value="I Want a Free Consultation" id="consult" <?php $OK = isset($_POST['needs']) ? true: false; if ($OK && isset($missing) && in_array('Schedule a showing', $_POST['needs'])) { ?> checked="checked" <?php } ?> /> <label for="consult">I Want a Free Consultation</label> <br /> <input type="checkbox" name="needs[]" value="Have a question" id="havequestion" <?php if ($OK && isset($missing) && in_array('Have a question', $_POST['needs'])) { ?> checked="checked" <?php } ?> /> <label for="haveaquestion">I Have A Question</label> </p> </fieldset> <p> <label for="question">How may we help you?</label><br /> <textarea name="question" cols="22" class="formbox" id="question" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['question']).'"'; } ?>"></textarea> </p> <p> <input name="send" id="send" type="submit" value="Send message" /> <input name="reset" id="reset" type="reset" value="Reset Form" /> </p> </form> <br /> </div> </div> Everything worked fine until I wanted to redirect the user to another page for email confirmation. I need to have the user go to a new page so I can use the Google Analytics tracking code for PPC campaigns. So, here is a sample of how this file is included in other pages of the site. I suspect this is the problem, the other pages contain HTML before this file is included. <!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 name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org" /> <title>Thank You! | JudeLaw LLC</title> <meta name="description" content="JudeLaw has a qualified and experienced attorney that practices in all (5) Federal Bankruptcy Courts in Colorado. JudeLaw is the lawyer with the experience that is able to file your case not only in the Denver Bankruptcy Court, but also in Fort Collins, LoveLand, Greeley, Colorado Springs, Grand Junction and Pueblo bankruptcy courts." /> <meta name="keywords" content="about JudeLaw, judelaw, jude law, bankruptcy, personal injury, attorney, lawyer, judelaw employees" /> <!-- STYLES --> <link href="http://www.judelawllc.com/styles/base.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="outerWrapper"> <div id="headerWrapper"><img src="../images/header-logo-01.jpg" width="800" height="137" alt="JudeLaw LLC" /></div> <div id="navWrapper"><?php require ('includes/mainNav.php'); ?></div> <div id="bodyWrapper"> <div id="sidebarWrapper"><?php require ('includes/content-nav-sidebar_thank.php'); ?></div> <div id="contentContainer"> <div id="contentContainerTitle"> <h1>Thank You for contacting us!</h1> </div> <div id="contentContainerBody"> <h5>Your message has been sent.</h5> <p>We will review your inquiry and will be able to help you with your situation very shortly. Thank you for considering Jude Law for your legal needs. <br /><br />If you need immediate assistance, please call 303-757-5833 and someone will be able to assist you. Thank you!</p> <!-- Google Code for contact form thank you Conversion Page --> <script type="text/javascript"> <!-- var google_conversion_id = 1035626379; var google_conversion_language = "en"; var google_conversion_format = "2"; var google_conversion_color = "ffffff"; var google_conversion_label = "9RXqCPXzgwEQi8_p7QM"; var google_conversion_value = 0; if (800.00) { google_conversion_value = 800.00; } //--> </script> <script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js"> </script> <noscript> <div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1035626379/?value=800.00&label=9RXqCPXzgwEQi8_p7QM&guid=ON&script=0"/> </div> </noscript> <SCRIPT> microsoft_adcenterconversion_domainid = 799687; microsoft_adcenterconversion_cp = 5050; microsoft_adcenterconversionparams = new Array(); microsoft_adcenterconversionparams[0] = "dedup=1"; </SCRIPT> <SCRIPT SRC="https://0.r.msn.com/scripts/microsoft_adcenterconversion.js"></SCRIPT> <NOSCRIPT><IMG width=1 height=1 SRC="https://799687.r.msn.com/?type=1&cp=1&dedup=1"/></NOSCRIPT><a href="http://advertising.microsoft.com/MSNadCenter/LearningCenter/adtracker.asp" target="_blank">::adCenter::</a> <SCRIPT language="JavaScript" type="text/javascript"> <!-- Yahoo! Inc. window.ysm_customData = new Object(); window.ysm_customData.conversion = "transId=,currency=,amount="; var ysm_accountid = "1TKLPE8MB57H8SOJHVOE3OU6KOO"; document.write("<SCR" + "IPT language='JavaScript' type='text/javascript' " + "SRC=//" + "srv3.wa.marketingsolutions.yahoo.com" + "/script/ScriptServlet" + "?aid=" + ysm_accountid + "></SCR" + "IPT>"); // --> </SCRIPT> </div> </div> <div class="clear"></div> <div id="footerWrapper"><?php require ('includes/footer.php'); ?></div> </body> </html> Please give me some new ideas on what to try in order to make this work. I just need to have the redirect work so I can still use the code for analytics to track conversions. Thank You! Mod edit: [code] . . . [/code] tags added. Hello, I want to know which is the table in the sql SELECT query. What i have done to take fields : Code: [Select] $temp_sql = strtolower($sql); $pos = stripos($temp_sql, 'select'); $str = substr($temp_sql, $pos); $str_two = substr($str, strlen($start)); $second_pos = stripos($str_two, 'where'); $temp_fields = substr($str_two, 0, $second_pos); $fields = trim($temp_fields); But for table i don't know what to do. After the table can end the string or can be a WHERE or ORDER . Is there any way to take it. Until now i use $temp = explode(' ',$sql); $table= $temp[3]; Thank you Hi guys I am new here I have had a search around and can't really find out how to do this. Its quite difficult for me to explain and I am really new to PHP / mySQL - just starting out really. I hope to learn from doing small projects like this and seeing how it gets done. So I have a mySQL DB with two different tables - one is called "notesnew" the other is called "users". I have modified a common tutorial on how to make a "to do list" for what I am doing here. Basically users can login and post messages on this list as them self. Each user's post appears as a list item, showing their username, the time they posted the message and the message content. The message content, time and owner of the message is stored in the "notesnew" table. The list of user's, their passwords and their "avatar/profile" image URL location is stored in the "users" table. Now I am having trouble getting each user's avatar image from being output next to each of their posts. The part that is confusing me is being able to match up the username's post with their content that is display - because I am posting the user's name along with their post, based on the logged in "session name" as their username. So basically, all the content being listed is being displayed from the "notesnew" table. I need to somehow figure out what each user's profile image is based on what is stored against their entry in the "users" table. Here is the code I have so far. It is not working properly - it displays all content etc, but displays the avatar / image of the last user that has registered. Can anyone help me out here with some code that works, or pointers to try follow? I know the $finduserprofile part is incorrect in the way it goes through all user's and finds their profileimg, and that the image displayed next to each post is therefore incorrect (as it displays the last member to have registered's avatar, but its just that I don't know how else to do what I am trying to do. Code: [Select] <?php //Connect to the database $connection = mysql_connect('localhost', 'zzzz' , 'zzzzzzz'); $selection = mysql_select_db('zzzzz', $connection); $username = $_COOKIE['ID_my_site']; //Was the form submitted? if($_POST['submit']){ //Map the content that was sent by the form a variable. Not necessary but it keeps things tidy. $content = $_POST['content']; //Insert the content into database $ins = mysql_query("INSERT INTO `notesnew` (content, owner, dp_time) VALUES ('$content', '$username', NOW())"); //Redirect the user back to the members or index page header("Location:index.php"); } /*Doesn't matter if the form has been posted or not, show the latest posts*/ //Find all the notes in the database and order them in a descending order (latest post first). $find = mysql_query("SELECT * FROM `notesnew` ORDER BY id DESC"); $finduserprofile = mysql_query("SELECT * FROM `users` ORDER BY id DESC"); //Setup the un-ordered list echo '<ul>'; while($row = mysql_fetch_array($finduserprofile)) { $imagelocation = $row['profileimg']; //Continue looping through all of them while($row = mysql_fetch_array($find)) { $owner = $row['owner']; //For each one, echo a list item giving a link to the delete page with it's id. echo '<li>' . '<img src ="' . $imagelocation . '">' . $row['owner'] . ' said at ' . $row['dp_time'] . ': ' . $row['content'] . ' <a id="' . $row['id'] . '" href="delete.php?id=' . $row['id'] . '"><img src="delete.png" alt="Delete?" /></a></li>'; } } //End the un-ordered list echo '</ul>'; ?> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=350064.0 Hi there I'm trying to work out how I'd go about searching my database for URLs that have been submitted by users that are duplicates. Now this isn't as simple as http://www.example.com/something.php and http://www.example.com/something.php oh no! People have entered links such as http://www.example.com//something.php or http://www.example.com///something.php The script (I didn't write it) currently see's these links as unique, but they're not. They function exactly the same way. Anyone have any advice on how to weed these out? I was thinking maybe a straight forward LIKE '%//%' in the mySQL syntax, but this will bring all URLs up due to the http:// aspect of the link Any feedback would be appreciated! Hi i wrote a find and replace code but my code replace last value of array and skip the first, second.... values in the array. Please give me an idea because i stack with this code. Regards $KeyWord = explode("\n", $RowGetWords['KEYWORDS']); $Replace = explode("\n", $RowGetWords['ReplaceTo']); for($i=0; $i<count($KeyWord); $i++){ $pattern = $KeyWord[$i]; $replace = "<a href=\"" .$URL. "\" target=\"_blank\" >" .$Replace[$i]. "</a>"; $html = str_replace($pattern, $replace, $Row['MessageBody']); } Here is my code so far (I say it's PDO but it pretty much isn't. What is the object here? The database connection? LOL!); $sql = " SELECT SUM(IF(`sent` != 'N' , 1 , 0 )) as 'Emails Sent', SUM(IF(`completed` NOT IN('N','paper') , 1 , 0 )) as 'Completed Electronically', SUM(IF(`completed` = 'paper' , 1 , 0 )) as 'Completed Manually', SUM(IF(`completed` != 'N' , 1 , 0 )) as 'Total Number Completed', SUM(IF(`remindercount` = '1' , 1 , 0 )) as 'Reminder Sent Once', SUM(IF(`remindercount` = '2' , 1 , 0 )) as 'Reminder Sent Twice', SUM(IF(`remindercount` = '3' , 1 , 0 )) as 'Reminder Sent Thrice' FROM `tokens_$survey_id` "; $statement = $dbh->prepare($sql); $statement->execute(); $result = $statement->fetch(PDO::FETCH_OBJ); foreach($result as $key => $value) { echo "<tr> <td>$key</td> <td>$value</td> </tr>"; }This is all well and good if the tokens_$survey_id table is actually there. Sometimes, for a genuine reason, there won't be a tokens table for that particular survey. How do I account for this? At the moment I get an error.. Warning: Invalid argument supplied for foreach() in /var/www/html/index.php on line 149I tried this but I am not satisfied this is correct; if(!$result) { die(); }I don't want the code to die! If I take out the die() statement then this if is ignored for some reason I don't understand. Hi, No matter what I seem to change in my code, I sill get the same error! "Table 'suvoocom_wl.beta' doesn't exist" This is my 'core.php' file; Code: [Select] <?php session_start(); @include ('config.php'); @include ('connect.php'); // ######################################################################### // Check if Writing Lounge is under maintenance, and avoid, if possible $qry="SELECT * FROM fuse_rights WHERE username='".$_SESSION['username']."'"; $result=mysql_query($qry); if($result) { if(mysql_num_rows($result) == 1) { $checks = mysql_fetch_assoc($result); $am = $checks['avoid_maintenance']; } } if(isset($_SESSION['username']) && $am == 0) { $result = mysql_query("SELECT * FROM break") or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { if($row['on'] == 1) { header('location:../maintenance'); exit(); } } } if(isset($_SESSION['username']) && $am == 1) { } else { $result = mysql_query("SELECT * FROM break") or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { if($row['on'] == 1) { header('location:../maintenance'); exit(); } } } // ######################################################################### // Check if Writing Lounge has BETA activated if(!session_is_registered(betaaccess)){ $result = mysql_query("SELECT * FROM beta") or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { if($row['on'] == 1) { header('location:../BETA'); exit(); } } } // ######################################################################### // Check if the user logged in is banned $result = mysql_query("SELECT username FROM bans WHERE username = '".$_SESSION['username']."'") or die(mysql_error()); if (mysql_num_rows($result) > 0) { header('location:../banned'); exit(); } // ######################################################################### // Define the variables Writing Lounge will use later on $remote_ip = $_SERVER[REMOTE_ADDR]; $H = date('H'); $i = date('i'); $s = date('s'); $m = date('m'); $d = date('d'); $Y = date('Y'); $j = date('j'); $n = date('n'); $today = $d; $month = $m; $year = $Y; $date_normal = date('d-m-Y',mktime($m,$d,$Y)); $date_reversed = date('Y-m-d', mktime($m,$d,$y)); $date_full = date('d-m-Y H:i:s',mktime($H,$i,$s,$m,$d,$Y)); $date_time = date('H:i:s',mktime($H,$i,$s)); $date_hc = "".$j."-".$n."-".$Y.""; $regdate = $date_normal; $forumid = strip_slashes($_GET['id']); ?> It's basically the backbone to my website. This is my 'config.php' file; Code: [Select] <?php $sqlhostname = "localhost"; $sqlusername = "suvoocom_wl"; $sqlpassword = "*****"; $sqldb = "suvoocom_wl"; ?> And this is my 'connect.php' file; Code: [Select] <?php mysql_connect("$sqlhostname", "$sqlusername", "$sqlpassword")or die("Unable to connect."); mysql_select_db("$sqldb")or die("Unable to select the database you provided. Either I do not have premission to connect to that database, or the database doesn't exist."); ?> Does anyone have any ideas? :S Thanks! I need to copy a table from one code to another. But I couldn't figure out how to do it properly. Just tried to copy code from one file to another but it doesn't work the same. I need to find where to change the code to show right columns.
https://easyupload.io/maoa9h - zipped cart.php (original code with right table) and review.php (the one that doesn't show right table)
We need to copy the table from cart.php: But it doesn't work. The quantity column doesn't show in review.php - as you can see here https://ibb.co/brP0yy1
When I echo out my variable in the php file it works fine but when I put the variable in a table cell it doesn't echo out. Hi, My site was working fine, but I just switched servers/web hosts and now I'm getting the following errors (in blue). The thing is, I don't get the error if I try to run the query loop after just using 'mysql_select_db' once, but if I use it again to select a different database and then run the query loop, I start getting the error. Code: [Select] mysql_select_db ("database1", $mysql_con); $mysql_query = mysql_query ("SELECT ID FROM someTable1", $mysql_con); $someVar1 = 0; while ($mysql_array = mysql_fetch_array ($mysql_query)) { $someVar1 ++; } ////// The above code gives me no error. But If I then try to select a different database and run a loop in the same way (in the same file), I start getting the below error... mysql_select_db ("database2", $mysql_con); $mysql_query = mysql_query ("SELECT ID FROM someTable2", $mysql_con); $someVar2 = 0; while ($mysql_array = mysql_fetch_array ($mysql_query)) { $someVar2 ++; } Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/snubby5/public_html/coozymcmillan.com/view.php on line 86 So I looked it up and somewhere it told me to add some extra code to handle errors better: Code: [Select] if ($mysql_query === FALSE) { die (mysql_error ()); // TODO: better error handling } But when I do that, I get a different error: Table 'database1.someTable2' doesn't exist It doesn't seem to recognize that I switched databases, and it says 'database1.someTable2' doesn't exist (because it doesn't), when really it should be checking for 'database2.someTable2' (which exists). So to reiterate, I can run the query loop fine after selecting database1, but after that if I select database2, it either gives me the first error, or If I add the 'die' code it gives me the second error. Thanks much! PS: I can get it working if I put everything into one database, but I have multiple websites (which sometimes need to call eachothers' databases) and it would be a huge hassle to cram them all into one database unless I have to. if ($count==1){ header("Location:store.php"); }very simple I have issolated it and it doesn't redirect maybe u can see where my mistake is Hi I downloaded a PHP script, copied at localhost and when I run it, it will not display all results instruction says that Globals should be off in PHP.ini and scripts should work while Globals are off. but I can't find php.ini in XAMPP. I tried xampp/apache/bin but I didn't find php.ini what should I do? Hey, What function / how would I find if a string has something? Say I have a string like: $string = 'Hello their! This is my post :) btw, my name is Justin.'; Say I wanted to find out if my name "Justin" is inside that string.. so: whateverfunction('Justin', $string) So I think you should get my idea now though Thanks a lot! The issue I'm having is that this query won't find a max value record if it has less than 5 votes. It'll only show the results of an entry has 5 or greater votes. Why is that? $contest_id = 5; $category_id = 8; $find_entries = $db->prepare("SELECT entry_id, user_id, votes FROM contest_entries WHERE contest_id = :contest_id AND category_id = :category_id AND e_status = :e_status AND votes = (SELECT MAX(votes) FROM contest_entries) LIMIT 1"); $find_entries->bindParam(':contest_id', $contest_id); $find_entries->bindParam(':category_id', $category_id); $find_entries->bindValue(':e_status', 0); $find_entries->execute(); $result_entries = $find_entries->fetchAll(PDO::FETCH_ASSOC); if(count($result_entries) > 0) { foreach($result_entries as $row) { $entry_id = $row['entry_id']; $user_id = $row['user_id']; $votes = $row['votes']; } echo $entry_id; } else { echo 'nothing'; } Edited June 26, 2019 by imgrooot Hello PHPFreaks, Im looking to make a script that can find sertend text or numbers in mysql database and can change it. The only problem is that the database also contains same text and numbers that dont need to be changed. So only for example within [39,10] the , has to be changed into a . and only between the [ ] Anyone got script for this or can help me make one cause im new to php. Anybody know why I'm getting "Please fill in all fields" error? I put comments in to make it easier Code: [Select] <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Who's Missing?</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2>Someone Missing?</h2> <?php require_once('appvars.php'); require_once('connectvars.php'); if (isset($_POST['submit'])) { // Grab the score data from the POST $name = $_POST['name']; $partner_name = $_POST['partner_name']; $state = $_POST['state']; $photo = $_FILES['photo']['partner_name']; $photo_type = $_FILES['photo']['type']; $photo_size = $_FILES['photo']['size']; if (!empty($name) && !empty($partner_name) && !empty($state) && !empty($photo)) { if ((($photo_type == 'image/gif') || ($photo_type == 'image/jpeg') || ($photo_type == 'image/pjpeg') || ($photo_type == 'image/png')) && ($photo_size > 0) && ($photo_size <= GW_MAXFILESIZE)) { if ($_FILES['photo']['error'] == 0) { // Move the file to temp $target = GW_UPLOADPATH . $photo; if (move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Write to the database $query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$partner_name', '$state', '$photo')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Partner added. Enjoy!</p>'; echo '<p><strong>Name:</strong> ' . $name . '<br />'; echo '<strong>Partner:</strong> ' . $partner_name . '<br />'; echo '<strong>State:</strong> ' . $state . '<br />'; echo '<img src="' . GW_UPLOADPATH . $photo . '" alt="Score image" /></p>'; echo '<p><a href="guitar.php"><< Back to Partners page</a></p>'; // Clear the data to clear the form $name = ""; $partner_name = ""; $state = ""; $photo = ""; mysqli_close($dbc); } else { echo '<p class="error">Sorry, there was a problem uploading your partners photo.</p>'; } } } else { echo '<p class="error">The photo must be a GIF, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 320768) . ' MB in size.</p>'; } // delete the temporary photo image file @unlink($_FILES['photo']['tmp_name']); } else { echo '<p class="error">Please fill in all fields.</p>'; } } ?> <hr /> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo GW_MAXFILESIZE; ?>" /> <label for="name">Name:</label> <input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br /> <label for="partner">Partner:</label> <input type="text" id="partner_name" name="partner_name" value="<?php if (!empty($partner_name)) echo $partner_name; ?>" /><br /> <label for="state">State:</label> <input type="text" id="state" name="state" value="<?php if (!empty($state)) echo $state; ?>" /><br /> <label for="photo">Photo:</label> <input type="file" id="photo" name="photo" /> <hr /> <input type="submit" value="Add Partner" name="submit" /> </form> </body> </html> hello I've some code and I want find and cut url from it using php. this url link between 1 - 5 link. this mean some times 1 URL in the code sometimes 2 url in the code and ... can anyone help me? Code: [Select] MB</div><br/> <br/> <br/> <b><br/> DOWNLOAD<br/> <br/> <a href="http://uploading.com/files/c2182562/LIBERO%252B24%252BLUGLIO%252B2010.pdf/" target="_blank" rel="nofollow">http://uploading.com/files/c2182562/LIBERO%2B24%2BLUGLIO%2B2010.pdf/</a><br/> <br/> <br/> <br/> <br/> <a href="http://rapidshare.com/files/408736098/LIBERO_24_LUGLIO_2010.pdf.html" target="_blank" rel="nofollow">http://rapidshare.com/files/408736098/LIBERO_24_LUGLIO_2010.pdf.html</a></b> </div> <table class='file-express' width='100%'> <tr> <td style='text-align: left; color: #B2AC94; font-size: 3'><br>titletm= LIBERO 24 LUGLIO 2010 LIBERO 24 LUGLIO 2010 :found<br><font color="blue">2</font>http://www.avaxhome.ws/magazines/everyday_practical_electronics_vol_33_no_5_2004.html<br>File exists.dllink'MB</div><br/> <br/> <br/> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <?php // Connect to database================================================== include("connect_db.php"); // sending query =========================================================== $result = mysql_query("SELECT * FROM members Order By last") or die(mysql_error()); if (!$result) { die("Query to show fields from table failed"); } echo "<br />"; echo "<p>MEMBERS LIST</p>"; echo "<table border='10' cellpadding='3' cellspacing='2'>"; echo "<tr><th>First Name</th><th>Last Name</th>><th>Phone</th><th>Email</th></tr>"; // keeps getting the next row until there are no more to get ================ while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table ========================== echo "<tr><td>"; echo $row['first']; echo "</td><td>"; echo $row['last']; echo "</td><td>"; echo $row['phone']; echo "</td><td>"; echo $row['email']; echo "</td></tr>"; } echo "</table>"; ?> </body> </html> This is the output. MEMBERS LIST > First Last Phone Email data data data data ect............................................................... I cannot find where the > (greater than) sign is coming from. There is a space after MEMBERS LIST but I could not get it to work in this display. I'm trying to write a piece that checks to see if something someone posts is a url or if it's just a url in a sentence. Basically, I want it so if someone puts in www.phpfreaks.com (then it does something) but if they put I am on www.phpfreaks.com where are you? (Then it does something else) Like the first one will get the dom of the page and post that, and the second one would just post the sentence with the url in it as a link. So I am getting my post $Post checking if there is a www or .com or .net or .gov in it $find2 = 'www.'; $find3 = '.com'; $find4 = '.net'; $find5 = '.gov'; if((strstr($Post, $find2) ==true)||(strstr($Post, $find3) ==true)||(strstr($Post, $find4) ==true)||(strstr($Post, $find5) ==true)){ then do I explode the whole thing, or what would I do in here with the $Post? some people might put in just phpfreaks.com others might put in http://www.phpfreaks.com and others might put in http://www.phpfreaks.com/forums/index.php?action=post;board=1.0 so I need to find the www. and or .com and find the first space before that, and after that and cut out the middle section, but I'm at a loss. } |