Jump to content

freshrod

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Everything posted by freshrod

  1. I posted this before in nOOb, but really didn't get it figured out. It's really puzzling me. Basically I have a value in a DB field that I want to check. The column is set up like this: 'alumInfo enum ('0','1') NOT NULL default='0', I query it like this: $sql = mysql_query ("SELECT alumInfo FROM users WHERE username='$username' AND password='$password'"); Then I want to check what the value is. If it's 0 I want to print one thing, if it's 1 I want to print something else. I've tried something like this: $row = mysql_fetch_array($sql); // I'm thinking the problem lies here... if($row['alumInfo'] == '0') { echo "one thing"; } else { echo "something else"; } It seems to ignore the first 'echo' and only prints the last one, even though the default value is '0'. Any suggestions? Thanks. I know there is data in the field from looking with my MySQL Command Line, but: echo '<p>alumInfo is: ',$row['alumInfo'],'<p>'; gave me no result. So possible I'm doing the query wrong? Or is it the mysql_fetch_array? Thanks.
  2. Maybe I'm asking the wrong question. Is there a better way to run a query, check the data, and run an if/else of it? Maybe my problem lies in my approach? Or the way I'm writing the query?
  3. Thanx Ober. When I run (SELECT * FROM users;) it shows a 0 in the field. I really don't know what the deal is. I've used similar querys and such before... never had this much trouble.
  4. Thanx for the help thorpe, but it still isn't showing the echo? I pasted the code in that you put. I really don't understand what the problem is.
  5. I posted about this before and got an answer, but while it did stop the error, it still isn't working how I wanted. Basically I have a value in a DB field that I want to check. The column is set up like this: 'alumInfo enum ('0','1') NOT NULL default='0', I query it like this: $sql = mysql_query ("SELECT alumInfo FROM users WHERE username='$username' AND password='$password'"); Then I want to check what the value is. If it's 0 I want to print one thing, if it's 1 I want to print something else. I've tried something like this: $row = mysql_fetch_array($sql); // I'm thinking the problem lies here... if($row['alumInfo'] == '0') { echo "one thing"; } else { echo "something else"; } It seems to ignore the first 'echo' and only prints the last one, even though the default value is '0'. Any suggestions? Thanks.
  6. argh! so close... Thanx again Violent.
  7. I don't know why I can't figure this out... but I haven't yet. Basically I have a value in a DB field that I want to check. The column is set up like this: 'alumInfo enum ('0','1') NOT NULL default='0', I query it like this: $sql = mysql_query ("SELECT alumInfo FROM users WHERE username='$username' AND password='$password'"); what I want to do next is where the problem lies (at least I think it is). I want to check what the value is. If it's 0 I want to print one thing, if it's 1 I want to print something else. I've tried something like this: $row = mysql_fetch_array($sql); if({$row['alumInfo']} == 1) { // I've tried writting this several ways... apparently all wrong echo "one thing"; } else { echo "something else"; } but that's getting me nothing but errors. Help?
  8. I have a multipage form from which people are selecting different things (which are then sent via POST then stored as a SESSION) from each page. I would like to add in between each a script that will let them confirm that they chose what they wanted, before they go on to the next choice. If not, then they can go back. What I'm not sure about is what to do with the SESSION? Do I need to destroy it? Or will it get overwritten? Here is the basic code I have now: <?php session_start(); $_SESSION['align'] = $_POST['align']; if ( isset ( $_SESSION['align'] )) { print "<p>You have selected " . $_SESSION['align'] ." for your Characters Alignment.</p>"; } else { print print '<p>Please go back and select an Alignment for your Character!</p>'; exit; } ?> <table> <tr> <td>If you are sure sure about your Alignment choice, continue to the next page. Otherwise select the 'Back' button. </td> </tr> <tr> <td><form><input type="button" name="align_back" value="BACK" onClick="history.go(-1);return true;"></form> </td> <td><form method="post" action="char_breed.php"><input type="submit" name="align_confirm" value="NEXT"></form> </td> </tr> </table> Thanks for any help or suggestions.
  9. Thanks Barand, It was A by the way. You wouldn't happen to know any good resources where I could find answers to those sorts of questions as they would relate to game creation, would you? Or I guess I can just keep posting here. Don't get me wrong, I love this site!!! I just didn't know if everyone wanted to hear about my troubles making a game, or if there was a place specifically for that kind of thing.
  10. Wow. Thanks for the in depth post, Crayon Violent. I think you thought more about it than I did. lol. I guess to be more specific, I was thinking that a lot of the posts had to do with MMO-RPG type games. Kind of like the ones you mentioned. This seems to be a really popular field (maybe toooooo popular) right now, and it actually seems to include many different aspects of making dynamic websites. The fact that they are so popular is what really seemed strange that I don't seem to find any forums or sites dedicated (or even with just a section dedicated) to it. I just thought that if there was a forum or something specific to that, it would be a great way to collect many different question, and more importantly, similar answers (or even tutorials) in one place. While I agree that all games are different (well... hmmmm) many of the things about them can be recycled, such as similar codes, functions, queries, and DB structure. Just a thought. p.s. I like your picture. p.s.s. Yeah, there was one thing I'm thinking about now with my own game, but it really isn't a PHP question. It has to do with how to set-up the DB. Not the SQL or anything, but like the best way to arrange it, if that makes sense? For instance, there are users (with their own stored unique info), and the users have characters (with different unique stored info), so should these be 2 separate tables in the DB, or just one big old long one? What would that do to the DB drag.... blah, blah, blah. Questions like that.
  11. If you could post exactly what those lines in the MySQL table say, or the PHP code where the query is, I might be able to help you better.
  12. Greetings. Yeah, I'm one of those guys how is trying to use PHP to create some crazy game. Actually I am really trying to learn PHP, but just copying examples out of books wasn't really forcing me to learn PHP. I was just learning how to copy text well. So I notice that, while there seem to be several threads and questions relating to game creation, there doesn't seem to be any one section dedicated to this topic. I haven't found one any where else either. I was wondering if anyone knew of one (or if I was just missing it here somewhere), or wondering if perhaps we could start one? Thanks for any help.
  13. [!--quoteo(post=368880:date=Apr 26 2006, 10:53 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 26 2006, 10:53 AM) [snapback]368880[/snapback][/div][div class=\'quotemain\'][!--quotec--] Are yoy running that code on a local setup of Apache/PHP? If you are then you will need to configure PHP to use an SMTP server in order for emails to be sent! You can configure the SMTP server in php.ini file. If you are running it off your webhost then it should work or your webhsots has disabled the use of using th mail function. [/quote] Duh-Oh! They don't call me nOOb for nothing. Thank you wildteen88!
  14. I'm relieved to see you guys are having problems with mail as well. In every tutorial, book, article, whatever I read, they make it sound like sending mail with the 'mail()' function is the easiest thing in the world. But I've tried and tried, and even simple code like this: <?php // Your email address $email = "freshrod@freshrod.com"; // The subject $subject = "testing"; // The message $message = "I hope this works!"; mail($email, $subject, $message, "From: $email"); echo "The email has been sent."; ?> just doesn't seem to work.
  15. AH-HA!!! I got it to work (of course getting it to work doesn't always mean I did it RIGHT, hahaha). All I did was switch out where I had: value="{$data[jobName]}" for value="{$row[jobName]}" and it seems to be working. Thanks for the help.
  16. Thanks for the response gizmola. I guess I didn't explain well enough what the page is supposed to be doing. I want the query to populate a form that lists out the available jobs based on the number of abilities. The form will display the jobName, jobPay, jobDescription, and then have a radio button with which they select which job they want. That much is working...at least it looks as if it's working. Thanks for pointing out the difference between mysql_fetch_row() and mysql_fetch_assoc(). But even after changing that, it's still only displaying the first letter of the jobDescription. Perhaps if you saw all the code it would help [code] <form id="jobs" name="jobs" action="char_title.php" method="post"> <tr> <td align="center" valign="middle" width="33%"> <?php switch ($_SESSION['breed']) {   case 'Human':     $abilities = 3;     break;   case 'Altered':     $abilities = 2;     break;   case 'Mutant':     $abilities = 1;     break;   default:     echo "ERROR!!!"; } function displayJobs ($result) {     print "<h3>Avalible Jobs for " . $_SESSION['breed'] . "</h3>\n";     print "\n<table>\n<tr>\n" .           "\n\t<th>Job Title</th>" .           "\n\t<th>Job Pay</th>" .           "\n\t<th>Job Description</th>" .           "\n\t<th>Select One</th>" .           "\n</tr>";                while ($row = @ mysql_fetch_assoc($result)) {           print "\n<tr>";                      foreach ($row as $data)                     print "\n\t<td><center> {$data} </center></td>";             print "\n\t<td><input type=\"radio\" name=\"job\" value=\"{$data[jobName]}\"></td>";             print "\n</tr>";         }     print "\n</table>\n"; } $query = "SELECT jobName, jobPay, jobDescription FROM jobs WHERE numAbil <= {$abilities} ORDER BY jobName ASC"; if (!($connection = mysql_connect("localhost", "*****", "*****")))    die ("Cannot Connect to DB!");    if (!(mysql_select_db("*****", $connection)))    showerror();    if (!($result = mysql_query ($query, $connection)))    showerror();    displayJobs($result); ?> </td> </tr> </tbody></table>   </center> </div> <p><center> <input name="job_butt" value="LET IT BE SO!" type="submit"> </center></p> </form> [/code] Any help is appreciated in advance.
  17. Greetings Melvnatic Ok...so lets say you have a function you want to use a lot. You create a php file with that function. <?php function bold($string) { print "<b>" . $string . "</b>"; } ?> Save that as bold.inc or just bold.php. Then you access it in your script by calling it with include "bold.inc"; or include (bold.php); Then you can use the function like: bold ("This is some bold text right here!"); OR If you wanted to use it as/with a variable: $boldPrint = "This is some bold text right here!"; bold ($boldPrint); I hope this helps.
  18. Hey Derek It's hard to know exactly what you want from your post. If you want, as you said (quote) but first i want to make just a php script that you can add or subtract varibles and still have it work for a register form (end quote) then you should start with that script and try and modify it and then ask about the specifics problems you run into. You might look here for some ready-made registration scripts: [a href=\"http://www.phpfreaks.com/scripts/User_Authentication/16.php\" target=\"_blank\"]http://www.phpfreaks.com/scripts/User_Authentication/16.php[/a] I hope this helps.
  19. I'm like you Jake. A visual learner. I have to SEE how it works to really understand it. I haven't taken the Zend course, but I guess it would depend on what you need to learn PHP for, and how much disposable cash you have. I mean, If you really need to learn it fast and well, then you might want to take a course, either the Zend online or in a real classroom. But you might also be able to find everything you need in a book you can buy or check out at a library for free. And you can alway get help online, like here. If you ask around you might even find someone who knows PHP and can help you. I hope this helped.
  20. I posted before, but I managed to figure out that problem... kind of. Now I have a related, yet entirely new and exciting problem. Here's the deal. I query the DB like so: $query = "SELECT jobName, jobPay, jobDescription FROM jobs WHERE numAbil <= {$abilities} ORDER BY jobName ASC"; I slap it into an array like so: while ($row = @ mysql_fetch_row($result)) { print "\n<tr>"; foreach ($row as $data) print "\n\t<td><center> {$data} </center></td>"; print "\n\t<td><input type=\"radio\" name=\"job\" value=\"{$data[0]}\"></td>"; print "\n</tr>"; } What I'm trying to do here is get the jobName from the query to be the value for the radio button. Then it's POSTed to the next page, where I assign it to a SESSION like so: $_SESSION['job'] = $_POST['job']; Then I try and get it to display like so: <p align="center"><font size="2"><b>JOB</b>: <?php print $_SESSION['job']; ?> The weird thing is, that all I get displayed is the first letter of the jobDescription, which I thought would be $data[2], but why only the first letter I can't begin to guess. Any thoughts? If you need more code or better description, please ask. Thanks.
  21. Sorry for the double post, but I wanted to rescue my initial post from archive hell (or is it archive purgatory?), and I also thought of something that might increase the chances someone might have an idea about how to help me. I know that DB querys are returned as arrays in php, right? But I really don't understand arrays very well. So is there a way to assign a value to a certain field from the table (in this case the jobName field) and then use that for the value in the radio button form? Something like: $job=$data[0]; $jobName=$data[1]; etc... then: <input type="radio" name="job" value="$data[1]"> I don't know...like I said I don't understand arrays very well yet. Thanks for any help.
  22. Greetings Ames I'm a noob too, so I'm not 100% sure about everything you need to do to get this working right...BUT If you want to edit data in the DB you need to use an UPDATE command. I think after you have retrieved the data, displayed it in a form, edited the data, then you need to add another query that updates the data to the DB. Example: $query = "UPDATE * FROM `events`WHERE eventid=$id"; I hope this helps.
  23. Greetings Clinker If you want to have the data available over several pages, or for the complete time that person is accessing the server, you might want to look into using a SESSION. SESSIONS are kind of a big topic for one post, so you might want to look around a bit. I learned enough about them to use them for multi-page forms from different tutorials and articles on the web. I hope this helps.
  24. Greetings I'm a noob as well, but I think I may be able to help on this one. Either way you might want to take my advice with a grain of salt. If you use the LIMIT command in your query, it should only return that many rows. Example: $query3 = mysqli_query($conn, "SELECT * FROM event, venue WHERE event.venue = venue.venueName AND event.date <= '$mysqlTwoDays' AND event.eventID = '$key' LIMIT 3") or die('Error, query failed'); You can also specify which row to start at and how many to return like this: SELECT * FROM event BLAH, BLAH whatever LIMIT 12, 5; This would return rows 12 to 16 from the event table. I hope this helps.
  25. This is for a game I'm trying to make. The players select a job that is based on their breed. The jobs are in the DB. I don't know how to get the radio input's value to be the same as the job (or jobName, as it's called in the DB) for that row, so I can then assign it to a SESSION. This is what I have so far: <form id="jobs" name="jobs" action="char_menu.php" method="post"> <tr> <td align="center" valign="middle" width="33%"> <?php switch ($_SESSION['breed']) { case 'Human': $abilities = 3; break; case 'Altered': $abilities = 2; break; case 'Mutant': $abilities = 1; break; default: echo "ERROR!!!"; } function displayJobs ($result) { print "<h3>Avalible Jobs for " . $_SESSION['breed'] . "</h3>\n"; print "\n<table>\n<tr>\n" . "\n\t<th>Job Title</th>" . "\n\t<th>Job Pay</th>" . "\n\t<th>Job Description</th>" . "\n\t<th>Select One</th>" . "\n</tr>"; while ($row = @ mysql_fetch_row($result)) { print "\n<tr>"; foreach ($row as $data) print "\n\t<td><center> {$data} </center></td>"; print "\n\t<td><input type=\"radio\" name=\"job\" value=\"???\"></td>"; print "\n</tr>"; } print "\n</table>\n"; } $query = "SELECT jobName, jobPay, jobDescription FROM jobs WHERE numAbil <= {$abilities} ORDER BY jobName ASC"; displayJobs($result); ?> This is my first post, so I hope I didn't mess it up.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.