PDA

View Full Version : Help


MJS
05-03-2007, 10:44 PM
Hi
Thanks for this very good forum and the tutorials on php and ajax. Ihave worked through these and have found them very helpful.
I have setup a webpage that has dropdowns init and all that works fine. I was trying to get the second dropdown when picked and submitted to goto a box on the same webpage and then to be saved to a database so it can be recalled when other members login so they can see the information.

Martin

davidj
05-04-2007, 09:28 AM
not sure what you want here

can you explain a bit more with an example

MJS
05-04-2007, 11:58 AM
Ok hope this helps.
so you select event and then availability and press submit. I would like it to go into the box of the event, that is there are three possibility's YES, NO, POS. and eleven events and I was trying to put the yes,no,pos into the right box for which event was called.
So in short if a member G0TVD logs in he could put his availability into each event box and it would be saved to the database, so it could be recalled when the next member calls in.
The full page has 15 members down the left hand side and 11 events across the top.
the image is only a test page.

Martin

davidj
05-04-2007, 03:03 PM
ok

i would create a new table called events and create a field for each event using the event as the field name ...

set that as a varchar and with dimensional size of 3

also you will need a user_id field and set this as a integer with a dimensional size of 3

it would be better to add the user id when you first set up a user. This can be done automatically which i can explain

///////////////

your user table should have a user id and when you log in to the application you can set the user id to a session

//////////////

in the page your adding the info for events you would have form fields that represent each event (probably on the top of the page)

your SQL query needs to update the event table so you would populate all the event fields using the WHERE user_id = '$_SESSION['user_id']'

pm me for more details

MJS
05-05-2007, 11:52 AM
Hi David

I have put together the database and I think I got it right see event.zip
The aval is the second drop down list, events is the list of events and users is the list of users and I have included the PHP page as it is so far.
the part I'm stuck on is the form field what type and should it be inside PHP.

MArtin

davidj
05-05-2007, 05:56 PM
forms should be POSTed

MJS
05-06-2007, 01:23 PM
is this OK for the form
<form id="Watford Half" name="form1" method="post" action="" >
<form id="Chilteern Challenge" name="form2" method="post" action="">
<form id="Keetch House" name="form3" method="post" action="">
<form id="Scout Event" name="form4" method="post" action="">

also I am unsure of the sql query where user_id and where it should go into the page Please remember I am new to this.
Martin

davidj
05-06-2007, 03:52 PM
you have 4 form tags and no form fields???

MJS
05-08-2007, 10:21 AM
Have got this right .

<th scope="row">G0TVD</th>
<form method="post" name="form0" action="">
</form>
<? $query = sprintf("SELECT * FROM users where user_id = '$SESSION['user_id']'");
$result = mysql_query($query);
$rowUser = mysql_fetch_array($result);?>
<td><form id="Watford Half" name="form1" method="post" action="">
</form>

davidj
05-08-2007, 10:33 AM
hi mate

your sprinting before you can walk

you need to understand the form mechanism first before you start using PHP

Your project is too advanced for your knowledge

MJS
05-08-2007, 10:49 AM
Thank you David for your reply I thought you would say something like that.
I did say way back that I have just started with web design and I just wanted to be pointed in the right direction, so it looks like I will have to do it in Dream weaver and its messy code (you words).

Thanks for all your help in the past.

Martin

davidj
05-08-2007, 02:09 PM
do a quick tut on forms and find out how they work

follow the vid tutorials and try to get an understanding

MJS
05-12-2007, 07:20 PM
Hi David
I have had a rethink on how to go about this page I was working on and have gone for checkbox for ease of use and I hope I have got to grips with the code.


<th width="272" scope="col"><form id="wat1" name="form1" method="post" action="">
<div align="center">
<input type="checkbox" name="YES" id="YES" value="YES"/>
<span class="style9">YES</span>
<label>
<input type="checkbox" name="NO" id="NO" value="NO" />
<span class="style9">NO</span></label>
<label class="style9">
<input type="checkbox" name="POS" id="POS" value="POS" />
POS</label>
</div>
</form> </th>

davidj
05-12-2007, 07:45 PM
your getting there but you have forgot a major component of the form!...

the submit button!

MJS
05-13-2007, 08:09 PM
David
I have eleven events each with it own form I have put the submit button at the end of the page will this work or do I have to put a submit button in each form.

davidj
05-13-2007, 08:23 PM
how do you know which form your wanting to submit?

if you have seperate none relating forms then you need a seperate button for each form. If your submitting every formfield at the same time you just need one button with one form tag

MJS
05-13-2007, 08:56 PM
Ok thanks david will Have a rethink and see if I can do it with one form.

MJS
05-14-2007, 04:31 PM
Like this one for each event

