PHP - Database Query And Url Parameters
So I'm creating a website for bar deals... I've tried for hours trying to get the url to take in more than one parameter with no luck, I don't know if my database isn't setup correctly or something but the url would look like this
http://www.site.com/?id=1&day=Monday and when those parameters are passed the deals for that id and day are then posted in the content area I'm pretty much stumped. I feel like it's much easier than I am making it. My database looks like: ID Name Monday Tuesday Wednesday -> and so on 1 Bar1 MondayDeal TuesdayDeal WednesdayDeal 2 Bar2 MondayDeal -> and so on Similar TutorialsHello, I have made some dynamic code that performs a query on the SQL database, I only know that query at run time. However, after reading some more about PHP, I noticed that I need to include the function mysql_real_escape_string before doing this line: @mysql_query( $aStatement); So, how can I read that $aStatement and then call the mysql_real_escape_string function for each needed parameter? Thanks. Hello All, I have created a web application. Unfortunately at development time I forgot to encrypt my query parameter. So generally my apply URL shown like : http://mysite.com/myprofile.php?userId=2 So here any user can guess some other Ids because User Ids are not encrypted in URL. Is there any simple way to do it. I have more than 100 php pages and implementing ecry/decry logic on each page is time consuming So is there any way around? Regards, Prateek I am calling CURL and trying to do a POST request with parameters: Code: [Select] $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Accept: application/json", "Content-Type: application/json")); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_USERAGENT, "curl 7.23.1 (x86_64-unknown-linux-gnu)"); curl_setopt($curl, CURLOPT_USERPWD, "username:password"); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_URL, "https://www.mydomain.com/route"); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, "key1=blah1&key2=blah2"); return curl_exec(curl); The problem, inside the request at http://www.mydomain.com/route I am not seeing any POST parameters passed. I.E. Code: [Select] print_r($_POST); Code: [Select] Array ( ) Should have key1=blah1 and key2=blah2. Any ideas? hello I want query from one table and insert in another table on another domain . each database on one domain name. for example http://www.site.com $con1 and http://www.site1.com $con. can anyone help me? my code is : <?php $dbuser1 = "insert in this database"; $dbpass1 = "insert in this database"; $dbhost1 = "localhost"; $dbname1 = "insert in this database"; // Connecting, selecting database $con1 = mysql_connect($dbhost1, $dbuser1, $dbpass1) or die('Could not connect: ' . mysql_error()); mysql_select_db($dbname1) or die('Could not select database'); $dbuser = "query from this database"; $dbpass = "query from this database"; $dbhost = "localhost"; $dbname = "query from this database"; // Connecting, selecting database $con = mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect: ' . mysql_error()); mysql_select_db($dbname) or die('Could not select database'); //query from database $query = mysql_query("SELECT * FROM `second_content` WHERE CHANGED =0 limit 0,1"); while($row=mysql_fetch_array($query)){ $result=$row[0]; $text=$row[1]."</br>Size:(".$row[4].")"; $alias=$row[2]; $link = '<a target="_blank" href='.$row[3].'>Download</a>'; echo $result; } //insert into database mysql_query("SET NAMES 'utf8'", $con1); $query3= " INSERT INTO `jos_content` (`id`, `title`, `alias`, `) VALUES (NULL, '".$result."', '".$alias."', '')"; if (!mysql_query($query3,$con1)) { die('Error: text add' . mysql_error()); } mysql_close($con); mysql_close($con1); ?> I have some function or method. Is there a better design patter to implement this?
function myFunction($a=null,$b=null,$c=null,$d=null,$e=null,$f=null,$g=null,$h=null) { //Do a bunch of stuff }Maybe the second function? function myNewFunction($data=array()) { $data=array_merge(array('a'=>null,'b'=>null,'c'=>null,'d'=>null,'e'=>null,'f'=>null,'g'=>null,'h'=>null),$array); //Do a bunch of stuff }Please provide decision making factors why you would use one approach over the other. Hello All, Trying to write a log-in script using PDO. But have one question. With the below when I query the database and even run a print_r on $RES nothing is outputted? Any ideas? Thanks if (isset($_POST['Submit'])) { $email = $_POST['email']; $password = $_POST['password']; $QUERY = $dbc->prepare("SELECT email, password FROM tbl WHERE email = :email"); $QUERY->bindParam(':email', $email); $QUERY->execute(); $RES = $QUERY->fetchColumn(); echo "Email is:".$RES['email']; echo "PW is: ".$RES['password']; print_r($RES); } Hello All, This is my first post. I have tried getting some help on the PHP channel in IRC but people there always point you to a reference page. I need actual help and example with my code. Possible someone to show/highlight what I did wrong and then show me the correction. First, my code is supposed to create a form. The form (server_select.php) is a pre-populated form that has a drop down box that queries a table from the database. The form then sends the info to get_disk.php page to post the results of the users selected query options. Here is how it's supposed to work: User goes to webpage.tld/index.php. They click on "Select Server Details" page (server_select.php). A form gets loaded User then has to select from the drop down menu's: server, date range from and to and then hit submit User gets sent to get_disk.php The get_disk.php is supposed to show them all of the following info from their selected server and date range: hostname, device name, device size, current usage, remaining size, percentage used, mount point, time stamp. All of that is supposed to show when they user hits submit. Issue: My submit page seems to work but my "get_disk.php" page doesn't seem to know how to query the database correctly. Attached are both of my files. Can someone tell me why my query on the get_disk.php page is not working and how I get it to display my requested info, please? Is it possible to query my database and display results from a varible that changes each time from a users search? I know how to get results from a variable like a field name and display them but i was wondering if for example; the user searches for criteria and gets the result there looking for (postcode); they then click that result in the browser and are redirected to another page with lots more information.(company_name and location). There result from the original search would be different each time but i would like to know if i could take that result and display all other fields in my table associated with that one result. ***Freelistings*** id company_name location postcode 1 Dave's Storage London PO Box1 2 Steve's Trucks Birmingham WS12 3 3 Sue's Tyres Manchester M14 6 4 Paul's Birmingham WS11 7 ***Basicpackge*** id company_name location postcode 1 Storage Ltd London LN12 5TW 2 Fran's Grit Birmingham WS5 37 3 Raj Walls Manchester M14 60 4 Paul's Light's Birmingham WS12 17 ***Premiumuser*** id company_name location postcode 1 Name1 Location1 PC1 2 Name2 Location2 PC2 3 Name3 Location3 PC3 4 Name4 Location4 PC4 I'm sure this can be done, i'm just getting stuck on how to treat the user's search result. Currently it's called '%$var%'. Can i use: $query = "(SELECT company_name, location FROM freelistings WHERE company_name, location like '%$var%') UNION (SELECT company_name, location FROM basicpackage WHERE company_name, location like '%$var%') UNION (SELECT company_name, location FROM premiumuser WHERE company_name, location like '%$var%') ORDER BY postcode"; So that would be looking at all three tables, getting the details from each field that is associated with that (result) postcode. I hope i have given enough information to explain my problem i'm having. for me quite a tough one? any help would be appreciated, thanks guys in advance! I just did a massive hardware/software upgrade - first new computer (a Mac) in 6 1/2 years, first MAMP upgrade in several years, etc. I'm now using these software versions: Apache 2.2.21, PHP 5.3.6, MySQL 5.5.9 Just about everything seems to be working fine except my database connections. I appear to be making a simple mistake, but I can't figure out the solution. I've checked out all sorts of online help pages, but I'm only getting more confused. Rather than ask what the problem is, it might be better to go back to square one and ask how you would write this query from scratch. I pasted my current, somewhat convoluted code below, to give you an idea of how I was doing it. But here's what I'm trying to do: Imagine a website with a static page at World: MySite/World. It displays dynamic pages, like these: MySite/World/France, MySite/World/Spain...just as long as "France" or "Spain" match values stored in a database table (gw_geog). In my query, I represent France, Spain and other place names with the variable $MyURL. So I want to query that database table. If $MyURL = 'Japan' (e.g. MySite/World/Japan), then $result should = 1, fetching a web page. If $result = 0 (e.g. a misspelled URL, like MySite/World/Japax), then it fetches a 404 error page. If $result = 2 or more (e.g. MySite/World/Georgia - the name of a country and a U.S. state), then it fetches a duplicate note. I wrote this script years ago, when I didn't know much about PHP/MySQL (I still don't), and I've upgraded my software, so I need to start fresh. Can anyone tell me how YOU would a script to accomplish this task? Thanks. * * * * * Code: [Select] <?php // DATABASE CONNECTION $conn = mysql_connect("localhost", "Username", "Password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("db_general")) { echo "Unable to select db_general: " . mysql_error(); exit; } // DATABASE QUERY $sql = " SELECT COUNT(URL) FROM gw_geog WHERE URL = '$MyURL' "; $sql_result = mysql_query($sql,$conn); $result = $sql_result; // DO SOMETHING WITH THE RESULTS switch ($result) { case 1: echo "\n"; include_once($BaseINC."/$MyPHP/inc/B/DB2/Child/World.php"); include_once($BaseINC."/$MyPHP/inc/B/Child2.php"); include_once($BaseINC."/$MyPHP/inc/D/Child.php"); echo "\n"; break; case 0: include_once($BaseINC."/404.php"); break; default: // More than one results, as in Georgia (state and republic) include_once($_SERVER['DOCUMENT_ROOT']."/Dupe.php"); echo "\n"; break; } ?> I have a test database set up that I am working on. Right now, just some names like so firstName lastName companyName I have used phpmyadmin to insert names in the database. Right now just three names are inserted. One first and last name, one first name and one company name I am getting the results back in an associative array. How can I echo out the information with the break tag, or one field at a time? if I use a break tag, then the loop adds in extra blank lines when it gets to the first name and it's null. Can I test for null values and do it that way? I am a beginner so I have no idea what I am doing. Code: [Select] $result = $mysql->query("select * from names") or die($mysql->error); if($result){ while($row = $result->fetch_assoc()){ $name = $row['firstName']; $lastName = $row['lastName']; $company = $row['companyName']; echo $name . " "; echo $lastName . " "; echo $company . " "; } } Hi guys, i am currently working on a project that queries an inventory database through the use of radio buttons, for example; If the first button FOR THE Item(HAMMERS)is clicked, the output should be the name of the item, the number sold and the total profit(calculations) into a table. the way i have it now, when io click on the radio button my output comes back as the results for all the items in the table, i want it to display only the information about hammers, then only about each individual item when the corresponding radio button is clicked. any help would be greatly appreciated!!! in database, I have faced error where query does not responded properly
it was showing the error message that "too much query, user cannot execute more query"....
when I increased the limit, it works for sometime and after sometime, it again generates the error , my question here is:
"why the error is occurring ?"
"what is the correct way to improve the execution of multiple queries at single instance ??? "
Hi I'm using a couple of queries to search a database. This works well but is slow as I'm cascading/nesting the queries.. Below is an example of what I mean... (LDAP queries) Code: Code: [Select] <? $dn = "cn=user"; $filter="(objectclass=user)"; $justthese = array('cn','telephone','guid','ID','email'); $sr=ldap_search($ds, $dn, $filter, $justthese); $info = ldap_get_entries($ds, $sr); for ($n=0; $n<$info['count']; $n++) { $cn = $info[$n]['cn'][0]; $email = $info[$n]['email'][0]; $id= $info[$n]['id'][0]; $dn = "cn=Device"; $filter="(objectclass=device)(userid=$id)"; $justthese = array('cn','system','guid','ID','userid'); $sr=ldap_search($ds, $dn, $filter, $justthese); $info = ldap_get_entries($ds, $sr); for ($n=0; $n<$info['count']; $n++) { $system = $info[$n]['system'][0]; $userid = $info[$n]['userid'][0]; } } ?> I'm sure there's a better way of writing this... that will make it faster. Thanks Working on a website directory that includes ratings for listed companies. Trying to obtain information from database that would put some companies in a higher category than others. Or at least, I believe that is the approach I should be taking.
There are a few tricky issues.
1. Ratings are their own custom posts but are attached to company pages (parents)
2. Rating values I need to obtain are meta keys (1. total number of ratings & 2. rating average of EACH)
3. Ratings are based on four criteria which are summed and averaged for each rating submitted. As a result, values are rarely single digits such as 4 or 5 but include decimals rounded to 1 place (e.g. 4.8 or 3.5)
Additional info:
Ratings are based on 5-star system (out of 5)
Higher category would be business that achieved at least 10 ratings of 4 or more
Any help appreciated.
The title may not fit but only thing i could think of. I am pulling data from MSSQL database table.... I need everything from that table but i need to do some basic math funcitons to the resulting data. So the quesiton is should i do the math for this in the SQL query if so how do i pull all fields and do the math in an effcient way. Or should i let php do the math for me after i get all the data i need. If it is better to use php how can i do this in a while loop and get the math result and not a printed equation. Just looking for a few pointers never had to do math before with php I'm having a problem with adding icon/avatar to my database..this is a submit form where I just submit the avatar url. I don't know how to change the submit link from avatar_add.php?mode=submit to index.php?mode=submit&x=avatar_add. http://www.graphics.allmerk-noplay.com/index.php?x=avatar_add Code: [Select] <?php $host =""; // host name $user =""; // user $pass =""; // password $dbase =""; // database name // connect to the server mysql_connect("$host","$user","$pass"); // and select the database mysql_select_db($dbase); $mode=$_GET["mode"]; // get the mode $QUERY_STRING = 'x=avatar_add'; if(!isset($mode) || empty($mode)) // if mode is empty, switch to case index { $mode='index'; } switch($mode) { case 'index'; // displays the form ?> <form method="post" action="avatar_add.php?mode=submit"> Avatar URL:<br> <input type="text" name="avatar_url" size="30"><br><br> <input type="submit" value="Submit"> <?php break; case 'submit'; // form processing mode $avatar_url=$_POST["avatar_url"]; // check for empty fields if(empty($avatar_url)) { echo "Error! Please go back and fill in all the required fields!"; // if you have a footer include, insert it before the die statement die; // stops the script from executing the rest of the code } // let's get the date in YYYY-MM-DD format $date = date("Y-m-d"); $query="INSERT into icons_db (id,avatar_url) VALUES ('','$avatar_url')"; $result=mysql_query($query) or die ("Couldnot execute query: $query." . mysql_error()); if($result) // if mysql query successful { echo "Thank you! The avatar has been added to or database."; } break; } ?> I'm trying to get a nickname system working for a little project, but I've run into a problem. This code that I wrote here gets the users nickname from their username: Code: (php) [Select] $user = $_GET['user']; @mysql_select_db("db") or die( "Unable to select database"); $query = mysql_query("SELECT `nickname` FROM `info` WHERE `username`='$user'"); WHILE($rows = mysql_fetch_array($query)): $nickname = $rows['nickname']; echo $nickname; endwhile; ?> But the problem is, if the user doesn't have a nickname then it just turns up blank. How can I check if the output of $nickname is blank and if it is then just return their normal name ($user) Thanks Oh, and how to you format php code to look like php code on these forums? Hello every body....
I'm creating a simple php project where the user will be able to choose option from dropdown menu and the query will be executed accordingly..
The html form is shown below....
<select name='movie_name'> <option value='ALL'>All</option> <option value='blah'>Blah blah </option> <option value='blah'>Blah blah </option> ... </select> <select name='movie_genre'> <option value='ALL'>All</option> <option value='Horror'>Horror</option> <option value='Anime'>Anime</option> ... </select> <select name='movie_cast'> <option value='ALL'>All</option> <option value='john'>john</option> <option value='Katrina'>Blah blah Katrina</option> ... </select>If the user select "ALL" then, all the resuls will be displayed according to the selected options AND again If the user select "different" options then, all the resuls matcing from the database will be shown... Tha database schema is shown below | id | movie_name| movie_genre | movie_cast | 1 | Hello Brother | Comedy | Salman Khan | 2 | Blah blah | ALL | Blah blah | 3 | ALL | ALL | ALL | 4 | Blah Blah | Blah Blah | ALL * here "ALL" is a specific text which may or may not be present in the rows.... Thank u in advance.... Hey guys. Wondering if you people could give me some help on a procedural problem i am having. I want to display information from a database. What i am hoping to do is process all of the query and connection in the background. He is how i am doing this. there is a form that submits to the process page with post variables. and in that page there is a few switch statements that change the query and based on that change forwards them to a different page to display the result but the connection and variable name are not being forwarded so the table never gets processed. It is all done in an if statement and switch statemenst any ideas on how to do this properly. I think i am just confused on the procedure of it all. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=314391.0 |