PDA

View Full Version : Please Help me OH Magnificent one


MJS
06-12-2007, 04:48 PM
Ok David where do we start.

Karkar
06-12-2007, 10:14 PM
>>el oh el<< :-)

davidj
06-13-2007, 09:32 AM
Start this again so your not working around dodgy code

ok first step is to get a login system working

create a login system (using the tuts) and define a redirection for users and a one for admin.

your table needs to have a user_level field and you could use a numeric data type with a length of 1. This field is going to accept 2 numerics 1 & 2.

1 = admin
2 = user

when you log in you need to check not only the access is authentic (password and username) you are also going to grab the user_level value for that user.

The first condition your going to check the user to see if the password and user matches. If true , before you let them in your going to check the access level and if you detect a 1 redirect to admin page and if you detect a 2 redirect to user page.

in your admin page your going to have to setup a form that allows you to add new users and remember that you are also going to have to build in some functionality that changes or sets that users level. You need to be able to edit / add / delete users

get this up and running and we will move onto the next bit.

MJS
06-13-2007, 09:55 AM
OK do I have to have a admin page when I have full control over the data base on my website through PHP admin, this is the live site, on the testing server I use SQL Manager. I have a login system up and running and displaying user name on members page when they are logged in.

davidj
06-13-2007, 10:16 AM
ok

so you want to administer the site through your db

thats fine

the login is working and your displaying the session['user_id']

MJS
06-13-2007, 05:39 PM
yes all that works fine

davidj
06-13-2007, 06:34 PM
ok you have a number of events

are these events dynamic? Can you add Events

how do you want to display the events? In a matrix table with a dropdown in each row which contains availability options

MJS
06-13-2007, 08:05 PM
David I have a page made up already with radio buttons see Attachment.
I have been working on this page and have had some success I can update the DB but it changes all the events to the same thing.

davidj
06-13-2007, 09:53 PM
i have ripped out the duff code and tweaked it

your going to have to read through it and fill in ID values and check db SQL as this is probbably wrong because i guessed your naming conventions

it should give you a good foundation of where to start.

Take your time and double check everything (you had form fields incorrectly named and your logic was completly wrong)

This script wont work! but it gives you a blue print to work from


<?php
session_start();
require_once("Connections/connection.php"); // database connection
include('Includes/security.php');
//////////////////////////////////
$id = $_SESSION['id'].""; /// person logged on shows on to this page this works OK
///////////////////////
$available = $_POST['available'];
$available2 = $_POST['available2'];
$available3 = $_POST['available3'];
$available4 = $_POST['available4'];
$available5 = $_POST['available5'];
$available6 = $_POST['available6'];
$available7 = $_POST['available7'];
$available8 = $_POST['available8'];
$available9 = $_POST['available9'];
$available10 = $_POST['available10'];
$eventID = $_POST['eventID'];

if($eventID){
switch($eventID){

case '1': $field = "wat1"; $avail = $available; break;
case '2': $field = "chi2"; $avail = $available2; break;
case '3': $field = "kee3"; $avail = $available3; break;
case '4': $field = "wat1"; $avail = $available4; break;
case '5': $field = "wat1"; $avail = $available5; break;
case '6': $field = "wat1"; $avail = $available6; break;
case '7': $field = "wat1"; $avail = $available7; break;
case '8': $field = "wat1"; $avail = $available8; break;
case '9': $field = "wat1"; $avail = $available9; break;
case '10': $field = "wat1"; $avail = $available10; break;

}


////////////////////////////
$query = sprintf("update events set $field = '$event', availability = '$avail' where user_id = '$id'");
@mysql_query($query) or die (mysql_error());
////////////////////////////
}
?>

MJS
06-13-2007, 10:16 PM
Thanks for that will sort though it and get back to you .

