PHP - Checking To See If There Is A Allready That Result In Mysql
hey guys,
i need some help with my php/mysql iplogger. My code: <?php //finds out ip $ip = $_SERVER['REMOTE_ADDR']; //conects to the mysql server $connection = mysql_connect('localhost', 'root', ''); //sellects the database mysql_select_db('iplog', $connection); //looks for duplacute ips $dup = mysql_query("SELECT COUNT(number) FROM logged_ips WHERE ip_address = '$ip'",$connection); $count = mysql_result($dup, 0); //checks to see if there is a duplecate name if ($count == 0){ //inserts the ip in to the database $string = 'INSERT INTO `logged_ips` (`aid`, `ip_address`, `ip_visits`) VALUES (\'' . null . '\', \'' . $ip . '\', \'0\')'; mysql_query($string, $connection); }else{ //adds a visit to the database $string2 = "UPDATE `logged_ips` SET `ip_visits` = '++1' WHERE `ip_address` = $ip LIMIT 0,1"; mysql_query($string2, $connection); } //outputs the ip echo $ip; ?> error: Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\randoms\logger\test.php on line 11 127.0.0.1 It also doesnt put anything in to the mysql database. Please help. Thanks jragon Similar TutorialsOkay I need some help. I want to check a MySQL DB and then if it says 0 then don't do anything if it says anything else echo out what's there. I have tried for about a hour now. Hello, I have a problem. I run this query: $query = "SELECT column1 FROM table WHERE column2='$kk'"; $which = $link1; mysql_query($query,$which); some codes.... It is displaying all data correct but only when $kk exists in column2 and when $kk does not exist, it display blank page. So, i want to do a check before running above query to make sure that $kk exists in column2. How to check it before running query? I got this code
<?php // Check if session is not registered, redirect back to main page. // Put this code in first line of web page. session_start(); if (!isset($_COOKIE["user"])) { header("location:login.php"); } include 'connection.php'; ?> <html> <head> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="HandheldFriendly" content="true"> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>EBS Service Skjema</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <?php include 'menu.php'; echo "<div class=\"bluebox\">"; if (isset($_GET['sted'])) { require_once('graph/jpgraph.php'); require_once('graph/jpgraph_line.php'); include 'connection.php'; // data $sql = mysqli_query($con, "SELECT * FROM diesel WHERE sted = '".$_GET['sted']."' GROUP BY WEEK(dato)"); $ydata = array(); $ydate = array(); while($row = mysqli_fetch_array($sql)) { $ydata[]=$row['krl']; $ydate[]=$row['dato']; } // Create the graph. These two calls are always required $graph = new Graph(600,250); $graph->SetScale('textlin'); $graph->title->Set('Pris Historikk'); $graph->xaxis->title->Set("Dato"); $graph->yaxis->title->Set("Pris"); $graph->xaxis->SetTickLabels($ydate); // Create the linear plot $lineplot=new LinePlot($ydata); $lineplot->SetColor('blue'); //$lineplot->SetFillColor('orange@0.5'); // Add the plot to the graph $graph->Add($lineplot); // Display the graph $graph->Stroke(); } else { echo "Du får ikke tilgang på denne måten."; } echo "</div>"; ?> </body> </html>but I get headers allready sent. I was earlier told to learn and code or make my apps different, but I'm totaly stuck cause I need to make a page with those stats. Not sure how I can make all my code be processed first then put into the html area. Is a function the way to go here ? Thanks for reading and hope someone can enlighten me Is there an alert method for the MySQL database or something similar?
What is the proper way to check if the MySQL database connection is working?
I mean other than "creating" and "retrieving" with "insert" and "select".
Good day dear community. I need to build a function which parses the domain from a url. I have used various ways to parse html sources. But this one is is a bit tricky! See the target i want to parse - it has some invaild Markup: http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=644.0013008534253&SchulAdresseMapDO=194190 well what do you think - can i apply this code here <?php require_once('config.php'); // call config.php for db connection $filename = "url.txt"; // Include the txt file which have urls $each_line = file($filename); foreach($each_line as $line_num => $line) { $line = trim($line); $content = file_get_contents($line); //echo ($content)."<br>"; $pattern = '/<td>(.*?)<\/td>/si'; preg_match_all($pattern,$content,$matches); foreach ($matches[1] as $match) { $match = strip_tags($match); $match = trim($match); //var_dump($match); $sql = mysqli_query("insert into tablename(contents) values ('$match')"); //echo $match; } } ?> well i have to rework the parser-part of this script. I need to parse somway different - since i have other site here. Can anybody help me here to get a better regex - or a better way to parse this site ... Any and all help will be greatly apprecaited. regards db1 How can I check if a returned mysql value is equal to '' i.e. nothing? I keep getting an error where the page won't load because the returned value is '' so i need to check for it Im not sure where to post this but since it includes php il post it here instead of in the mysql forum. ok so, i have a table and i get the values using while($row = mysql_fetch_array($result)){ and then echo them in rows. that works fine but i need to add a class to the last row of my table. I would need somehow to fetch the last row of the array and make it echo something different. Any help is appreciated Thank you hello I'm using this code: Code: [Select] $query="SELECT * FROM `second_content` WHERE CHANGED =0 limit 0,1";to query first row data when I want see it and echo it I recived : Code: [Select] Resource id #2can anyone help me ? thank you Hi, I don't know anything about php and Mysql but I found a tutorial for a shopping cart and everything is working. The only thing is they don't have the email part in the totorial so I'm kind of stuck with my file. Anyone know how to email the resul to me via email with this code? <? include("includes/db.php"); include("includes/functions.php"); if($_REQUEST['command']=='update'){ $name=$_REQUEST['name']; $email=$_REQUEST['email']; $address=$_REQUEST['address']; $phone=$_REQUEST['phone']; $result=mysql_query("insert into customers values('','$name','$email','$address','$phone')"); $customerid=mysql_insert_id(); $date=date('Y-m-d'); $result=mysql_query("insert into orders values('','$date','$customerid')"); $orderid=mysql_insert_id(); $max=count($_SESSION['cart']); for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=$_SESSION['cart'][$i]['qty']; $price=get_price($pid); mysql_query("insert into order_detail values ($orderid,$pid,$q,$price)"); } die('Thank You! your order has been placed!'); } ?> <!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>Billing Info</title> <script language="javascript"> function validate(){ var f=document.form1; if(f.name.value==''){ alert('Your name is required'); f.name.focus(); return false; } f.command.value='update'; f.submit(); } </script> </head> <body> <form name="form1" onsubmit="return validate()"> <input type="hidden" name="command" /> <div align="center"> <h1 align="center">Billing information</h1> <table border="0" cellpadding="2px"> <tr><td>Total:</td><td><?=get_order_total()?></td></tr> <tr><td>Name :</td><td><input type="text" name="name" /></td></tr> <tr><td>Address :</td><td><input type="text" name="address" /></td></tr> <tr><td>Email :</td><td><input type="text" name="email" /></td></tr> <tr><td>Phone :</td><td><input type="text" name="phone" /></td></tr> <tr><td> </td><td><input type="submit" value="Place Order" /></td></tr> </table> </div> </form> </body> </html> Hello, i created this script for a client and have ran into an annoying error with the results displaying on a new line for each result instead of side by side, any help is welcome Cheers Code: [Select] <?php $subcat = mysql_real_escape_string(strip_tags(htmlspecialchars(protect($_GET['subcat'])))); $cat = mysql_real_escape_string(strip_tags(htmlspecialchars(protect($_GET['cat'])))); $sql = @mysql_query("SELECT * FROM cakes WHERE category =\"$cat\" AND sub_cat=\"$subcat\" ORDER BY id DESC"); while ($row = mysql_fetch_array($sql)) { $reference = $row['reference']; $image = $row['image']; echo ("<p><img src='./images/cakes/$image' height='289px' width='177px' alt='IMAGE OF CAKE'></img><br />"); echo ("<b>Reference:</b>$reference"."</p>"); } if (!$reference) { echo 'There are no cakes in this category yet.'; } ?> I know the errors only going to be something small i'm missing, but i've been coding all day I am getting the row results from mysql as called, but they appear as a straight line instead of new table row when I echo like: echo "TABLETABLETABLETABLE"; I am looking for: echo "TABLE TABLE TABLE TABLE"; Here is my code: Code: [Select] $brand = $_POST['brand']; $city = stripslashes($_POST['city']); $state = $_POST['state']; $zip_code = stripslashes($_POST['zip_code']); if($city !=""){ $query = "SELECT name, bus_type, street, city, state, zip_code, brand, quantity, price1, price2, date FROM `prices` WHERE city ='".$city."' AND state ='".$state."' AND brand = '".$brand."'"; }else{ $query = "SELECT name, bus_type, street, city, state, zip_code, brand, quantity, price1, price2, date FROM `prices` WHERE zip_code ='".$zip_code."'"; } $result = mysql_query($query); $count=mysql_num_rows($result); if($count==0 && $zip_code !=""){?> <td width="100%" class="style9">Sorry! There are no results for that city, state and brand.</td> <? }else{ while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ ?> <td width="100%" class="style9"><?php echo "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td{$typ_image}</td> <td><b><a href=\"\" title=\"{$row['street']} {$row['city']}, {$row['state']}. {$row['zip_code']}\" target=\"_blank\">{$row['name']}</a></b><br>Last Updated:{$row['date']}</td> <td><b>{$row['brand']} - {$row['quantity']}</b><br>Before Tax:\${$row['price1']} After Tax:\${$row['price2']}</td> <td{$pago}</td> </tr> </table><BR>"; ?></td> <?php } } ?></table> <p> </p> </td> Hi, I am new to php but not to programming. I created a script on a windows platform which connects to the mysql database and returns the results of a table. A very basic script which I wrote to simply test my connection worked. The script works fine on my windows machine but not on my new mac. On the mac it simply does not display any records at all. I know that the database connection has been established because there is no error but I can not see why the result set is not being displayed on screen, as I said it worked fine on my windows machine. The Mac has mysql (with data) and apache running for php. Please could someone help as I have no idea what to do now? Script below: Code: [Select] $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'root'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'test'; mysql_select_db($dbname); mysql_select_db("test", $conn); $result = mysql_query("SELECT * FROM new_table"); while($row = mysql_fetch_array($result)) { echo $row['test1'] . " " . $row['test2'] . " " . $row['test3']; echo "<br />"; } mysql_close($con); Hi, I'm trying to make a mysql output to a link so the name will be a link so when you hit this link you will get the full information of this mysql input. Can someone point me in the correct direction? Here is how i get the output from my mysql database into my table. Code: [Select] <td>"; echo $row['name']; echo "</td> I am seeking to learn more about the noted subject, how to use PHP to allow a user to enter search terms and search a database. I have experimented with this with little results save for errors. Please see code listed below: search.php <? //// filename = search.php <form method="post" action="result.php3"> <select name="metode" size="1"> <option value="row_name1">metode1</option> <option value="row_name2">metode2</option> </select> <input type="text" name="search" size="25"> <input type="submit" value="Begin Searching!!"> </form> ?> results.php //// filename = result.php3 <? $hostname = "mysql7.000webhost.com"; // Usually localhost. $username = "a4542527_root"; // If you have no username, leave this space empty. $password = "*******"; // The same applies here. $usertable = "people"; // This is the table you made. $dbName = "a4542527_test1"; // This is the main database you connect to. MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); @mysql_select_db( "$dbName") or die( "Unable to select database"); ?> <? //error message (not found message) $XX = "No Record Found"; $query = mysql_query("SELECT * FROM $usertable WHERE $metode LIKE '%$search%' LIMIT 0, 30 "); while ($row = mysql_fetch_array($query)) { $variable1=$row["row_name1"]; $variable2=$row["row_name2"]; $variable3=$row["row_name3"]; print ("this is for $variable1, and this print the variable2 end so on..."); } //below this is the function for no record!! if (!$variable1) { print ("$XX"); } //end ?> Upon viewing search.php I receive the error message: Parse error: syntax error, unexpected '<' in /home/a4542527/public_html/search.php on line 3 I believe I may be missing something and am a bit lost. Thank-you in in advance for any help or suggestions. ~Matty Hey guys, Currently Im using: $row = mysql_fetch_array($result) or die(mysql_error()); echo $row['user_family']. " - ". $row['user_registered']; $row['user_family'] = $fam; $_SESSION['family'] = $fam; to take data from a mysql table & set it as SESSION family. However, I cant seem to get this to set. The information IS being taken from mysql because its being echo'd earlier up in the code, but its just not passing to the session. Any ideas? im getting an error: Warning: mysql_fetch_array() [function.mysql-fetch-array]: The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH. in C:\www\library\mysql.class.php on line 353 $result_type = "MYSQL_ASSOC"; $row = mysql_fetch_array($result, $result_type) but if i use (below) it works fine...is the constant() function the right way to what im doing? $result_type = "MYSQL_ASSOC"; $row = mysql_fetch_array($result, constant($result_type)) thank you I am having a little bit of trouble with this piece of code. I'm sure it's something simple, but I have been working on this thing all day and want to get it finally finished. Here's the troublesome code: function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); } } reset($objects); rmdir($dir); } } $sql_clean = "SELECT * complete WHERE createdate < date_sub(current_date, interval 1 minute)"; $sql_list = mysql_query($sql_clean); while($row = mysql_fetch_assoc($sql_list)) { $directory = "complete/" . $row['fileurl']; rrmdir($directory); } The purpose of this particular bit is to run on a cron every few days. It gets "createdate" and other info from the "complete" table in order to know how old the record is. If the record is older than (in the example, 1 minute; it will be set to several days on public) the defined max age, it removes that directory and everything within it to keep the directory clean and the disk usage down. The error returned is Quote Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home1/latenit2/public_html/kindleprocessor/process/garbagecleaner.php on line 46 Line 46 is Quote while($row = mysql_fetch_assoc($sql_list)) { I may be doing the look-up on the MySQL database incorrectly, too. I haven't discounted that, and I'd be thankful if someone could help me out with this issue. Hello Everyone, I have a quick question for you all, I think its fairly simple... I have created a database and I am using PHP to grab the data: $usera = $_SESSION['username']; $query2 = "SELECT * FROM tracker WHERE id = '$usera', hidden = yes"; mysql_query($query2) or die('Error, query failed : ' . mysql_error()); This hopefully will return multiple rows which look like this in the database. id username date reps hidden 1 supremebeing 2011-01-02 30 yes 4 supremebeing 2011-04-02 46 yes How would i turn each result into a variable eg: $date1 = 2011-01-02; $date2 = 2011-04-02; $reps1 = 30; $reps2 = 46; I think i have explained that well enough for you to understand, please reply if not though and i will provide more information. Thanks in Advance |