Jump to content

melting_dog

Members
  • Posts

    118
  • Joined

  • Last visited

    Never

Posts posted by melting_dog

  1. Hi guys,

     

    I have a simple query here:

     

    $sql="SELECT user_id FROM $tbl_name WHERE email='$loginuseremail' AND password='$loginpassword'";

    $result=mysql_query($sql);

    $row = mysql_fetch_assoc($result);

     

    //START SESSION

    session_start();

    $_SESSION['username']=$loginuseremail;

    $_SESSION['user_id']=$row;

     

    echo $_SESSION['user_id'];

     

    It should obviously output an ID number but instead I just get the word 'Array'. If I remove the  mysql_fetch_assoc() I just get 'Resource ID #4'.

     

    Can anyone point me in the right direction?

     

    Thanks!

  2. Hmm it kind of is -

     

    Say if I had an SQL query that returned a set of results that I would use across my site over and over again. I imagine that it would be better practice to have that query on its own file and to 'call' that file (via include?) whenever you need it.

     

    I just want to confirm that this is the best practice to do this

     

    Thanks!

  3. OK I get a new meesage now:

     

    Warning: move_uploaded_file(uploads/ferriswheel.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/xampp/whatmycitywears/submitphotoprocess.php on line 35

     

    So I think I need to somehow set the permissions in XAMPP to allow upload?

  4. Hi guys,

     

    I need a little help. I am running a site in XAMPP whilst I develop it locally. I am trying to upload an image file. Heres my code:

     

    $photo=$_POST['photo'];

     

    $target_path = "uploads/";

     

    $target_path = $target_path . basename( $_FILES['photo']['name']);

     

    if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path)) {

        echo "The file has been uploaded";

    } else{

        echo "There was an error uploading the file, please try again!";

    }

     

    But I get these errors:

     

    Warning: move_uploaded_file(upload/ferriswheel.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory

     

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/XAMPP/xamppfiles/temp/phpNwxq6I' to 'upload/ferriswheel.jpg' in /Applications/XAMPP/xamppfiles/htdocs/xampp/whatmycitywears/submitphotoprocess.php on line 53

     

    Am I right in thinking this is some sort of issue with the temp directory? It seems to be putting it somewhere is XAMPSS folders rather then in my directory

     

    Any help would be great!

  5. Thanks,

     

    I'm actually getting the image and all other information (caption, alt text, etc) fine. Im just having a good deal of difficulty with the styling -  I want to create rows of three images next to each other (so if I had 12 images I'd get 4 rows of three) . I was wondering if there was a better way to go about the gallery that I was missing. List? Tables? Or maybe arrays?

     

    Thanks again!

  6. Hi guys,

     

    Just after a bit of advice really. I want to create an image gallery. Currently, my images (which are sourced from a DB) are brought about in a loop and set in their own div, side by side. I was just thinking though: would it be better to do this with an array? Its a bit difficult coding for this just using the basic loop. Anyone have any suggestions to make this better?

     

    PS, here is my current code:

     

    $sql =  "SELECT * FROM imagegal";

    if ($result = mysql_query($sql)) {

        if (mysql_num_rows($result)) {

     

    while($row = mysql_fetch_array($result)){

     

    echo '<span class="imagegal">';

    echo '<span><img src="' . $row['image'] . '"</span>';

    echo '</span>';

     

    }}}

  7. Hi guys,

     

    Sorry - I know this is a basic question but I've been out of the game for a year now and need to jog my memory.

     

    I am trying to count the number of rows per group. e.g:

     

    $sql =  "SELECT *, COUNT(id) FROM image GROUP BY city";

    $result = mysql_query($sql);

    $row = mysql_fetch_assoc($result);

     

    echo $row['COUNT(id)'];

     

     

    So if there are, for example, 5 New York's in the table, 3 London's and 2 Sydney's I want the echo to display 5, 3, 2

     

    Should I use a loop for this?

     

    Cheers

  8. Hi guys,

     

    Trying to ge this to work:

     

     

    function  checkEmail($useremail) {

    if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $useremail)) {

      return false;

      $error = '<div id="blackText"><p>Sorry! Please check your email address and try again!<p><p><a href="forumsSignUp.php">Back</a></p></div>';

    }

    return true;

     

    //PASSWORD AND OTHER VALIDATION STUFF, blah blah blah

     

    }

     

    But its just not. Everything works fine if I remove this though. Can anyone suggest an alternative to email address validation? Thanks!

  9. Hi guys

     

    Probably a simple but trying to figure out why I cant get this while loop to work (at least I think its the loop)

     

    Query works as it returns 1 row, but not all of them.

     

    Any help would be great!

     

    $sql = "SELECT * FROM requests ORDER BY leave_after DESC";

      if ($result = mysql_query($sql)) {

        if (mysql_num_rows($result)) {

     

     

      while ($row = mysql_fetch_assoc($result))

      {

    echo '<div id="resultholder">';

    echo "<p>Request ID:" . $row['id'] . ", User ID: " . $row['user_id'] . ", Departing From: " . $row['departing'] . ", Going To: " . $row['destination'] . " , Leaving After: " . $row['leave_after'] . " , but Arriving Before: " . $row['arrive_before'] ."</p></div>";

    echo '</div>';

    }

        }

      }

     

    Thanks!

  10. Hi guys,

     

    I want to create a piece of script that takes my users to a website based of there input in a form. Basiaclly what they input into a text field will become part of the URL used in action at the top of the form.

     

    So it would look like this:

     

    http://www."their input from form".mydomain.com

     

    does anyone have any suggestions on how to accomplish this?

     

    Thanks

  11. Hi all,

     

    Yeah just a fresh pair of eyes needed. It just wont insert into the table and the alert returns a blank. Only thing I can think is thats its posting variables from two different queries...but that shouldnt make a difference...

     

    Cheers

     

    FORM PAGE*************************
    
    //*****************************LOGGED CHECKER*********************
    
    $sql = "SELECT * FROM users WHERE firstName= '$logged'";
    
    if ($result = mysql_query($sql)) {
        if (mysql_num_rows($result)) {
       if ($row = mysql_fetch_assoc($result)) {
    
    
    //**************QUESTION FORM*****************************
    $sql2 = "SELECT * FROM questions WHERE questionID= '$orderCounter'";
    
    if ($result2 = mysql_query($sql2)) {
        if (mysql_num_rows($result2)) {
       if ($row2 = mysql_fetch_assoc($result2)) {
    
    echo "<p>" . $row2['questionText'] . "</p>";
    
    echo '<form name="form1" method="post" action="questionProcess.php">';	
    echo   '<input type="radio" name="q1" value="' . $row2['answer1'] . '" />' . $row2['answer1'] . '<br />';
    echo	'<input type="radio" name="q1" value="' . $row2['answer2'] . '" />' . $row2['answer2'] . '<br />';
    echo    '<input type="radio" name="q1" value="' . $row2['answer3'] . '" />' . $row2['answer3'] . '<br />';
    echo     '<input type="radio" name="q1" value="' . $row2['answer4'] . '" />' . $row2['answer4'] . '<br />';     
    echo    '<input type="hidden" name="userid" value="' . $row['userid'] . '" />';
    echo    '<input type="hidden" name="orderCounter" value="' . $row['orderCounter'] . '" />'   
    echo    '<input type="submit" name="Submit" id="Submit" value="Next" />';
    echo     '</label>';
    echo    '</form>';
    
    
    }
    }
    }
    
    }
    }
    }
    ?> 
    
    PROCESSING PAGE****************************************
    
    $q1=$_POST['q1'];
    $userid=$_POST['userid'];
    $orderCounter=$_POST['orderCounter'];
    // To protect MySQL injection 
    $q1 = stripslashes($q1);
    $userid = stripslashes($userid);
    $orderCounter = stripslashes($orderCounter);
    
    $q1 = mysql_real_escape_string($q1);
    $userid = mysql_real_escape_string($userid);
    $orderCounter = mysql_real_escape_string($orderCounter);
    
    //ALERT CHECKER
    function confirm($msg)
    {
    echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";
    }
    $msg = $userid;
    confirm($msg);
    //ALERT CHECKER
    
    if
    ($q1 == "" ) {
    $wrong = '<div id="blackText"><p>Please Answer the Question<p></div>';
    }
    
    else {
    $sql="INSERT INTO $tbl_name (userid, value, orderCounter) VALUES ('$userid', '$q1', '$orderCounter')";
    $result=mysql_query($sql);
    }
    
    ob_end_flush();
    ?>
    

  12. So sorry if this doesnt belong in this section but i was wondering if anyone knew of a way to encrypt sensitive information (i.e credit card details) passed from a form to a database/email?

     

    I am building a shopping cart and apart from protecting against SQL injection was wondering if there are any other ways to protect information.

     

    Cheers

  13. The correct format for putting a GET parameter on the end of a URL is -

     

    your_page.php?name=value&name2=value2&name3=value3

     

    In your case you are only using one name/value pair, so you would need to produce -

     

    your_page.php?name=value

     

    If the name you want is comDiscussNo and the value is in the variable $comDiscussNo, you would need to use -

     

    your_page.php?comDiscussNo=$comDiscussNo

     

    Thanks heaps...thats done the trick!

  14. Hey again all,

     

    This is a follow on from another post but now i think the issues a bit more simpler.

     

    I am having issues with getting a variable from a header:location()

     

    The first page has:

     

    header("location:forumsDiscussion.php?$comDiscussNo");

     

    The second page has:

     

    $discussIDtrans = (int)$_GET['comDiscussNo'];

     

     

    function confirm($msg)

    {

    echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";

    }

    $msg = $discussIDtrans;

    confirm($msg);

     

    But its comeing up as nothing (0) even though i can see the correct number in the URL.

     

    Cheers, any help is appreciated

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