MJS
06-15-2007, 02:11 PM
Hi David hows this looking.
<?php
session_start();
require_once("Connections/connection.php"); // database connection
include('Includes/security.php');
//////////////////////////////////
$id = $_SESSION['id'].""; /// person logged on shows on to this page this works OK
///////////////////////
$available = $_POST['available'];
$available2 = $_POST['available2'];
$available3 = $_POST['available3'];
$available4 = $_POST['available4'];
$available5 = $_POST['available5'];
$available6 = $_POST['available6'];
$available7 = $_POST['available7'];
$available8 = $_POST['available8'];
$available9 = $_POST['available9'];
$available10 = $_POST['available10'];
$eventID = $_POST['eventID'];
$yesnomaybe = $_POST['available'];
/////////
$Yes = 1;
$No = 2;
$Maybe = 3;
switch($yesnomaybe){
case '1' : $eventID = "Yes"; break;
case '2' : $eventID = "No"; break;
case '3' : $eventID = "Maybe"; break;
}
$avail = $_POST['wat1'];
if($eventID){
switch($eventID){
case '1': $field = "wat1"; $avail = $available; break;
case '2': $field = "chi2"; $avail = $available2; break;
case '3': $field = "kee3"; $avail = $available3; break;
case '4': $field = "wat4"; $avail = $available4; break;
case '5': $field = "sta5"; $avail = $available5; break;
case '6': $field = "bor6"; $avail = $available6; break;
case '7': $field = "bus7"; $avail = $available7; break;
case '8': $field = "mar8"; $avail = $available8; break;
case '9': $field = "lin9"; $avail = $available9; break;
case '10': $field = "pea10"; $avail = $available10; break;
}
////////////////////////////
$query = sprintf("update events set $field = '$eventID' , events = '$avail' where user_name = '$id'");
@mysql_query($query) or die (mysql_error());
////////////////////////////
}
?>

davidj
06-16-2007, 08:06 PM
im sorry mate this is completly wrong. Your not understanding the concept of PHP and what you have written is completly illogical to me. I dont understand your logic at all. I think your very lost with this stuff. I dont know what to do next to help you other than to write this for you myself.

MJS
06-16-2007, 08:39 PM
David can you point out which part is wrong, I take it's this part
////////////////////////////
$query = sprintf("update events set $field = '$eventID' , events = '$avail' where user_name = '$id'");
@mysql_query($query) or die (mysql_error());
////////////////////////////
I have been working on it and have got it to echo to the page which submit button it pressed with the name wat1,chi2 and so on,the code for this part now is.
////////////////////////////
$query = sprintf("update events set $field = '$event', eventID = '$avail' where user_name = '$id' and eventID = $field");
@mysql_query($query) or die (mysql_error());
////////////////////////////
I am trying to get to grips with php.

MJS
06-17-2007, 10:24 AM
I have had some success and can now update the database with this code it probably will need to be tidied up but it works.

