Jump to content

downah

Members
  • Posts

    127
  • Joined

  • Last visited

Posts posted by downah

  1. Hi guys, have a little problem here, when you login first it seems to work fine, and redirects back to index.php showing your username etc, but then when I click on another page which checks if session is set, it asks me to login again, so I do that, get redirected back to index.php again and click on the same page and then it works.. but almost every time it asks me to login twice.. and not sure why?

     

    Logging in / creating the session :

    <?php
    // Login
      session_start();
      $_SESSION['username'] = htmlspecialchars($username); // htmlspecialchars() sanitises XSS
    
    header( 'Location: index.php' ) ;
    ?>
    

     

    then on index.php:

     

    <?php
    include 'connect.php';
    session_start();
    $username = $_SESSION['username'];
    ?>
    

     

    And on another page:

     

    <?php
    include 'connect.php';
    include_once "markdown.php";
    session_start();
    if(!isset($_SESSION['username']))
    {
    //code
    }
    ?>
    

  2. echo '<img src="data:image/jpg/png/jpeg;base64,' . base64_encode( $row['image'] ) . '" height="150" />';
    

    This is showing up images great in firefox, safari and chrome, but in internet explorer it shows a nice red cross, and I assume it is because of the encoding?

     

    Does anyone know how to get working in internet explorer as well?

     

    Pretty urgent job!

     

    Much appreciated for your help!

  3. FIXED! I am getting a hang of this slowly but surely.

     

    here is the working script  if it is any help for anyone else

     

    if(isset($_POST['eventsID']) && count($_POST['eventsID']))
    {
    $eventsID = $_POST['eventsID'];
    
        //Ensure values are ints
        $deleteIDs = implode(', ', array_map('intval', $_POST['eventsID']));
        $query = "DELETE FROM Eventparticipants WHERE eventsID IN ({$deleteIDs})";
        //Debug line
    echo '';
        mysql_query($query) or die(mysql_error());
        $result5=mysql_query("SELECT maxparticipants, currentparticipants FROM Events WHERE eventsID='$eventsID'");
    $row5=mysql_fetch_assoc($result5);
    
    $currentparticipants = $row5['currentparticipants'];
    
    
    mysql_query("UPDATE Events SET `currentparticipants` = (`currentparticipants` - 1) WHERE `eventsID` IN ({$deleteIDs})") or trigger_error('MySQL Update Failed: ' . mysql_error());
    }
    
    

  4. Now using this but still the same problem, the currentparticipants is not decreasing by one, any ideas?

     

    	if(isset($_POST['eventsID']) && count($_POST['eventsID']))
    {
    $eventsID = $_POST['eventsID'];
    
        //Ensure values are ints
        $deleteIDs = implode(', ', array_map('intval', $_POST['eventsID']));
        $query = "DELETE FROM Eventparticipants WHERE eventsID IN ({$deleteIDs})";
        //Debug line
    echo '';
        mysql_query($query) or die(mysql_error());
        $result5=mysql_query("SELECT maxparticipants, currentparticipants FROM Events WHERE eventsID='$eventsID'");
    $row5=mysql_fetch_assoc($result5);
    
    $currentparticipants = $row5['currentparticipants'];
    
    
    
    
    $b[] = $eventsID;
    
    mysql_query("UPDATE Events SET `eventsID` = (`currentparticipants` - 1) WHERE `eventsID` IN(" . implode(',', $b) . ")") or trigger_error('MySQL Update Failed: ' . mysql_error());
    }
    

  5. Thanks for the suggestion, I am have not used the count function before, but I need this field and there must be something small wrong with why its not updating? Anyone else have any ideas why it is not decreasing the current participants by one?

  6. Hi guys, I have written this code, it might look messy but I am learning so I don't really mind that but my main concern is that it is not working, could anyone help me out?

     

    I am using an array to "unsubscribe" from multiple events at once, now I also need to decrement the amount of participants in that event, the code is working I am able to unsubscribe from events but the currentparticipants field is not updating.. any idea why?

     

    This is the code that runs when you click unsubscribe :

     

    if(isset($_POST['eventsID']) && count($_POST['eventsID']))
    {
    $eventsID = $_POST['eventsID'];
    
        //Ensure values are ints
        $deleteIDs = implode(', ', array_map('intval', $_POST['eventsID']));
        $query = "DELETE FROM Eventparticipants WHERE eventsID IN ({$deleteIDs})";
        //Debug line
    echo '';
        mysql_query($query) or die(mysql_error());
        $result5=mysql_query("SELECT maxparticipants, currentparticipants FROM Events WHERE eventsID='$eventsID'");
    $row5=mysql_fetch_assoc($result5);
    
    $currentparticipants = $row5['currentparticipants'];
    $maxparticipants = $row5['maxparticipants'];
    
    $newcurrentparticipants = $currentparticipants--;
    
    
    
    $sql="UPDATE Events SET currentparticipants='$newcurrentparticipants'
    WHERE eventsID='$eventsID'";
    
    if (!mysql_query($sql))
      {
      die('Error: ' . mysql_error());
      }
    
    }
    

     

    And here is the code where you actually click unsubscribe

     

         $result2 = mysql_query("SELECT * FROM Eventparticipants WHERE participant = '$username'")
    or die(mysql_error());
    
    echo '</br><b>You are currently taking place in these events: </b></br>';
    echo "<form action='' method='POST' onsubmit='return executeOnSubmit();'>";
    echo '<table border="0">';
    while($row2 = mysql_fetch_array($result2))
    {
    
    
    echo '<tr>';
    echo '<td><a href="showevent.php?eventsID=';
    echo $row2['eventsID'];
    echo '">';
    echo $row2['eventdescriptionheader'];
    echo '</a></td>';
    
    
    echo "<td><input type='checkbox' name='eventsID[]' value='{$row2['eventsID']}' /></td>";
    echo '</tr>';
    
    
    }
    echo '</table>';
          echo "</br><input type='submit' value='Unsubscribe to event(s)' name='delete' />";
            echo '</form>';
    

     

     

    And here is the full script in one

    <?php
    include 'connect.php';
    include_once "markdown.php";
    session_start();
    
    if(!isset($_SESSION['username']))
    {
         	echo 'You have to be a registered member to be able to view your space.<br><br> <a href="register.html">Click here to register</a>';
         	       	echo '<br><br><br><br>Or if you are already a member, please login to use this area.<br>';
           	echo '
           	<form method="POST" action="loginverification.php">
           	<table border="0">
           	<tr><td>
      Username: </td><td><input type="text" name="username" size="15" /></td></tr>
      <tr><td>Password:</td><td> <input type="password" name="password" size="15" /></td></tr>
      </table>
      <div align="center">
        <p><input type="submit" value="Login" /></p>
      </div>
    </form>';
    }
    else{
    
    if(isset($_POST['eventsID']) && count($_POST['eventsID']))
    {
    $eventsID = $_POST['eventsID'];
    
        //Ensure values are ints
        $deleteIDs = implode(', ', array_map('intval', $_POST['eventsID']));
        $query = "DELETE FROM Eventparticipants WHERE eventsID IN ({$deleteIDs})";
        //Debug line
    echo '';
        mysql_query($query) or die(mysql_error());
        $result5=mysql_query("SELECT maxparticipants, currentparticipants FROM Events WHERE eventsID='$eventsID'");
    $row5=mysql_fetch_assoc($result5);
    
    $currentparticipants = $row5['currentparticipants'];
    $maxparticipants = $row5['maxparticipants'];
    
    $newcurrentparticipants = $currentparticipants--;
    
    
    
    $sql="UPDATE Events SET currentparticipants='$newcurrentparticipants'
    WHERE eventsID='$eventsID'";
    
    if (!mysql_query($sql))
      {
      die('Error: ' . mysql_error());
      }
    
    }
    
    
    
           $username = $_SESSION['username'];
    
    
           $result = mysql_query("SELECT * FROM Members WHERE username = '$username'")
                   or die(mysql_error());
                   while($row = mysql_fetch_array($result))
                   {
                           echo '<b>' . $username . '</b></br></br>';
    
    
         echo '<img src="data:image/jpg/png/jpeg;base64,' . base64_encode( $row['image'] ) . '" height="150" />';
         echo '</br>';
    
    
    $selfdescription = Markdown($row['selfdescription']);
                           echo $selfdescription;
                           echo '</br></br>';
    echo '<table border="0">';
    
    echo '<tr>';
    echo '<td>';
    echo 'Email: ';
    echo '</td>';
    echo '<td><b>';
    echo $row['email'] . "</b>";
    echo '</td>';
    echo '</tr>';
    
    echo '<tr>';
    echo '<td>';
    echo 'Date joined: ';
    echo '</td>';
    echo '<td><b>';
    print date('d M Y', strtotime($row['datejoined']));
    echo "</b>";
    echo '</td>';
    echo '</tr>';
    
    echo '<tr>';
    echo '<td>';
    echo 'Last visit: ';
    echo '</td>';
    echo '<td><b>';
    print date('d M Y', strtotime($row['lastvisit']));
    echo "</b>";
    echo '</td>';
    echo '</tr>';
    
    echo '<tr>';
    echo '<td>';
    echo 'First name: ';
    echo '</td>';
    echo '<td><b>';
    echo $row['firstname'] . "</b>";
    echo '</td>';
    echo '</tr>';
    
    echo '<tr>';
    echo '<td>';
    echo 'Family name: ';
    echo '</td>';
    echo '<td><b>';
    echo $row['familyname'] . "</b>";
    echo '</td>';
    echo '</tr>';
    
    echo '<tr>';
    echo '<td>';
    echo 'Date of birth: ';
    echo '</td>';
    echo '<td><b>';
    print date('d M Y', strtotime($row['dob']));
    echo "</b>";
    echo '</td>';
    echo '</tr>';
    
    echo '<tr>';
    echo '<td>';
    echo 'Gender: ';
    echo '</td>';
    echo '<td><b>';
    echo $row['gender'] . "</b>";
    echo '</td>';
    echo '</tr>';
    
    echo '<tr>';
    echo '<td>';
    echo 'County: ';
    echo '</td>';
    echo '<td><b>';
    echo $row['county'] . "</b>";
    echo '</td>';
    echo '</tr>';
    
    echo '<tr>';
    echo '<td>';
    echo 'Postcode: ';
    echo '</td>';
    echo '<td><b>';
    echo $row['postcode'] . "</b>";
    echo '</td>';
    echo '</tr>';
    
    echo '<tr>';
    echo '<td>';
    echo '</br>';
    echo '<form action="editprofile.php">';
    echo '<input type="submit" name="" value="Edit Profile">';
    echo '</form>';
    echo '</td>';
    echo '</tr>';
    
    echo '</table>';
    
                   }
    
                $result2 = mysql_query("SELECT * FROM Eventparticipants WHERE participant = '$username'")
    or die(mysql_error());
    
    echo '</br><b>You are currently taking place in these events: </b></br>';
    echo "<form action='' method='POST' onsubmit='return executeOnSubmit();'>";
    echo '<table border="0">';
    while($row2 = mysql_fetch_array($result2))
    {
    
    
    echo '<tr>';
    echo '<td><a href="showevent.php?eventsID=';
    echo $row2['eventsID'];
    echo '">';
    echo $row2['eventdescriptionheader'];
    echo '</a></td>';
    
    
    echo "<td><input type='checkbox' name='eventsID[]' value='{$row2['eventsID']}' /></td>";
    echo '</tr>';
    
    
    }
    echo '</table>';
          echo "</br><input type='submit' value='Unsubscribe to event(s)' name='delete' />";
            echo '</form>';
    
                                $result4 = mysql_query("SELECT * FROM Events WHERE hoster = '$username'")
    or die(mysql_error());
    
    echo '</br><b>You are currently hosting these events: </b></br>';
    echo "<form action='' method='POST'>";
    echo '<table border="0">';
    while($row4 = mysql_fetch_array($result4))
    {
    
    
    echo '<tr>';
    echo '<td><a href="showevent.php?eventsID=';
    echo $row4['eventsID'];
    echo '">';
    echo $row4['eventdescriptionheader'];
    echo '</a></td>';
    
    
    
    echo '</tr>';
    
    
    }
    echo '</table>';
    
            echo '</form>';
    
    }
    
    
    ?>
    

     

    Much appreciated!

  7. Hi guys,

     

    I am very simply inserting text into a table with php and mysql, and outputting it, it all works fine but when I use paragraphs when inserting it, and then try to ouput it, all the paragraphs are gone and it looks like one big block of text, I suppose the way to go around this is to use <br> instead of just enters as it probably doesnt read this, but is it possible to make this text area do read and insert <br>'s where people use enter to make paragraphs?

     

    Much help appreciated, I realize this must be a very beginner question but I am not really sure how to word this so I wasn't sure on specific search on this.

     

     

  8. Hi guys I have got this code here, giving quite a few errors and was wondering if anyone could help me sort it out, the script (should) run straight away just have to edit the database connect, I've tried manually creating the table and taking out the create table but when I try and upload an image I get these errors:

     

    Warning: move_uploaded_file(latest.img) [function.move-uploaded-file]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/php/image.php on line 23

     

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/XAMPP/xamppfiles/temp/php2lgspw' to 'latest.img' in /Applications/XAMPP/xamppfiles/htdocs/php/image.php on line 23

     

    Warning: fopen(latest.img) [function.fopen]: failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/php/image.php on line 24

     

    Warning: filesize() [function.filesize]: stat failed for latest.img in /Applications/XAMPP/xamppfiles/htdocs/php/image.php on line 25

     

    Warning: fread() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/php/image.php on line 25

     

    here is the code:

     

    <?php
    
    // Connect to database
    
    $errmsg = "";
    if (! @mysql_connect("localhost","root","")) {
            $errmsg = "Cannot connect to database";
            }
    @mysql_select_db("test");
    
    // First run ONLY - need to create table by uncommenting this
    // Or with silent @ we can let it fail every subsequent time ;-)
    
    $q = < < <CREATE
    create table pix (
        pid int primary key not null auto_increment,
        title text,
        imgdata longblob)
    CREATE;
    @mysql_query($q);
    
    // Insert any new image into database
    
    if ($_REQUEST[completed] == 1) {
            // Need to add - check for large upload. Otherwise the code
            // will just duplicate old file ;-)
            // ALSO - note that latest.img must be public write and in a
            // live appliaction should be in another (safe!) directory.
            move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
            $instr = fopen("latest.img","rb");
            $image = addslashes(fread($instr,filesize("latest.img")));
            if (strlen($image) < 149000) {
                    mysql_query ("insert into pix (title, imgdata) values (\"".
                    $_REQUEST[whatsit].
                    "\", \"".
                    $image.
                    "\")");
            } else {
                    $errmsg = "Too large!";
            }
    }
    
    // Find out about latest image
    
    $gotten = @mysql_query("select * from pix order by pid desc limit 1");
    if ($row = @mysql_fetch_assoc($gotten)) {
            $title = htmlspecialchars($row[title]);
            $bytes = $row[imgdata];
    } else {
            $errmsg = "There is no image in the database yet";
            $title = "no database image available";
            // Put up a picture of our training centre
            $instr = fopen("../wellimg/ctco.jpg","rb");
            $bytes = fread($instr,filesize("../wellimg/ctco.jpg"));
    }
    
    // If this is the image request, send out the image
    
    if ($_REQUEST[gim] == 1) {
            header("Content-type: image/jpeg");
            print $bytes;
            exit ();
            }
    ?>
    
    <html><head>
    <title>Upload an image to a database</title>
    <body bgcolor=white><h2>Here's the latest picture</h2>
    <font color=red><?= $errmsg ?></font>
    <center><img src=?gim=1 width=144><br>
    <b><?= $title ?></center>
    <hr>
    <h2>Please upload a new picture and title</h2>
    <form enctype=multipart/form-data method=post>
    <input type=hidden name=MAX_FILE_SIZE value=150000>
    <input type=hidden name=completed value=1>
    Please choose an image to upload: <input type=file name=imagefile><br>
    Please enter the title of that picture: <input name=whatsit><br>
    then: <input type=submit></form><br>
    <hr>
    By Graham Ellis - graham@wellho.net
    </body>
    </html>
    

  9. I got it to work using:

     

      echo "<td>"; 
    print date('d M Y', strtotime($row['eventdate']));
    echo " ";
    echo $row['starttime'] . "</td>";
    
    

     

    Thanks guys, although I'd still like to know why this doesn't work if anyone could point that out?

     

    $date = $row['eventdate'];
    $my_date = strtotime($date); 
    
    
      echo "<td>" . date('d-m-Y',$my_date) . " " . $row['starttime'] . "</td>";
    

  10. Thanks for the help, at the moment I am first trying to turn yyyy/mm/dd around to dd/mm/yyyy with this:

     

    $date = $row['eventdate'];
    
      echo "<td>" . date('d-m-Y',$date) . " " . $row['starttime'] . "</td>";
    

     

    which puts it into dd/mm/yyyy great! although it is not showing the right dates! but automatically all dates seemed to change to 01/01/1970.. know why?

  11. I have got a date field in my mysql database with events, and as you know date in MYSQL uses yyyy/mm/dd but I would first like to turn this around to dd/mm/yyyy but also turn this into for example "Tuesday - May 1990" would anyone like to point me into the right direction?

     

    Much appreciated!

  12. 
    $result = mysql_query("SELECT * FROM Events ORDER BY eventdate");
    
    echo "<table border='0'>
    <tr>
    <th>Date/Time</th>
    <th>Event</th>
    <th>Participants</th>
    <th>Hoster</th>
    </tr>";
    
    while($row = mysql_fetch_array($result))
    {
    
      echo "<tr>";
      echo "<td>" . $row['eventdate'] . " " . $row['starttime'] . "</td>";
    
    echo '<td><a href="showevent.php?eventsID=';
    echo $row['eventsID'];
    echo '">';
    echo $row['eventdescriptionheader'];
    echo "</a></td>";
      echo "<td>" . $row['currentparticipants'] . "/" . $row['maxparticipants'] .  "</td>";
      echo "<td>" . $row['hoster'] . "</td>";
      echo "</tr>";
    }
    echo '</table>';
    }
    ?>
    
    

     

    eventdate is a date field in MYSQL

  13. Hey guys,

     

    I have got some events, and got it sorted by date, although at the moment the oldest date is showing first, and I would like to turn that around(new first old last), any simple suggestions?

     

    Also another little question how would I turn a date row (for example 2009/5/31) into Tuesday - May 2009 or something similar, anyone can point me into the right direction?

  14. Hi guys, I have a problem.. I have a table which shows the results, but the table is showing right at the bottom below the button "delete members" although the code is right above it so I don't really understand.. and hope someone can shed the light?

     

    Appreciated

     

    
    <?php
    include "connect.php";
    session_start();
    if(!isset($_SESSION['email']))
    {
    die('You have no access to this page.');
    }
    else{
    
    //Check if records were submitted for deletion
    if(isset($_POST['id']) && count($_POST['id']))
    {
        //Ensure values are ints
        $deleteIDs = implode(', ', array_map('intval', $_POST['id']));
        $query = "DELETE FROM member WHERE id IN ({$deleteIDs})";
        //Debug line
        echo "Successfuly deleted member(s)";
        mysql_query($query) or die(mysql_error());
    }
    ?>
      	<link rel="stylesheet" type="text/css" href="view.css" media="all">
    <script type="text/javascript" src="view.js"></script>
    <body id="main_body" >
    
    <img id="top" src="top.png" alt="">
    <div id="form_container">
    
    <h1>Consult, Modify or Delete a Member</h1>
    
    	<form id="form_362567" class="appnitro"  method="post" action="searchmember.php">
    				<div class="form_description">
    		<h2> Consult, Search, Modify or Delete a Member</h2>
    		<p></p>
    	</div>						
    		<ul >
    
    				<li class="section_break">
    
    
    <br>Search members with any keyword or character within the options id/email/firstname/lastname/phone/address1/address2/city/county/postcode - relevant matches will show.<br><br>
    <b>Keyword/Character:</b><br>
    <input id="search" name="search" class="element text medium" type="text" maxlength="50" value=""/> <br><br>
    <b>Search on</b>:<br>
    <select name="searchvalue" id="searchvalue">
    	<option name="id" id="id">id</option>
    <option name="email" id="email">email</option>
        <option name="firstname" id="firstname">firstname</option>
        <option name="lastname" id="lastname">lastname</option>
        	<option name="phone" id="phone">phone</option>
        	   <option name="address1" id="address1">address1</option>
        <option name="address2" id="address2">address2</option>
        	<option name="city" id="city">city</option>
        	   <option name="county" id="county">county</option>
        <option name="postcode" id="postcode">postcode</option>
        	
    </select><br><input type='submit' value='Search' name='go' /><INPUT TYPE="button" VALUE="Cancel" onClick="history.go(-1);return true;"><br>
    <br>
    To consult or modify a profile click on the member's E-mail address.	<li class="section_break">
    </form>
    <?php
    
    $result = mysql_query("SELECT * FROM member");
    ?>
    <table border='1'>
    <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Phone Number</th>
    <th>Postcode</th>
    <th>E-mail</th>
    <th>Delete</th>
    </tr>
    <?php
    while($row = mysql_fetch_array($result))
    {
    
    
    echo "<form action='' method='POST'>";  
    
      echo "<tr>";
      echo "<td>" . $row['firstname'] . "</td>";
      echo "<td>" . $row['lastname'] . "</td>";
        echo "<td>" . $row['phone'] . "</td>";
          echo "<td>" . $row['postcode'] . "</td>";
          
          	echo "<td>";
          	echo '<a href="consultmember.php?email=';
    echo $row['email'];
    echo '">';
    echo $row['email'];
    echo "</a></td>";
    	echo "<td><input type='checkbox' name='id[]' value='{$row['id']}' /></td>";
      echo "</tr>";
      
    
    }
    ?>
    <br><input type='submit' value='Delete Members' name='delete' /><INPUT TYPE="button" VALUE="Cancel" onClick="history.go(-1);return true;"><br>
    </form>
    		<div id="footer">
    
    	</div>
    </div>
    <img id="bottom" src="bottom.png" alt="">
    </body>
    
    <?php
    }
    ?>
    
    

  15. Thanks a lot for the timediff() I think that will help, and it makes sense to store the 3 selects into one variable and to send that through to the server, thanks for the input!

     

    to robertP

     

    I keep reading over the code you wrote and understand it considerably but would it be able for you to explain me how to use that in action?

     

    Appreciated

  16. I was using a date before but does it not require users to use dd/mm/yyyy ? I now have 3 selects which nicely lets user select the month day and year, is this possible to put into one date field? if so enlighten me!

     

    Back to the main question my age field at the moment is in the same table as the dob fields and it is an int. - or is this not what you meant?

     

    to floridaflatlander

     

    Is this tutorial about this certain question or similar? if so I will have a look

     

    Thanks for the help so far guys!

  17. Hi guys,

     

    My apologies if this is in the wrong forum but I am not really sure how to go about this.

     

    I have not written any code for this but I have four fields in one table one called age and 3 others dobmonth / dobday /dobyear -

     

    My question being how would I write some code that automatically fills in the age field based on the date of birth fields?

     

    If anyone could point me in the right direction that would be awesome,

     

    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.