<th width="272" scope="col"><form id="wat1" name="form1" method="post" action="">
<div align="center">
<input type="checkbox" name="YES" id="YES" value="YES"/>
<span class="style9">YES</span>
<label>
<input type="checkbox" name="NO" id="NO" value="NO" />
<span class="style9">NO</span></label>
<label class="style9">
<input type="checkbox" name="POS" id="POS" value="POS" />
POS</label>
<label>
<input type="submit" name="Submit1" value="Submit" />
<input type="hidden" name="submitted" id="submitted" value="" />
</label>
</div>
</form> </th>

davidj
05-14-2007, 07:11 PM
ok that works

now what do you want to do

MJS
05-14-2007, 10:01 PM
The next step is to get it to update the database with the info that is put into one of the checkbox's then the info can be recalled to a page for viewing.

davidj
05-15-2007, 04:17 AM
have you covered the tutorials? SQL inserts etc

do you have your database in place

MJS
05-15-2007, 10:12 PM
This is the database lay out and I have just gone over the sql insert tutorial

does the database lay out look right there are 11 events and 15 event_id's this will match the 15 users_id

MJS
05-17-2007, 08:25 PM
Hi David
Have you had a chance to have a look at my database.zip will it work?

davidj
05-17-2007, 09:43 PM
yes they look ok

MJS
05-19-2007, 05:34 PM
Hi David
I have been trying to get this code to work part of it will but I can not get it to talk to the database here is the code.

<?php
session_start();
require_once("Connections/connection.php"); // database connection
///include('Includes/security.php');
//////////////////////
$eventid = $_POST['eventid'];
$wat1 = $_POST['wat1'];
$submitted = $_POST['submitted'];
////////////////
$query = sprintf("SELECT * FROM events where event_id = '$eventid' AND field2 = '$wat1'");
$result = @mysql_query($query);
$rowWat1 = @mysql_fetch_array($result);
/////////////////////////////
/////////////////////////////
$id = $_SESSION['id'].""; /// person logged on shows on to this page this works OK
/////////////////////////////////
if ($rowWat1 > 1 ){
////////////////////
$query = sprintf ("INSERT into wat1 value ($rowWat1)'");
@mysql_query($query)or die (mysql_error());
/////////////////////////////////////////////
}elseif($submitted && $rowWat1 == 0 ){
echo "All of the boxes are empty please tick one !"; ////this works OK
}
?>

MJS
05-24-2007, 12:25 PM
Hi David
Try number 2
I have been trying to get this code to work part of it will but I can not get it to talk to the database here is the code.



<?php
session_start();
require_once("Connections/connection.php"); // database connection
///include('Includes/security.php');
//////////////////////
$events= $_POST['events'];
$wat1 = $_POST['wat1'];
$submitted = $_POST['submitted'];
/////////////////////////////////////////////
$query = sprintf("SELECT * FROM events where event_id = 'event_id' AND WHERE wat1 = '$wat1'");
$result = @mysql_query($query);
$rowWat1 = @mysql_fetch_array($result);
/////////////////////////////
/////////////////////////////
$id = $_SESSION['id'].""; /// person logged on shows on to this page this works OK
/////////////////////////////////
if ($rowWat1 > 1 ){
////////////////////
$query = sprintf ("INSERT into events (wat1) value ($rowWat1)'");
@mysql_query($query)or die (mysql_error());
/////////////////////////////////////////////
}elseif($submitted && $rowWat1 == 0 ){
echo "All of the boxes are empty please tick one !"; ////this works OK
}
?>

davidj
05-24-2007, 12:29 PM
is your Select statement working?

davidj
05-24-2007, 12:37 PM
where you have this...

SELECT * FROM events where event_id = 'event_id' AND WHERE wat1 = '$wat1'");


its completly wrong

you dont have a variable here unless your looking for a string (event_id)

event_id = 'event_id'


you also have 2 WHERE clauses in your statement

it should be like this

SELECT * FROM events where event_id = '$event_id' AND wat1 = '$wat1'");

MJS
05-24-2007, 12:54 PM
Hi David
I
do not think the select statement is working I get this error.
Forbidden
You don't have permission to access /web_root/South_West_Herts_RAYNET/< on this server.

davidj
05-24-2007, 01:03 PM
where is your server

is it on a hosting service?

MJS
05-24-2007, 01:33 PM
no I have a testing server on this computer the hosting server is separate.

davidj
05-25-2007, 03:10 PM
are you logged into your machine as admin

MJS
05-25-2007, 08:41 PM
yes I can login with the members page OK it's when I run the event page and try to submit the data.

davidj
05-30-2007, 02:57 PM
the hosting server is separate.

is the hosting server on a live machine through a hosting account

MJS
05-30-2007, 02:59 PM
Yes localhost