<?php
session_start();
require_once("Connections/connection.php"); // database connection
include('Includes/security.php');
//////////////////////////////////
$id = $_SESSION['id'].""; /// person logged on shows on to this page this works OK
///////////////////////
$available = $_POST['available'];
$available2 = $_POST['available2'];
$available3 = $_POST['available3'];
$available4 = $_POST['available4'];
$available5 = $_POST['available5'];
$available6 = $_POST['available6'];
$available7 = $_POST['available7'];
$available8 = $_POST['available8'];
$available9 = $_POST['available9'];
$available10 = $_POST['available10'];
$eventID = $_POST['eventID'];
$submit = $_POST['submit'];
/////////
$Yes = 1;
$No = 2;
$Maybe = 3;
switch($available){
case '1' : $event = "Yes"; break;
case '2' : $event = "No"; break;
case '3' : $event = "Maybe"; break;
}
switch($available2){
case '1' : $event = "Yes"; break;
case '2' : $event = "No"; break;
case '3' : $event = "Maybe"; break;
}
switch($available3){
case '1' : $event = "Yes"; break;
case '2' : $event = "No"; break;
case '3' : $event = "Maybe"; break;
}
switch($available4){
case '1' : $event = "Yes"; break;
case '2' : $event = "No"; break;
case '3' : $event = "Maybe"; break;
}
switch($available5){
case '1' : $event = "Yes"; break;
case '2' : $event = "No"; break;
case '3' : $event = "Maybe"; break;
}
switch($available6){
case '1' : $event = "Yes"; break;
case '2' : $event = "No"; break;
case '3' : $event = "Maybe"; break;
}switch($available7){
case '1' : $event = "Yes"; break;
case '2' : $event = "No"; break;
case '3' : $event = "Maybe"; break;
}
switch($available8){
case '1' : $event = "Yes"; break;
case '2' : $event = "No"; break;
case '3' : $event = "Maybe"; break;
}
switch($available9){
case '1' : $event = "Yes"; break;
case '2' : $event = "No"; break;
case '3' : $event = "Maybe"; break;
}
switch($available10){
case '1' : $event = "Yes"; break;
case '2' : $event = "No"; break;
case '3' : $event = "Maybe"; break;
}
if($eventID){
switch($eventID){
case '1': $field = "wat1"; $avail = $available; break;
case '2': $field = "chi2"; $avail = $available2; break;
case '3': $field = "kee3"; $avail = $available3; break;
case '4': $field = "wat4"; $avail = $available4; break;
case '5': $field = "sta5"; $avail = $available5; break;
case '6': $field = "bor6"; $avail = $available6; break;
case '7': $field = "bus7"; $avail = $available7; break;
case '8': $field = "mar8"; $avail = $available8; break;
case '9': $field = "lin9"; $avail = $available9; break;
case '10': $field = "pea10"; $avail = $available10; break;
}
////////////////////////////
$query = sprintf("update events set $field = '$event' where user_name = '$id' ");
@mysql_query($query) or die (mysql_error());
////////////////////////////
}

echo $field;
echo $event;
?>

davidj
06-17-2007, 10:41 AM
ok who helped you?

it looks like you either woke up and the light went on or someone helped you?

MJS
06-18-2007, 01:30 PM
All my own work it just came to me I know what I wanted to do but could not get it through my thick brain but as you said the light came on and it all came together.

Now it get results from DB to a results page.

MJS
06-21-2007, 02:08 PM
Hi David I have been working on this results page and have got stuck is this code any good for getting results or have I got my self in a twist again.


<?php
session_start();
require_once("Connections/connection.php"); // database connection
include('Includes/security.php');
$id = $_SESSION['id']."";
$eventID = $_GET['eventID'];
//////////////////////////////////////////////
$query = sprintf("SELECT * FROM events where eventID = '$eventID' ORDER BY eventID ");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
/////////////////////////////////////

//////////////////////////////////////////
$field1 = $_POST['wat1'];
$field2 = $_POST['chi2'];
$field3 = $_POST['kee3'];
$field4 = $_POST['wat4'];
$field5 = $_POST['bor5'];
$field6 = $_POST['bus6'];
$field7 = $_POST['mar7'];
$field8 = $_POST['big8'];
$field9 = $_POST['lin9'];
$field10 = $_POST['pea10'];
$today = date("l : jS : F : Y");
?>

and this.


