PHP - A Mysql Function Does Not Produce An Exploitable Value In A Php Script
$sqlresdays="SELECT DATEDIFF(CURDATE(),MAKEDATE(YEAR(CURDATE()),1)) AS date_difference"; When running the sql request raw, no problem, date_difference shows the right number but in the script nothing is echo'd. Thanks for clues on how to resolve this. Similar TutorialsHey guys, I'm building an E-commerce store for a T-Shirt selling company, I've assembled the shopping cart etc correctly but I am having problems within building a forum based system for the site admin to post Bulletins and Notices to the homepage + a blogging page. I am using a while loop which should iterate the results at the end of each cycle through my variable $postResult Here is my code... <?php include_once "../scripts/db_connect.php"; // Connect to the database // Get the section ID from the url variable coming in $sqlout = mysql_query("SELECT * FROM blog_posts ORDER BY ordered ASC LIMIT 10"); if (isset($_GET['id']) && $_GET['id'] != "") { $sid = preg_replace('#[^0-9]#i', '', $_GET['id']); // filter all characters except numbers for security } else { echo "ERROR: Variables to run this script have been removed from the URL."; exit(); } // Query the database for that section id, make sure it exists and get the section title $sql = mysql_query("SELECT * FROM blog_category WHERE forum_id='$sid' LIMIT 1"); $numRows = mysql_num_rows($sql); if ($numRows < 1) { echo "ERROR: That section deos not exist you have tampered with our URLs."; exit(); } while($row = mysql_fetch_array($sql)){ $sectionTitle = $row["forum_title"]; } // Use the section ID to query the "forum_posts" table in the database to get all the threads for this section $sql = mysql_query("SELECT * FROM blog_posts WHERE type='a' AND section_id='$sid' ORDER BY date_time DESC LIMIT 10"); $postResult = ''; $numRows = mysql_num_rows($sql); if ($numRows < 1) { $postResult = "There are no threads in this section yet. You can be the first to post."; } else { while($row = mysql_fetch_array($sql)){ $thread_id = $row["id"]; $post_author = $row["post_author"]; $post_author_id = $row["post_author_id"]; $date_time = $row["date_time"]; $convertedTime = ($myAgoObject -> convert_datetime($date_time)); $whenPost = ($myAgoObject -> makeAgo($convertedTime)); $thread_title = $row["thread_title"]; $dynamicList .= '<img src="style/threadPic.jpg" width="26" height="18" alt="Topic" /> ' . $post_author . ' - <a href="view_thread.php?id=' . $thread_id . '">' . $thread_title . '</a> - ' . $whenPost . '<br />'; } } ?> And here is a snippet of where I echo the results in my HTML: <br /><br /> <div style="margin-left:12px; "><?php echo $postResult; ?></div> <br /><br /><br /></td> I have been slaving over this for hours now, the first $postResult variable will always iterate its text of "There are no threads in this section yet. You can be the first to post.", I can't see anything wrong in my SQL syntax as I have a similar set up to iterate my products to different pages and that has always worked fine Any input on this would be great Kind Regards Alex. Hi there,
My friend asked me to help him perform a task today and I was completely stumped as to how I should complete it. Being someone who is reasonably experienced with PHP programming I didn't think I would find it absolutely impossible to complete, maybe hard, but not impossible. So I wondered if someone would now be able to explain to me in order to assist me in expanding my knowledge how to complete this task.
https://www.dropbox....B8M6cr_z7a?dl=0
Here is a link to the files he sent me, please ignore the C++ section.
If anyone could help / begin to give an explanation please fire away. I feel so bad about myself for NOT knowing that I'm now motivated to learn more!
Many thanks!
im trying to write a simple script. Pretty much to scrape a page content. maybe you can help me. This is what i got so far <?php $url = 'http://www.solecollector.com/forums/memberlist.php'; $output = file_get_contents($url); echo $output; ?> which works good. Now how could i have it navigate to the next page and run the script again, and do so untill it reaches the last page. Any help its appreciated or point me on the right direction. Why doesn't this code update two mysql databases (on two servers)? What am I doing wrong? //SERVER 1 $link = mysql_connect("localhost","usern1","pw1"); mysql_select_db("db_one1"); //SERVER 2 $link = mysql_connect("xxx.xxx.xx.xxx","usern2","pw2"); mysql_select_db("db_one2"); $query = "INSERT INTO db1(subject, search, News, img) VALUES('$hsubject','$key','$news','$img')"; $result = mysql_query($query); $query = "INSERT INTO db2(subject, search, News, img) VALUES('$hsubject','$key','$news','$img')"; $result = mysql_query($query); $sentOk = "The data has been added to the database."; echo "sentOk=" . $sentOk; I had another thread about a problem I was having where it's not loading from the DB right aways. My solution is to make an update function and then have the id's calling it on the page. So the thing I am wondering is how to make a working update function. I have this so far: <?php include blah.... $uid = $_SESSION["user"][0]; $avatarid = $_SESSION["user"][12]; function update($str) { global $db_id; $query="select ".$str." from users where id=".$uid; $result=mysql_query($query, $db_id); $row=mysql_fetch_row($result); return $row[0]; } ?> and then it's being called on the profile page with <?php echo update($avatarid); ?>. I want the update() function to select avatar from users where id = userid and then return the value fresh so it's getting it new from the database every time they refresh the page. Then there won't be a problem with updating old avatar stuff. Currently gives me the error: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/root/public_html/func.php on line 69 So what am I doing wrong here? thanks for anyone who can help I'm pretty sure there isn't, but I was wondering if there was a php function that would return partial matches similar to MySQL's LIKE, I've been searching for a while and haven't found one. If not, is there a class or something that someone knows of that will accomplish a like of search or a string comparison? I want to be able to compare two variables and return one of three results - Exact Match, Partial Match, No Match. I suppose regex may do the trick but I'm a complete novice when it comes to regex and I have no idea where to even begin. Thanks for any suggestions. Hello PHPFreaks. I have one problem, that I've tried to fix for a day or two now. I need a function, that picks out a random row in a table, and returns one thing. I tried with, getting the max rows in the table, make a random number in the interval 0 to max rows, then select the random number, but it failed. I hope someone can help me out with this one? -Niixie This is my code, and I know it's pretty messy, because i fooled around with it for a day or two, so it's hard to find head or tail in it. Code: [Select] $query0 = sprintf("SELECT * FROM registertest"); $result = mysql_query($query0); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } $nums = mysql_num_rows($result); $rand_nums = rand(0,$nums); $query1 = sprintf("SELECT question FROM registertest WHERE id='%i'", $rand_nums); $result1 = mysql_query($query1) or die(mysql_error()); if (!$result1) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } $row = mysql_fetch_row($result1); mysql_free_result($result); mysql_free_result($result1); $_SESSION['registerquestion'] = $row; if(strlen($_SESSION['registerquestion'])!=0){return 1;}else{return 0;} Okay, I have been following this tutorial: http://www.freewebmasterhelp.com/tutorials/phpmysql/1 to achieve exactly what I wanted to get done. I also followed the way to have it formatted in tables and added extra columns that I needed, included an "Options" column which houses three links, including "edit" and "delete" Now, I have everything working fine but I am stumped on how to get the "edit" and "delete" links to work for each individual entry that is listed. I have to have these features so the entries can be edited and deleted without having to physically go into the MySQL database to do it. The tutorial explains how to do it in Step 6, but I am confused. I'm not quite sure where to place the code for the links, which are generated automatically every time a new entry is inputted into the database. Anybody available to help me out? Thanks! I have created a function to connect to a required database with a username and password. I have called this db_openConnection() Now for each function that requires a select from a database is it ok just to call the db_OpenConnection() first within the function or should i be keeping open a db connection (using persist, i think) rather than keep creating a connection. I know that the connection ends when you have finished a query any how. Not sure if this is the correct forum or if it should be mysql forum I hope I'm not being a vampire here sucking the life out of you guys, but I can't find any resources in google that explains how to properly use this function in a mysql array. All it does is add a url for any urls added in plaintext. Code: --- <?php function hyperlink ($string) { $string = preg_replace('#(^|\s)([a-z]+://([^\s\w/]?[\w/])*)#is', '\\1<a href="\\2" target="_blank">\\2</a>', $string); $string = preg_replace('#(^|\s)((www|ftp)\.([^\s\w/]?[\w/])*)#is', '\\1<a href="http://\\2" target="_blank">\\2</a>', $string); $string = preg_replace('#(^|\s)(([a-z0-9._%+-]+)@(([.-]?[a-z0-9])*))#is', '\\1<a href="mailto:\\2">\\2</a>', $string); return $string; } // mysql connection $result = mysql_query("SELECT * FROM top_web_articles ORDER BY ID DESC"); echo "<table border='0'>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>".$row['Category']."</td></tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>". $row['ArticleName'] ."</td></tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>"hyperlink(. $row['ArticleDescription'] .);"</td></tr>"; echo "<tr><td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'><a href='". $row['URL'] . "' target='_blank'><img src='http://www.thenewsguys.ca/images/read entire article.png' alt='' width='130' height='11' border='0' /></a></td>"; echo "</tr>"; echo "<td align='left' valign='top'> </td>"; } echo "</table>"; mysql_close($con); ?> --- Error: "Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/doofyd5/public_html/trevor/playground/displayarticles.php on line 146" (Clearly an error where I'm abusing the heck out of the bolded line. Any ideas on how to properly code this? So I have a basic search form that goes through and does a mySQL like '%$sanitizedInput%' to column in the table. The problem I have is that if I have two rows, one with a value "green" and the second "blue", and I do a search for "green", it shows the green result, if I do a search for "blue", it shows the blue result, but if i do a search for "green blue" it returns no results. Any ideas on how to fix this? Hi, Doing a Query SELECT * FROM table WHERE field BETWEEN low_number AND high_number If i have three rows with three numbers: IE: 27, 50, 80. and i run the query above, it returns a result of: 27 and 50. How can i get it to return a result of: 27,50, and 80.?? WHY: age range search: i want to return an age range of people = and between the age of say: 20 and 70 but i want to include the 20 and 70. How can i do this? How can i put an variable for example
$variable = 'something';
and then how do i put this into this js script
<script>$(document).ready(function() {$('#open$variable').dataTable();});</script> note: Im trying to put this '$variable' inside ' ' right after #open.
Hello: I have this snippet of code that will write the current year onto a page if it's embedded on the page itself: Code: [Select] <?php echo date("Y") ?> Works fine. But, when I include it in an included file and pull it onto the page with a function, it does not work. Like this: MyNav.php Code: [Select] <?php function spFooter() { $spFooter = " <p> © <?php echo date(\"Y\") ?> </p> "; return $spFooter; } ?> MyPage.php Code: [Select] <?php include('include/myNav.php'); ?> <html> ... <?php echo spFooter(); ?> ... </html> What is the proper way to do this, and also what are the basic rules for properly nesting PHP scripts like this? Thanks for the help. Hi, I have exactly the same script and same php.ini file like this website : https://translatesubtitles.com and as you can see the proccess of that php website is: upload srt file redirection to translate.php file where the uploaded text is shown in the table my website script is : https://translatesubtitles.co and when I try to upload srt file it redirected me to the translate.php page but there is no text shown in the table, so what can be the problem? Hi, Can anyone help me with a script, I have tried a if statement but I cannot get it to work and its driving me mad. Basically I have a string my website uses to get if the user is logged in what their username is and I want it so when they click a certain link it checks to see if a table all ready exists called their username, if it does it displays a message, if it doesnt it creates the table and if the username is "anonymous" is displays a message. So in short: if $username is the same as a table display "Table all ready exists" if $username="anonymous" display "You must be logged int" if $username not the same as a table then create table. Many thanks in advance Jay
Looking for help with a small task for my weather station website.
Want to see on my website a table with current temperature or other types of measurements for each hour. A small fee is usually given.
the website:
Examples of desired solutions:
Hi Guys I don't know if this is possible but can someone point me in the right direction. I have a php function which takes two inputs and returns an output. for simplicity's sake let's say it's an addition function. What I want to do is use a mysql select statement to show all the rows from a database where field1 and field2 equal '3'. Here's the sort of thing I mean. function addNumbers($one,$two) { return $one + $two; } mysql_query("SELECT * FROM table WHERE 'addNumbers(field1,field2)' = '3'"); What I actually want to do is a lot more complex than this but I am trying to understand how to make the syntax work in simple terms first. Can anybody help? Many Thanks Dan Let's say I have a mysql table named 'function' and a field named 'body' with 1 row. The 'body' field contains 'Echo out the number 1000 with a comma. ".number_format(1000).". Simple Example.' As you can see there is a function; number_format(); in the database, but is it possible to execute it onto a live webpage and be displayed correctly? |