Jump to content

john010117

Members
  • Posts

    492
  • Joined

  • Last visited

    Never

Posts posted by john010117

  1. I'll get right down to the problem. First of all, here's one of the part's I'm having trouble with.

    <?php
    // Above contains the SELECT query
    if(mysql_num_rows($query) > 0) {
        while($row = mysql_fetch_array($result)) {
            echo '<form action="result.php" method="POST">
    <input name="pm_delete[]" type="checkbox" value="' . $row['msg_id'] . '"><br />
    <input type="submit" name="submit" value="Submit">
    </form>';
    

     

    As you can see, for each of the results, it displays a checkbox.

     

    Here's result.php:

    <?php
    // All the checks go above here
    $query = DELETE $privmsgs_tbl_name, $privmsgs_spec_tbl_name FROM $privmsgs_tbl_name, $privmsgs_spec_tbl_name WHERE ";
    
    foreach($_POST['pm_delete'] as $arr => $pid) {
        $query .= "$privmsgs_tbl_name.msg_id = '$pid'
        AND $privmsgs_tbl_name.recipient_uid = '$session_uid'
        AND $privmsgs_spec_tbl_name.msg_id = '$pid'
        AND $privmsgs_spec_tbl_name.user_id = '$session_uid'
    }
    

     

    Ok. Let me explain. I put the selected checkbox(es) in an array. Now, for each of the checkboxes, I want to delete the row associated with it (with the "$row['msg_id']" being the common "thing" between them). But, I need an AND statement at the end of each query (otherwise, it would look like this:

    AND $privmsgs_spec_tbl_name.user_id = '$session_uid'$privmsgs_tbl_name.msg_id = '$pid'
    

    ... which of course, would throw an error).

     

    But if I just add an " AND " at the end, the last element would look like this:

    AND $privmsgs_spec_tbl_name.user_id = '$session_uid' AND
    

    ... which will also throw an error.

     

    So how would I configure the code so that it adds an " AND " at the end of each pass without adding one at the last pass?

  2. Yep, and also validating the e-mail address. This is just a function that I wrote a long time ago that validates the e-mail address..

     

    <?php
    function validate_email ($email) {
    // First, we check that there's one @ symbol, and that the lengths are right
    if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    	// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    	return false;
    }
    // Split it into sections to make life easier
    $email_array = explode("@", $email);
    $local_array = explode(".", $email_array[0]);
    for ($i = 0; $i < sizeof($local_array); $i++) {
    	if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
    		return false;
    	}
    }
    if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
    	// Check if domain is IP. If not, it should be valid domain name
    	$domain_array = explode(".", $email_array[1]);
    	if (sizeof($domain_array) < 2) {
    		// Not enough parts to domain
    		return false;
    	}
    	for ($i = 0; $i < sizeof($domain_array); $i++) {
    		if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
    		return false;
    		}
    	}
    }
    return true;
    }
    ?>
    

  3. I figured it out.

     

    <?php
    $query = "DELETE
                      $privmsgs_tbl_name,
                      $privmsgs_spec_tbl_name
                  FROM
                      $privmsgs_tbl_name,
                      $privmsgs_spec_tbl_name
                  WHERE
                      $privmsgs_tbl_name.msg_id = '$pm_id'
                      AND $privmsgs_tbl_name.recipient_uid = '$session_uid'
                      AND $privmsgs_spec_tbl_name.msg_id = '$pm_id'
                      AND $privmsgs_spec_tbl_name.user_id = '$session_uid'
                      AND $privmsgs_tbl_name.msg_id = $privmsgs_spec_tbl_name.msg_id
                      AND $privmsgs_tbl_name.recipient_uid = $privmsgs_spec_tbl_name.user_id
                      AND $privmsgs_tbl_name.author_uid = $privmsgs_spec_tbl_name.author_id";
    $result = mysql_query($query) OR DIE (mysql_error());
    ?>
    

     

    Thank you to everyone who helped.

  4. From what I can see, register2.php doesn't even check that all the fields were filled in.

     

    register2.php

    <?php
    $pagename = "Registration";
    include "session2.inc.php";
    include "../config.inc.php";
    include "top.txt";
    //Connect to mySQL Database
    mysql_connect("$host", "$username", "$password")or die("Can't connect");
    mysql_select_db("$db_name")or die("Can't connect");
    
    // Get the information the user submitted for registration
    $uname=$_POST['uname'];
    $pass=$_POST['pass'];
    $email=$_POST['email'];
    
    if(empty($uname)) {
        echo 'You did not fill in your username';
    }
    elseif(empty($pass)) {
        echo 'You did not fill in your password.';
    }
    elseif(empty($email)) {
        echo 'You did not fill in your e-mail.';
    }
    
    // Encrypt the password using MD5, to safely store the password.
    $md5pass=md5($password);
    
    $tbl_name = "admins";
    $sql = "INSERT INTO $tbl_name (`uname` , `pass` , `email`) VALUES ('$uname' , '$md5pass' , '$email')";
    $result=mysql_query($sql) or die("Error: ". mysql_error(). " with query ". $sql);
    
    if($result){
    echo "Thank you for registering, $uname. You may now <a href=\"index.php\">Login</a>";
    }
    else {
    echo "There was a mistake processing your registration. Go <a href=\"register.php\">back</a> and try again. ^^;";
    }
    mysql_close();
    include "bottom.txt";
    ?>
    

     

    For each of the fields that are required, do what I have done. If a field is optional, ignore it.

  5. [b]@ corillo181:[/b]
    So then, it would look something like this?
    
    [code]
    <?php
    $query = "DELETE
                      $privmsgs_tbl_name,
                      $privmsgs_spec_tbl_name
                  FROM
                      $privmsgs_tbl_name
                  LEFT JOIN
                      $privmsgs_spec_tbl_name
                  ON
                      $privmsgs_tbl_name . '.msg_id' = $privmsgs_spec_tbl_name . '.msg_id'
                  WHERE
                      pm.recipient_uid = $session_uid
                  AND pm_spec.msg_id = $pm_id
                  AND pm_spec.user_id = $session_uid
                  AND pm.msg_id = pm_spec.msg_id
                  AND pm.recipient_uid = pm_spec.user_id
                  AND pm.author_uid = author_id";
    $result = mysql_query($query) OR DIE (mysql_error());
    ?>
    

     

    @ skali:

    The printed query looks like this:

    DELETE FROM privmsgs AS pm, privmsgs_spec AS pm_spec WHERE pm.msg_id = '3' AND pm.recipient_uid = '4' AND pm_spec.msg_id = '3' AND pm_spec.user_id = '4' AND pm.msg_id = pm_spec.msg_id AND pm.recipient_uid = pm_spec.user_id AND pm.author_uid = author_id
    

     

    So the variables are all there. It fails in phpMyAdmin also.[/code]

  6. Does anyone know what's wrong with this?

     

    <?php
    $query = "DELETE FROM
                      $privmsgs_tbl_name AS pm,
                      $privmsgs_spec_tbl_name AS pm_spec
                  WHERE
                      pm.msg_id = $pm_id
                  AND pm.recipient_uid = $session_uid
                  AND pm_spec.msg_id = $pm_id
                  AND pm_spec.user_id = $session_uid
                  AND pm.msg_id = pm_spec.msg_id
                  AND pm.recipient_uid = pm_spec.user_id
                  AND pm.author_uid = author_id";
    $result = mysql_query($query) OR DIE (mysql_error());
    ?>
    

     

    MySQL keeps on giving me this error:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE pm.msg_id = '3' AND pm.recipient_uid = '4' A' at line 4

     

    I checked the manual and I believe I'm doing this correctly... but apparently, I'm not. Help, please. Oh, and btw, I got all the variables defined, so that's not the problem.

  7. I just want a simple drop-down list where a specific value is automatically selected according to the data stored in the database.

     

    Ex:

    <select name="select_blah_1">
        <option name="1" value="1" selected="true">
        <option name="2" value="2" selected="false">
    </select>
    

     

    How would I go about doing that?

     

  8. When logged in, it says

    "Thankyou for logging in huggy1"

     

    when it should be

    "Thank you for logging in, huggy1".

     

    Also, you should not give out a username and password with admin privileges.

     

    Overall, nice layout.

     

  9. If you want someone else to build it for you, please post your request in the Freelancing area. It's better to try to make your own script and stumble on every step of the way than to copy and paste a code off of a cra*py tutorial and expect it to work. ;)

  10. I'm not very experienced with iframes, so I can't say exactly. I'll let the other users answer that.

     

    For your second question, I'm assuming you have one page that displays the form, and another page which processes the form. If my assumption is correct, put that code near the top on the processing page. So it'll look something like this:

     

    form:

    <form action="process.php" method="POST">
    <input name="username" type="text">
    </form>
    

     

    processing page:

    <?php
    $username = $_POST['username'];
    // If the form wasn't submitted, redirect the user to the form page
    if(!isset($username)) {
       header('Location: form.php');
       exit();
    }
    else {
       header('Location: /' . $username . '/');
    }
    ?>
    

     

    Note that I haven't tested this yet. But the layout of the code should look similar to this.

  11. Pretty neat! I'm glad you used CSS. ;)

     

    Ok. First of all, your top banner (a part of it, anyways) needs to link back to the main page (even though you have the nav at the top).

    On forums/index.php, have the pics AND the title of the category be links. Also on that same page, "Healthy Eating Advice" and "Contact" overlap (in the top nav).

×
×
  • 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.