<? do{ ?>
<tr>
<th height="24" class="style9" scope="row"><form id="form1" name="form1" method="post" action="">
<div align="center">G0SGV </div>
</form> </th>
<td class="style9"><form action="" method="get" name="wat1" id="wat1">&nbsp;<?php echo $row['$field1']; ?></form></td>
<td class="style9"><form action="" method="get" name="chi2" id="chi2">&nbsp;<?php echo $row['$field2']; ?></form></td>
<td class="style9"><form action="" method="get" name="kee3" id="kee3">&nbsp;<?php echo $row['$field3']; ?></form></td>
<td class="style9"><form action="" method="get" name="wat4" id="wat4">&nbsp;<?php echo $row['$field4']; ?></form></td>
<td class="style9"><form action="" method="get" name="bor5" id="bor5">&nbsp;<?php echo $row['$field5']; ?></form></td>
<td class="style9"><form action="" method="get" name="bus6" id="bus6">&nbsp;<?php echo $row['$field6']; ?></form></td>
<td class="style9"><form action="" method="get" name="mar7" id="mar7">&nbsp;<?php echo $row['$field7']; ?></form></td>
<td class="style9"><form action="" method="get" name="big8" id="big8">&nbsp;<?php echo $row['$field8']; ?></form></td>
<td class="style9"><form action="" method="get" name="lin9" id="lin9">&nbsp;<?php echo $row['$field9']; ?></form></td>
<td class="style9"><form action="" method="get" name="pea10" id="pea10">&nbsp;<?php echo $row['$field10']; ?></form></td>
</tr>
<? }while ($row = mysql_fetch_array{$result)];?>
<tr>

to get it to display on a page but it dose not.....

Martin

davidj
06-21-2007, 02:20 PM
i can see what your after but you have some weird logic

i dont know what the $_POSTs are doing and you are using a $_GET to query a SELECT? using an event_id. Is this correct?

MJS
06-21-2007, 03:07 PM
OK the $_post is wrong I got it wrong I was trying it out, and I take it should be $field = wat1";

I was not sure what to put a post or a get I take it it should be a post..

davidj
06-21-2007, 03:10 PM
no thats not it

where are you using the $_POST vars?

You are setting some $field vars with the value of $_POST's but i cant see what or why your using them

MJS
06-21-2007, 03:34 PM
so I should have it with out the $_post : $field1 = $_post['wat1'] will now be $field1 = "wat1"; is this right so it is putting a value of wat1 into $field.

davidj
06-21-2007, 04:19 PM
i dont know what your using them for!

there is nothing after them in the script you posted so i cant see what they are for.

if i wrote ...

$var = $_POST['field'];

and there was nothing after it what would it mean? Im doing nothing with it so what does it do?

MJS
06-21-2007, 10:01 PM
OK david if I want to display the results from the database on a page, I thought you would have to put the data into var then get to echo on the page.

davidj
06-22-2007, 07:59 AM
yes thats right but $_POST is used to catch data from a form not display it in that way. You need to understand all this before you stand a chance of this sinking in. you need to use the variable from the recordset to display data on the page

MJS
06-22-2007, 12:17 PM
OK I can now get data from the DB with this

$query = sprintf("SELECT * FROM events ");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);

and it will display on the page with this
<td class="style9"><form action="" method="post" name="wat1" id="wat1">&nbsp;<?php echo $row['wat1']; ?></form></td>
<td class="style9"><form action="" method="post" name="chi2" id="chi2">&nbsp;<?php echo $row['chi2']; ?></form></td>
<td class="style9"><form action="" method="post" name="kee3" id="kee3">&nbsp;<?php echo $row['kee3']; ?></form></td>
<td class="style9"><form action="" method="post" name="wat4" id="wat4">&nbsp;<?php echo $row['wat4']; ?></form></td>
<td class="style9"><form action="" method="post" name="bor5" id="bor5">&nbsp;<?php echo $row['bor5']; ?></form></td>
<td class="style9"><form action="" method="post" name="bus6" id="bus6">&nbsp;<?php echo $row['bus6']; ?></form></td>
<td class="style9"><form action="" method="post" name="mar7" id="mar7">&nbsp;<?php echo $row['mar7']; ?></form></td>
<td class="style9"><form action="" method="post" name="big8" id="big8">&nbsp;<?php echo $row['big8']; ?></form></td>
<td class="style9"><form action="" method="post" name="lin9" id="lin9">&nbsp;<?php echo $row['lin9']; ?></form></td>
<td class="style9"><form action="" method="post" name="pea10" id="pea10">&nbsp;<?php echo $row['pea10']; ?></form></td>

