Jump to content

thomashw

Members
  • Posts

    244
  • Joined

  • Last visited

    Never

About thomashw

  • Birthday 08/16/1988

Contact Methods

  • Website URL
    http://www.tunerspec.ca

Profile Information

  • Gender
    Male
  • Location
    Alberta

thomashw's Achievements

Member

Member (2/5)

0

Reputation

  1. There is no difference between this query and the one he already had. This has nothing to do with his problem. Pikachu2000 already identified the issue. I've had problems using the syntax he's using, so that is why I suggested changing the string to what I posted.
  2. Can you post the full code, including the form?
  3. Change your query string to this: $query = "UPDATE users SET money='".$nmoney."' WHERE username='".$username."'";
  4. Oh, haha, no I wasn't. I just mistyped it up there. Anyway, thank you. My syntax was a little off.
  5. What's the correct syntax for having a variable in a select statement? Here's an example of what I'm trying to do (after I'm already connected to the database). $username = "thomas"; $query = mysql_query( "SELECT * from users WHERE username = $thomas" ); if( mysql_num_rows( $query ) > 0 ) { bla bla... It works if I don't put the WHERE part in, but I get an error if I use it, so I'm assuming I have the wrong syntax for using a variable in the select statement.
  6. I've bolded the part of the code I don't fully understand. Won't sum = sum2 just overwrite the old sum? So why do you need to release it beforehand? Why isn't sum2 released at the end of the program? Should it be? #import “Fraction.h” int main (int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Fraction *aFraction = [[Fraction alloc] init]; Fraction *sum = [[Fraction alloc] init], *sum2; int i, n, pow2; [sum setTo: 0 over: 1]; // set 1st fraction to 0 NSLog (@”Enter your value for n:”); scanf (“%i”, &n); pow2 = 2; for (i = 1; i <= n; ++i) { [aFraction setTo: 1 over: pow2]; sum2 = [sum add: aFraction]; [b] [sum release]; // release previous sum sum = sum2;[/b] pow2 *= 2; } NSLog (@”After %i iterations, the sum is %g”, n, [sum convertToNum]); [aFraction release]; [sum release]; [pool drain]; return 0; } Thank you!!
  7. Redirect to the same page, but without the $_POST's. header("Location: http://www.example.com/");
  8. Why don't you try setting $docRoot manually rather than using $_SERVER['DOCUMENT_ROOT']? If that fixes the problem, then you know the server is configured incorrectly.
  9. I'd like to have a few constants to use throughout my site. I'm wondering where to store them and the best way to access them? Should I just make a constants.php file in my root directory and include that file in all of my pages, or... what?
  10. Here you go. <?php session_start(); include 'db.inc.php'; $db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die ('Unable to connect. Please contact the webmaster.'); mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db)); $state_list = array('AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA, PR, RI, SC, SD, TN, TX UT, VT, VA, WA, WV, WI, WY'); //filter incomming values $username = (isset($_POST['username'])) ? trim($_POST['username']) : ''; $password = (isset($_POST['password'])) ? trim($_POST['password']) : ''; $first_name = (isset($_POST['first_name'])) ? trim($_POST['firstname']) : ''; $last_name = (isset($_POST['last_name'])) ? trim($_POST['last_name']) : ''; $email = (isset($_POST['email'])) ? trim($_POST['email']) : ''; $city = (isset($_POST['city'])) ? trim($_POST['city']) : ''; $state = (isset($_POST['state'])) && is_array($_POST['state']) ? $_POST['state'] : array(); $zip = (isset($_POST['zip'])) ? trim($_POST['zip']) : ''; if(isset($_POST['submit']) && $_POST['submit'] == 'Register') { $errors = array(); //make sure manditory fields have been entered if(empty($username)) { $errors[] = 'Username cannot be blank.'; } //check if username already is registered $query = 'SELECT username FROM users WHERE username = "' . $username . '"'; $result = mysql_query($query, $db) or die(mysql_error()); if (mysql_num_rows($result)>0) { $errors[] = 'Username' .$username. ' is already registered.'; $username = ''; } mysql_free_result($result); if(empty($password)) { $errors[] = 'Password cannot be blank.'; } if(empty($first_name)) { $errors[] = 'First name cannot be blank.'; } if(empty($last_name)) { $errors[] = 'Last name cannot be blank.'; } if(empty($email)) { $errors[] = 'Email address cannot be blank.'; } if(count($errors) > 0) { echo '<p><Strong style="color:#FF000;">Unable to process your '.'registration.</strong></p>'; echo '<p>Please check the following errors:</p>'; echo '<ul>'; foreach ($errors as $error) { echo '<li>' .$error. '</li>'; } echo '</ul>'; } else { // No errors so enter the information into the database. $query = 'INSERT INTO users (user_id, username, password) VALUES (NULL, "' . mysql_real_excape_string($username, $db) . '", '.'PASSWORD("' . mysql_real_excape_string($password, $db) . '"))'; $result = mysql_query($query, $db) or die(mysql_error()); $user_id = mysql_insert_id($db); $query = 'INSERT INTO user_info (user_id, first_name, last_name, email, phone, city, state, zip) VALUES (' . $user_id. ' , ' . '"' .mysql_real_excape_string($first_name, $db) .'", ' . '"' .mysql_real_excape_string($last_name, $db) .'", '. '"' .mysql_real_excape_string($email, $db) . '", '. '"' .mysql_real_excape_string($phone, $db) . '", '. '"' .mysql_real_excape_string($city, $db) . '", '. '"' .mysql_real_excape_string(join(', ', $state),$db) . '", '. '"' .mysql_real_excape_string($zip, $db) . '")'; $result = mysql_query($query, $db) or die(mysql_error()); $_SESSION['logged'] = 1; $_SESSION['username'] = $username; header('Refresh: 5; URL=main.php'); } } ?> <html> <head> <title>Register</title> <style type="text/css"> td{ vertical-align: top;} </style> </head> <body> <form action="register.php" method="post"> <table> <tr> <td><label for="username">Username:</label></td> <td><input type="text" name="username" id="username" size="20" maxlength="20" value="<?php echo $username; ?>"/></td> </tr><tr> <td><label for="password">Password:</label></td> <td><input type="password" name="password" id="password" size="20" maxlength="20" value="<?php echo $password; ?>"/></td> </tr><tr> <td><label for="email">Email:</label></td> <td><input type="text" name="email" id="email" size="20" maxlength="50" value="<?php echo $email; ?>"/></td> </tr><tr> <td><label for="first_name">First name:</label></td> <td><input type="text" name="first_name" id="first_name" size="20" maxlength="20" value="<?php echo $first_name ?>"/></td> </tr><tr> <td><label for="last_name">Last name:</label></td> <td><input type="text" name="last_name" id="last_name" size="20" maxlength="20" value="<?php echo $last_name ?>"/></td> </tr><tr> <td><label for="city">City:</label></td> <td><input type="text" name="city" id="city" size="20" maxlength="20" value="<?php echo $city ?>"/></td> </tr><tr> <td><label for="state">State</label></td> <td><select name="state[]" id="state" multiple="multiple"> <?php foreach ($state_list as $states){ if(in_array($states, $state)) { echo '<option value="'.$states.'" selected="selected">' .$states . '</option>'; } else { echo '<option value="'.$states.'">'.$states.'</option>'; } } ?> </select></td> </tr><tr> <td></td> <td><input type="submit" name="submit" value="Register"/></td> </tr> </table> </form> </body> </html> You were just missing a couple closing braces before you started the HTML section.
  11. Why not just use the original function names instead of using your own? You can try using the stripslashes function when removing it from your database.
  12. At the end of a function (the last line of code in the function) you can do a return, which will return a value to wherever it was called. For example, here's a function: function temp() { return 1; } Now if you call that function: $number = temp(); // number = 1 Get it? That's how you get a value out of a function. Also, there's no rules when to call functions as long as they make sense. You can have a function call another function, which calls five more functions. You can have a function call itself, etc.
  13. Where you have: ($user = mysql_fetch_array($users)) Try changing it to: ($user = mysql_fetch_assoc($users))
×
×
  • 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.