PHP - Help Replacing Hard Coded Values In Sql Statements
Hi all,
I have created a successful registration and login page for what will eventually be a squash league website. I am struggling with the following issue. When a player logs in using their email address and password I want to populate some drop down boxes which are relevant to the person who has just logged in. These drop downs should show all the leagues the logged in user belongs to and the other drop down should show all the players the currently logged in player has ever played against so that they could view a head to head. So my code works but currently I have the id of the player who has logged in hard coded in my sql statements. I'm wondering if anyone can help me so that I can pass in the id of the player who is logged in as obviously the whole site is not going to work with hard coded values. The code is as follows: Code: [Select] <?php include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/magicquotes.inc.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/access.inc.php'; if (!userIsLoggedIn()) { include 'login.html.php'; exit(); } if (!userHasRole('Squash Administrator')) { $error = 'This page is only for Squash Administrators.'; include 'accessdenied.html.php'; exit(); } if(isset($_REQUEST['email'])) { include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; $email = mysqli_real_escape_string($link, $_REQUEST['email']); $sql = "SELECT id, firstname, lastname, email FROM player WHERE email = '$email'"; $result = mysqli_query($link, $sql); if(!$result) { $error = 'Unable to select players firstname from the database.' . mysqli_error($link); include 'error.html.php'; exit(); } while($row = mysqli_fetch_array($result)) { $players[] = array('id' => $row['id'], 'firstname' => $row['firstname'], 'lastname' => $row['lastname'], 'email' => $row['email']); } // //POPULATE THE OPPONENTS DROP DOWN BOX TO SHOW ALL PREVIOUS OPPONENTS // $sqlid = "SELECT id FROM player WHERE email = '$email'"; $playerid = mysqli_query($link, $sqlid); $sql = "SELECT DISTINCT player.firstname, game.player2_id AS opponent_id FROM player INNER JOIN game ON player.id = game.player2_id WHERE player1_id = '$row['id']' UNION SELECT DISTINCT player.firstname, game.player1_id AS opponent_id FROM player INNER JOIN game ON player.id = game.player1_id WHERE player2_id = '$row['id']'"; $result = mysqli_query($link, $sql); if(!$result) { $error = 'Unable to populate the players dropdown from the database.' . mysqli_error($link); include 'error.html.php'; exit(); } while($row = mysqli_fetch_array($result)) { $opponents[] = array('id' => $row['opponent_id'], 'firstname' => $row['firstname']); } include 'squash.html.php'; } ?> Thanks for your help and time in advance. Similar TutorialsHi, I have 2 arrays, named $old_teams1 and $old_teams2. The arrays have from 6 values upwards. If $old_teams1 looks like this: Code: [Select] Array ( [0] => 3 [1] => 4 [2] => 3 [3] => 4 [4] => 1 [5] => 2 ) and $old_teams2 is the has the same mixture of values from 1-4..... .. How do I create a loop that will change all values of $old_teams1 and $old_teams2 to new values such as, 1->3, 2->4, 3->1, 4->2.... (The new values have been randomly generated). Hello, I am currently trying to learn php from a book called PHP for Absolute Beginners where it teaches you how to build a blog by "hand". All nice and good until i got to the submit an entry and save it to my database process. I'm using PDO with INSERT prepared statement like so, from a separate update.inc.php file: Code: [Select] $sql = "INSERT INTO entries (title, entry) VALUES (?,?)"; $stmt = $db->prepare($sql); $stmt -> execute(array($title, $entry)); $stmt ->closeCursor(); I have attached screenshots of my database in mysql. What could be the problem? Remeber I am an "ABSOLUTE BEGINNER" :p . Thank you This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=333553.0 I've coded an error variable thing to help with my login but it doesn't work and I am puzzled to why it does not. (>.<) error codes such as: Code: [Select] <?php /* checks to see if forms are filled in, if not, create a variable that will be used later. if forms are filled in than the variable is nothing and nothing will be echoed therefore passing onto the next if statement and repeating. */ if(!$_POST['username'] | !$_POST['pass']) { $errormessage_didnotfillinform = ('<center>You did not fill in a required field!</center>'); } else{ $errormessage_didnotfillinform = (''); } ?> Code: [Select] <html> <body> <!-- html such as the follow, goes here. --> <div align="center"><b>Log in</b> <form action="" method="post"> <table class="centered" border="0"> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr></table> </form></div> </body> </html> Code: [Select] <?php echo ( $errormessage_didnotfillinform ); if ( $errormessage_didnotfillinform ) == ('') { echo ( $errormessage_accountdoesnotexist ); } if ( $errormessage_accountdoesnotexist ) == ('') { echo ( $errormessage_invalidusernameorpassword ); } ?> I want to move a module, as shown in the attached jpeg. I want to move it to the position illustrated by the arrow, and I want to increase it's height so it fills the space but leaving a border. There is no module in the position that I can use, so I have to adjust the html coding (I presume). Can anyone help me with this? I have searched for help and I don't even know which file I need to change - whether it is the css or the html. Cheers, James. I something like this to happen...
A user has a text field and a button, he enters text in the field and clicks the button it will go to a URL. Once it goes to that URL it has a text field, this field would be automatically completed from what the user typed in at the start. On that URL there is also a button, that is automatically clicked once the text field has been automatically entered.
BUT the user only sees the first page where he entered text in the field and clicked the button. Everything that happens after he clicked that button he cannot see.
Is there a particular phrase you would call this from what is happening? If so, what is it and how would I do it? This probably is hard to understand but I tried :/
Thanks
Hey guys, this is what I'm trying to do. I want to print on the member's profile page, a list of the products he has bought so far. I've come with two solutions: A) add a new field to the products' table, with the ID of every clients that bought that product; B) add a new field to the members table, with the ID of every products he bought; These are pretty similar approaches, but I've no idea on how can this be done. It would look like: Bought: 2, 3, 4, 5, I dont know how to write this data or how to read it. Any idea? Thanks! Sorry this may sound insane. Is there anyway to accomplish this, using paypal you can creat buy it now buttons and whatnot. The problem with these is you set the price of the time when making the button. Is there a way to set the price with php thus creating a dynamic price instead of a static one? I know you can send paypal vars. but is there a way to edit the price? Thanks I hope that makes sense at all Get a hugh problem with a work in school! We are suposed to optimize a website for moblie devices.. Just by using xhtml, css and php. the problem is that I want the meny to just show at the front page for mobile devices.. I konw that I can choos pic with < img > < media="only screen and (min-width: 640px)" src="bild1.jpg" /> < media="only screen and (min-width: 800px)" src="bild2.jpg" /> </ img > is it possible to do a if construct in any point with using media? please help, Im lost. I get the following error: Quote Parse error: syntax error, unexpected ';' in /hermes/web06/b1946/moo.rghollenbeck/index.php on line 35 But here is the only php code on the whole page: . . .more html code above <?php // PHP version: 5.2.12 // MySQL Version: 5.0.77 $link = mysql_connect('path', 'username', 'pword'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db(guestlist); $Users_IP_address = $_SERVER["REMOTE_ADDR"] ; echo "<input type='hidden' name='ip' value="; echo $Users_IP_address; echo ">"; $first_name=mysql_query("SELECT 'fname' FROM tblMain; WHERE 'ip'=" . $Users_IP_address); // pseudocode section: // If $first_name !null{ // echo "Hello " . $first_name; // } // end pseudocode section: // something like that ?> more html code below. . . Thank you. Please delete my other post as I realized it is not what I needed and I cannot delete it myself. Here is exactly what I need. I have X amount of text files (with random names) in each text file there is Y amount of lines with one word on each line. I need to open all X amount of files and take the first line from each and save it in a new txt doc. then take the second line of each and save them to a new text doc. and so on. so I have all the line 1's from all the txt files together and all the line 2's together etc. I hope that makes sense. Ok all I need some help with this. I have been stuck for two days. Basically I have a form that asks a registrant their gender and age, then my script spits out a list of race categories they qualify for. The situation calls for the registrant to be able to register for any category YOUNGER than them, but not older. Screen Shot #1 shows my database setup (this can be changed if you have any better ideas...) that holds the race category information. Here is the sql statement I am using to pull a female racer information, where $race_age is their submitted age. "SELECT * from counts where female=1 and $race_age < age_end and $race_age > age_start" This works, but doesn't pull any categories YOUNGER Than their age. I'm stumpped Thanks for any help in advance. hey guys so I have this code: $result = mysql_query("SELECT * FROM pec_mssgs ORDER BY (y / m) DESC, d ASC"); while($row = mysql_fetch_array($result)) { echo "•<a style='text-decoration: underline; font-weight: bold;' href='../index?id=".$row['id']."'>". $row['m']."/".$row['d']."/".$row['y'] . " - ".$row['title']."</a>"; echo "<br /><br />"; } in my database instead of doing date I have 3 rows d, m, y, which correlate to day, month, year. now currently its echo out a list and sorting by year then month then day this way the events which are happening soonest will be at top. the problem is it shows events that has already passed. what do I do? It will be way to much work to to back and recode the application to just use date. is there a way I can create a var. using my d/m/y then compare that var. to the current date or something? thanks for the help. Hi guys, Here's my problem. My company wants to use SSRS to generate reports. The backend, what stores the data for the report is MS SQL 2005 (and no, I can't upgrade it to 2008, we don't have the licenses for it). When I used one of their examples to login, I got an error stating that the URL, username or password might not be correct. But when I do this, I connect just fine: Code: [Select] $client = new SoapClient("http://sampleURL/reportserver/reportexecution2005.asmx?wsdl", array('login' => "lmaster\SVCWEBDOCS", 'password' => "pdfconverter")); Now, honestly, I don't know much about this and I'm still doing some research, has anyone tried to make this SDK spit out a report? I'd appreciate some guidance/direction as to what to do next. Also, if you could tell me about some of your experiences in getting to work, I'd really appreciate it. I'd like to detect emails that hard bounce after i send out my newsletter, and then delete them from the table that stores them in my database. Any ideas? Thank you. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=328677.0 In ubuntu 18.10 , i created a folder name db in the external usb hard dirve changed the ownership to the www-data the apache2 server and set the permissions to 777 , i run this php code and get the permission error: <php chdir('/media/user/e46cafba-2656-4e42-b1c9-6417f28839df/db/'); system('./rs'); ?> but the php code cannot change to the dir and get the error: [21-Feb-2019 10:43:26 UTC] PHP Warning: chdir(): Permission denied (errno 13) in /home/user/www/html/rse4db.php on line 5
hello, if i have $big=3410 how can i take the last 2 digits of that to make it so that i only get the 10? hope this makes sence. Hi guys. First of, English is not my spoken language so have patience I've google it and done some reading regarding "hard refresh" but i cant find the information i'm looking for. Lets say that i visit a website that i've visit 6 month earlier, and what if they done some changes that require a so called hard refresh. How should people know that the site require a ctrl+5? I mean, i could be visit sites that looks different without my knowledge, that could been changed several month ago? How does it work? Is it manage automatically or is it up to the webmaster to implate some codes like Code: [Select] <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?> I dont know much about site development and i try to learn as much as i can. Is there no better way to handle this. And my second question. Where should i paste codes like this to solve the cache problem? In the header.php? hello, i seem to be stuck again and this bug is difficult for me to solve.
if(isset($_POST['boards'])) $boards[] = $_POST['boards']; $allboards = implode("",$boards[0]); echo $allboards;outputs (browser source)... hello world I have a combobox with the "multiple" property. when two items are selected, the combobox "name" property has an array that passes to the $_POST variable. what i would like is those two words to be displayed on the same line. I have tried rtrim($var, "\r\n") but that does nothing. the reason i need them on the same line is because i would change then to "hello, world" and then add them as a mysql query, for example... $query = "SELECT hello, world FROM table... |