how am I doing so far.

davidj
06-22-2007, 02:18 PM
yes i understand that

why have you got the echo'd vars in form tags

MJS
06-24-2007, 11:36 AM
Hi David I have done it got it to work may be the long winded way but it works here is part of the PHP code.ther are 15 SELCETs.

<?php
session_start();
require_once("Connections/connection.php"); // database connection
include('Includes/security.php');
$id = $_SESSION['id']."";
//////////////////////////////////////////////
$query = sprintf("SELECT wat1,chi2,kee3,wat4,bor5,bus6,mar7,big8,lin9,pea10 FROM events WHERE eventID = 1");
$result = @mysql_query($query);
$sgv = mysql_fetch_array($result);
/////////////////////////////////////////
$query = sprintf("SELECT wat1,chi2,kee3,wat4,bor5,bus6,mar7,big8,lin9,pea10 FROM events WHERE eventID = 2");
$result = @mysql_query($query);
$tvd = mysql_fetch_array($result);
/////////////////////////////////////////
$query = sprintf("SELECT wat1,chi2,kee3,wat4,bor5,bus6,mar7,big8,lin9,pea10 FROM events WHERE eventID = 3");
$result = @mysql_query($query);
$mpc = mysql_fetch_array($result);
/////////////////////////////////////////
$query = sprintf("SELECT wat1,chi2,kee3,wat4,bor5,bus6,mar7,big8,lin9,pea10 FROM events WHERE eventID = 4");
$result = @mysql_query($query);
$nuo = mysql_fetch_array($result);
/////////////////////////////////////////

and this is the HTML code to show it on the page.

<th height="24" class="style9" scope="row"><div align="center">G0SGV</div>
</th>
<td class="style9">&nbsp;<?php echo $sgv ['wat1']; ?></td>
<td class="style9">&nbsp;<?php echo $sgv ['chi2']; ?></td>
<td class="style9">&nbsp;<?php echo $sgv ['kee3']; ?></td>
<td class="style9">&nbsp;<?php echo $sgv ['wat4']; ?></td>
<td class="style9">&nbsp;<?php echo $sgv ['bor5']; ?></td>
<td class="style9">&nbsp;<?php echo $sgv ['bus6']; ?></td>
<td class="style9">&nbsp;<?php echo $sgv ['mar7']; ?></td>
<td class="style9">&nbsp;<?php echo $sgv ['big8']; ?></td>
<td class="style9">&nbsp;<?php echo $sgv ['lin9']; ?></td>
<td class="style9">&nbsp;<?php echo $sgv ['pea10']; ?></td>
</tr>

<tr>
<th height="24" class="style9" scope="row"><div align="center">G0TVD</div></th>
<td class="style9">&nbsp;<?php echo $tvd ['wat1']; ?></td>
<td class="style9">&nbsp;<?php echo $tvd ['chi2']; ?></td>
<td class="style9">&nbsp;<?php echo $tvd ['kee3']; ?></td>
<td class="style9">&nbsp;<?php echo $tvd ['wat4']; ?></td>
<td class="style9">&nbsp;<?php echo $tvd ['bor5']; ?></td>
<td class="style9">&nbsp;<?php echo $tvd ['bus6']; ?></td>
<td class="style9">&nbsp;<?php echo $tvd ['mar7']; ?></td>
<td class="style9">&nbsp;<?php echo $tvd ['big8']; ?></td>
<td class="style9">&nbsp;<?php echo $tvd ['lin9']; ?></td>
<td class="style9">&nbsp;<?php echo $tvd ['pea10']; ?></td>
</tr>