davidj
05-30-2007, 03:00 PM
i mean do you pay for a hosting account? Is this a live account

MJS
05-30-2007, 03:01 PM
yes but my testing server is on my computer is this what you mean

davidj
05-30-2007, 03:04 PM
you dont have the rights to the dir on the live machine

you need to use an ftp client ro change the access rights of the live root dir or you could ask the hosting company to do this for you

MJS
06-01-2007, 01:55 PM
Have sorted this one I checked what I had done found and sorted the mistake "look and will see and read whats on the page" I think it gos.

MJS
06-02-2007, 11:06 AM
Hi David I am getting this "Duplicate entry '0' for key 1" when I run my event page and I have not a clue what I have done to the page.

MJS
06-02-2007, 04:56 PM
Found out not the page but the database

davidj
06-02-2007, 06:44 PM
are you trying to update the id field when its already an autoincrement

MJS
06-03-2007, 09:35 AM
I think that it

MJS
06-03-2007, 03:05 PM
David that the problem I am having can not get it to update the event : wat1

davidj
06-03-2007, 03:14 PM
post the code

MJS
06-04-2007, 09:38 AM
Hi David here is the code I have been trying to get this to work for days so have probably made a right cock up of it.
<?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
///////////////////////
$eventid = $_POST['event_id'];
$wat1 = $_POST['wat1'];
$submit = $_POST['submit'];
///////////////////////
/////////////////
$YES= $_POST['YES'];
$NO= $_POST['NO'];
$POS= $_POST['POS'];
$submit= $_POST['submit'];
$upd = $_GET['upd'];
///////////////////////////////////////
$query = sprintf("SELECT * FROM events where wat1 = '$wat1' = '$upd'");
$result = @mysql_query($query);
$rowWat1 = @mysql_fetch_array($result);
/////////////////////////////
$query= sprintf("INSERT INTO events (wat1) values ('$wat1')");
mysql_query($query) or die (mysql_error());
//////////////////////////////////////
if ($submit && $rowWat1){
////////////////////
/////////////////////////////////////////////
}elseif($submit && $rowWat1 == 0 ){
echo "All of the boxes are empty please tick one !";
}
?>

davidj
06-04-2007, 10:42 AM
first off you have this...


$YES= $_POST['YES'];
$NO= $_POST['NO'];
$POS= $_POST['POS'];



Just use 3 radio buttons called the same name like "available" and give each a label and a value -->

1 = YES
2 = NO
3 = Maybe

then you just need 1 $_POST['available'] variable.
////

you have this...

$query = sprintf("SELECT * FROM events where wat1 = '$wat1' = '$upd'");

this is illegal.

how can this work?...

wat1 = '$wat1' = '$upd'"

If you are still confused about this you need to revisit the tutorials or get a book on SQL

you have this


$query= sprintf("INSERT INTO events (wat1) values ('$wat1')");

Because your INSERT Statement is outside of an IF condition it will run every time the page is run

you have this...

if ($submit && $rowWat1){
////////////////////
/////////////////////////////////////////////
}elseif($submit && $rowWat1 == 0 ){
echo "All of the boxes are empty please tick one !";
}

what are you doing if the Condition is true?
What you have written is it will do nothing if the condition is true which is not really illegal but is bad programming. What do you want to happen if the condition is true?

It appears from what you have written and the way it has been written is your not grasping the concept. You need to cover the tutorials so you come away knowing how the condition works or how the script is read and interpreted by the engine.

MJS
06-04-2007, 01:14 PM
Thanks David for the commits I had been fiddling about with that code and can see the mistakes you have pointed out, I will work on them and get back to you.

MJS
06-04-2007, 05:16 PM
Have I got this right now or am i still up a gumtree.

$Yes = 1;
$No = 2;
$Maybe = 3;
$Yes = $_POST['available'] ;
$No = $_POST['available'];
$Maybe = $_POST['available'];

davidj
06-04-2007, 07:02 PM
ok

you have 3 radio buttons...

<form id="form1" name="form1" method="post" action="">
<input type="radio" name="available" id="available" value="1" />
<input type="radio" name="available" id="available2" value="2" />
<input type="radio" name="available" id="available3" value="3" />
</form>


with this setup you only need 1 $_POST ...

$available = $_POST['available'];

then just perform a switch on the var...

a SWITCH is just another type of IF statement and the argument passed ($available) into the SWITCH is valuated and if the following CASE is met the code after the CASE is executed and then BREAK out of the SWITCH.


switch($available){
case '1' : $event = "YES"; break;
case '2' : $event = "NO"; break;
case '3' : $event = "MAYBE"; break;
}


in your update statement you can perform the update like...
SQL...
update event_table set event_field = $event where event_id = $id