jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
Header errors can explain everything you need to look at. To much to re-type. As for you paganation problems, if this line FAILS. if( $smoke != '' || $drink != '' || $orientation != '' || $religious != '' || $ethnicity != '' || $bodytype != '' ) { Your limit will not be written to the query. You need to move it out of the if statement, so it will be.
-
(PHP) mysql_query SELECT * FROM -Quick Question
jcbones replied to Gregoyle's topic in PHP Coding Help
Anything is possible, but we will need to see how your tables are made. -
There is no better way, and also nothing like learning a new skill. Otherwise this will take multiple queries, and cause your pages to slow down. In the off hand that you want to go with a slower route, you could write separate queries for the likes, dislikes, views, and date_posted tables to run after you insert query finishes. If you wish to create triggers, it is a simple as running this in phpMyAdmin, or similar software. CREATE TRIGGER likes AFTER INSERT ON likes FOR EACH ROW UPDATE `POSTS` SET Popularity = Popularity + 1; CREATE TRIGGER dislikes AFTER INSERT ON dislikes FOR EACH ROW UPDATE `POSTS` SET Popularity = Popularity - 1; ETC, until you have everything calculating how you want. This way, all you have to worry about in the script, is inserting the data to the respective tables.
-
(PHP) mysql_query SELECT * FROM -Quick Question
jcbones replied to Gregoyle's topic in PHP Coding Help
In 55 seconds. -
PHP Post is returning single quote character
jcbones replied to zander1983's topic in PHP Coding Help
Put this script in a file, and include it into all processing scripts. It will strip the slashes automatically. <?php if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { function GPCStrip($arr) { if (is_array($arr)) { foreach ($arr AS $arrKey => $arrVal) { $arr[$arrKey] = GPCStrip($arrVal); } } else if (is_string($arr)) { $arr = stripslashes($arr); } return $arr; } $_GET = GPCStrip($_GET); $_POST = GPCStrip($_POST); $_COOKIE = GPCStrip($_COOKIE); if (is_array($_FILES)) { foreach ($_FILES AS $key => $val) { $_FILES[$key]['tmp_name'] = str_replace('\\', '\\\\', $val['tmp_name']); } } $_FILES = GPCStrip($_FILES); } if (function_exists('set_magic_quotes_runtime')) { set_magic_quotes_runtime(0); } ?> *note* NOT MY SCRIPT, can't remember where it came from, but it is in my library. -
(PHP) mysql_query SELECT * FROM -Quick Question
jcbones replied to Gregoyle's topic in PHP Coding Help
Yes, it is a simple as adding "AND traded='0' ". Parse errors do NOT come from bad MySQL queries, they come from BAD PHP code. Don't make the mistake of thinking they are the same engine, or language. $traderss1=mysql_query("SELECT * FROM `poke_owned` WHERE `box`='1' AND `trainer`='{$trading->username}' AND `traded`='0' ORDER BY `name` ASC"); -
Sorry, I focused on the return part, and left out the other parts. function displayBody($id) { $result = mysql_query("UPDATE skins SET views = views + 1 WHERE id = '$id'"); return true; } Then: $content = (displayBody($id)) ? $extract['title']. ", by ". $extract['username'] ."." : NULL; You ran out of scope with the function, you must put ID into the function scope. As well, the $extract array is out of scope with the function. Since there is no reason to send an argument to the function just to return it, handle the $extracts outside of the function, based on how the function acts. So, we return the function as true, to enable us to decide which string should display.
-
$used = 2.5; $total = 5; $percent = number_format(($used * 100) / $total); echo $percent;
-
It should be: function displayBody() { mysql_query("UPDATE skins SET views = views + 1 WHERE id = '$id'"); return $extract['title']. ", by ". $extract['username'] ."."; } You are then setting $contents to the returned data from the function. HERE: $content = displayBody();
-
Try SUM instead of COUNT. $sql = "SELECT SUM(table2.hits) AS totalhits FROM table1 JOIN table2 ON table2.code=table1.code WHERE table1.user='user1'";
-
WHAT??? Setting the second argument in mysql_fetch_array() has no bearing on what the expected data should return. Rather, it tells the function to return it in an ASSOCiative array, a NUMerical array, or BOTH.
-
How to add integer value to count(*) function
jcbones replied to schult70's topic in PHP Coding Help
Yes, it will work. $hash_query = " SELECT ha.*, COUNT(hr.hasher_id) +1 as total FROM hashers as ha, hash_records as hr WHERE hr.hasher_id = ha.hasher_id GROUP BY hr.hasher_id ORDER BY total DESC "; -
This should get you started. <?php session_start(); $diff = 80; //seconds for timer. //MODIFICATION BELOW THIS LINE IS NOT REQUIRED $hld_diff = $diff; $timestamp = time(); //timestamp. /*********************/ //This block is to handle session held countdowns based on the setting of $diff. if(isset($_SESSION['ts'])) { //if timestamp is active in session $slice = ($timestamp - $_SESSION['ts']); //get the difference between the timestamps. $diff = $diff - $slice; //subtract the diff from the ts. } if(!isset($_SESSION['ts']) || $diff > $hld_diff || $diff < 0) { $diff = $hld_diff; $_SESSION['ts'] = $timestamp; } /*******************/ //Below is demonstration of output. Seconds could be passed to Javascript. $diff; //$diff holds seconds less than 3600 (1 hour); $hours = floor($diff / 3600) . ' : '; $diff = $diff % 3600; $minutes = floor($diff / 60) . ' : '; $diff = $diff % 60; $seconds = $diff; ?> <div id="strclock">Clock Here!</div> <div id="clock">Message Here</div> <script type="text/javascript"> var hour = <?php echo floor($hours); ?>; var min = <?php echo floor($minutes); ?>; var sec = <?php echo floor($seconds); ?> function checkTime() { var time = document.getElementById('strclock').innerHTML; if(time == '00:00:00') { window.location.reload(true); } } function countdown() { if(sec <= 0 && min > 0) { sec = 59; min -= 1; } else if(min <= 0 && sec <= 0) { min = 0; sec = 0; } else { sec -= 1; } if(min <= 0 && hour > 0) { min = 59; hour -= 1; } var pat = /^[0-9]{1}$/; secs = (pat.test(sec) == true) ? '0'+sec : sec; mins = (pat.test(min) == true) ? '0'+min : min; hours = (pat.test(hour) == true) ? '0'+hour : hour; document.getElementById('strclock').innerHTML = hours+":"+mins+":"+secs; if(min >= 1) { document.getElementById('clock').innerHTML = min+1+' minutes until timer runs out!'; } else { document.getElementById('clock').innerHTML = sec+' seconds until timer runs out!'; } //checkTime(); setTimeout("countdown()",1000); } countdown(); </script>
-
User Avatar not uploading even tho its correct image type (.jpg/.png)
jcbones replied to Russia's topic in PHP Coding Help
Be aware that you need to include jpeg and png in the following format for IE: $_FILES["photo"]["type"] == "image/pjpeg" $_FILES["photo"]["type"] == "image/x-png" IIRC Safari passes jpeg as: $_FILES["photo"]["type"] == "image/jpg" Might want to include that as well. -
trying to insert multiple rows into my sql from a php form
jcbones replied to scmeeker's topic in PHP Coding Help
This post is going to assume that you are receiving the data that you expect. Try running this in your add_select.php include('connect.php'); foreach($_POST['item'] as $row=>$item) { $Item_name=mysql_real_escape_string($item); $expiration_date=mysql_real_escape_string($_POST['expiration_date'][$row]); $username=mysql_real_escape_string($_POST['username'][$row]); $query_row[] = "('$item_name','$expiration_date','$username')"; } $sql2="INSERT INTO place (item, expiration_date, username) VALUES " . implode(',',$query_row); if (!mysql_query($sql2)) { die('Error: ' . mysql_error()); }else { header("location:insert_complete.php"); } -
$id is null, because you haven't set it in the first script. Therefore it isn't being passed to the second script. See, there is no ID <? $i=0; while ($i < $num) { $name=mysql_result($result,$i,"name"); $email=mysql_result($result,$i,"email"); $age=mysql_result($result,$i,"age"); $gender=mysql_result($result,$i,"gender"); $location=mysql_result($result,$i,"location"); $homephone=mysql_result($result,$i,"homephone"); $otherphone=mysql_result($result,$i,"otherphone"); $besttime=mysql_result($result,$i,"besttime"); $referrer=mysql_result($result,$i,"referrer"); ?>
-
$table = 'table_name'; $query = "SELECT a.auto FROM $table AS a JOIN $table AS b ON (a.x = b.x AND a.y = b.y AND a.auto != b.auto) ORDER BY a.auto";
-
already spotted the problem. Change: <a href="db_edit.php?id=$id"> To: <a href="db_edit.php?id=<?php echo $id; ?>"> First page displays, so short tags are enabled, although I do agree with darkfreaks that the long tags they should be.
-
Change: $result=mysql_query($query); To: $result=mysql_query($query) or die($query . ' encountered an error <br /><br /> ' . mysql_error());
-
Make sure there are no spaces before the opening <?php tag, nor between any of the other opening/closing tags (better still, take them out).
-
You need to select your database: $con = mysql_connect("localhost",$username,$password); mysql_select_db($database,$con);
-
You cannot retrieve a result from an UPDATE query.
-
What is the code to db_edit.php?
-
I'm trying to point you in a direction that will get your scripts de-bugged, and working in the shortest amount of time possible. The manual simply states that the second argument is optional. Therefore, if you delete the second argument all together, then it will work.
-
Did you try it? mysql_query("INSERT INTO ips VALUES (null, '{$_SERVER['REMOTE_ADDR']}')");