<tr>
<th height="24" class="style9" scope="row"><div align="center">G1MPC</div>
</th>
<td class="style9">&nbsp;<?php echo $mpc ['wat1']; ?></td>
<td class="style9">&nbsp;<?php echo $mpc ['chi2']; ?></td>
<td class="style9">&nbsp;<?php echo $mpc ['kee3']; ?></td>
<td class="style9">&nbsp;<?php echo $mpc ['wat4']; ?></td>
<td class="style9">&nbsp;<?php echo $mpc ['bor5']; ?></td>
<td class="style9">&nbsp;<?php echo $mpc ['bus6']; ?></td>
<td class="style9">&nbsp;<?php echo $mpc ['mar7']; ?></td>
<td class="style9">&nbsp;<?php echo $mpc ['big8']; ?></td>
<td class="style9">&nbsp;<?php echo $mpc ['lin9']; ?></td>
<td class="style9">&nbsp;<?php echo $mpc ['pea10']; ?></td>
<tr>
<th height="24" class="style9" scope="row"><div align="center">G1NUO</div>
</th>
<td class="style9">&nbsp;<?php echo $nuo ['wat1']; ?></td>
<td class="style9">&nbsp;<?php echo $nuo ['chi2']; ?></td>
<td class="style9">&nbsp;<?php echo $nuo ['kee3']; ?></td>
<td class="style9">&nbsp;<?php echo $nuo ['wat4']; ?></td>
<td class="style9">&nbsp;<?php echo $nuo ['bor5']; ?></td>
<td class="style9">&nbsp;<?php echo $nuo ['bus6']; ?></td>
<td class="style9">&nbsp;<?php echo $nuo ['mar7']; ?></td>
<td class="style9">&nbsp;<?php echo $nuo ['big8']; ?></td>
<td class="style9">&nbsp;<?php echo $nuo ['lin9']; ?></td>
<td class="style9">&nbsp;<?php echo $nuo ['pea10']; ?></td>
<tr>

davidj
06-24-2007, 12:30 PM
ecellent
do you understand it now

MJS
06-24-2007, 08:17 PM
Yes I think I do thanks for all your help David could not have done it with out your help......

MJS
06-25-2007, 11:51 AM
David when I put it on the live site the session do not work is this some thing that my website hosting admin has to sort out, it works fine on my test server here at home ?

davidj
06-25-2007, 12:02 PM
could be a global session issue

add a phpinfo() script to your server and run it. Compare that to your local setup and see whats different

MJS
06-26-2007, 09:55 AM
Hi David sorted the problem it was cookies.
Is it possible to have a e-mail sent when some one updates a availability page?

davidj
06-26-2007, 09:57 AM
yes just use the mail() command after the update


mail(string to, string subject, string message [, string additional_headers] [, string additional_parameters])


so in the TO parameter you would have your address then the message etc. You can ignore the additional headers

MJS
06-26-2007, 10:17 AM
Thanks David

MJS
06-26-2007, 11:04 AM
OK got it to work when you look at the page with this code
$xxxx = "xxxx@ntlworld.com";
$subject = "Page update";
$text = "The page has been updated";
mail ($xxxx, $subject, $text);
Is there a way to have it sent only when it updates
is it with a IF , ELSEIF statement.

davidj
06-26-2007, 01:27 PM
just stick it under the update (inside the IF)

when the update runs the mail will fire

MJS
06-27-2007, 01:25 PM
David is it posable to get the user name of the person who update the page in the e-mail.

Martin

davidj
06-27-2007, 01:32 PM
NOTE: \n is newline


$xxxx = "xxxx@ntlworld.com";
$subject = "Page update";
$text = $username; // << just add this to the $text var. $username is your user
$text .= "\nThe page has been updated\n"; //<< add a .= to append this var with the one above
mail ($xxxx, $subject, $text);

davidj
06-27-2007, 01:39 PM
i cant believe how advanced you have become in such a short space of time. Its as if the penny has dropped

MJS
06-27-2007, 04:33 PM
Thank David could not have done it with out your help.
I have replaced the $username with $id in the above text and it works fine.