Results 1 to 20 of 20
Hybrid View
-
10-30-2002, 07:39 PM #1Newbie
- Join Date
- Oct 2002
- Location
- Norway
- Posts
- 7
Can you help me? Im a newb.... Some PHP stuff here... You PHP-gurus click right here!
Im making a form where peeps can go in and register that they want to participate in a course or something....
I'm almoast done making the layout, code and stuff, but i want to close the registration when X has registred (lets say X = 20)
Like if 20 have registred, you cannot register...
I tried this:
<?php
$result = @mysql_query("SELECT * FROM course where id = 20");
if (isset($result)) {
echo("This course is full"); }
?>
this is not working, but im a complete newb... so dont make fun of me
(and please dont make the answer complex, the only thing i have read is "Build Your Own Database Driven Website Using PHP & MySQL
(First 4 Chapters)")
Can you please help me? I would really appreciate it!
Thank you...
-
10-30-2002, 07:44 PM #2Web Hosting Master
- Join Date
- May 2002
- Location
- UK
- Posts
- 2,997
How about
PHP Code:$result = mysql_query("SELECT * FROM course");
$recordcount = mysql_num_rows($result);
if ($recordcount >= 20) {
echo ("This course is full");
}
PHP Code:$recordcount = mysql_result(mysql_query("SELECT COUNT(id) FROM course"),0);
if ($recordcount >= 20) {
echo ("This course is full");
}
-
10-31-2002, 02:22 AM #3Disabled
- Join Date
- Aug 2002
- Posts
- 1,216
You got to it before I did rich . Well done.
-
10-31-2002, 08:24 AM #4Aspiring Evangelist
- Join Date
- Aug 2002
- Location
- Long Island
- Posts
- 427
Rich why do you put a "0" at the end of the result function?
Also amess you should look into a book called MySQL teach yourself in 21 days. it's not too bad, it helped me alot when I first started to learn SQL.
it will show you simple to more advanced SQL queries.
ISBN 0-672-31914-4
Good luck, not sure how deep you are going to get with PHP and MySQL.John Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.
-
10-31-2002, 08:59 AM #5Web Hosting Master
- Join Date
- May 2002
- Location
- UK
- Posts
- 2,997
It's the initial row number.
-
10-31-2002, 09:00 AM #6Aspiring Evangelist
- Join Date
- Aug 2002
- Location
- Long Island
- Posts
- 427
thanks never used that
John Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.
-
10-31-2002, 09:50 AM #7Web Hosting Master
- Join Date
- May 2002
- Location
- UK
- Posts
- 2,997
According to the PHP manual it's a required statement but I have to admit I don't use it either!
mixed mysql_result ( resource result, int row [, mixed field])
-
10-31-2002, 11:11 AM #8Newbie
- Join Date
- Oct 2002
- Location
- Norway
- Posts
- 7
Thanks for the help, but I cant get it to work... Please take a look at my code....
________________________________________________
<?
$dbcnx = @mysql_connect("localhost", "user",
"pass");
if (!$dbcnx) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
$result = mysql_query("SELECT * FROM kurs2;");
$recordcount = mysql_num_rows($result);
if ($recordcount >= 20) {
echo ("This course is full");
}
if ($meld == 1) {
$dbcnx;
@mysql_select_db("br");
$sql = "INSERT INTO kurs2 (kurs, bransatt, avd, kunde, kommentar, kontakt, overn, grkurs, date) values
('$kurs',
'$bransatt',
'$avd',
'$kunde',
'$kommentarer',
'$kontakt',
'$overn',
'$grkurs',
CURDATE());";
if (@mysql_query($sql)) {
echo("<p>thank you</p>");
} else {
echo("<p>error: " .
mysql_error() . "</p>");
}
}
?>
________________________________________________
-
10-31-2002, 12:03 PM #9Web Hosting Master
- Join Date
- May 2002
- Location
- UK
- Posts
- 2,997
What's your error message and what is going wrong with it? Is that a complete script as it doesn't appear to have anywhere defining what $meld is
Additionally you have connected to the mysql server but not connected to a database, you need to add
$dbsel = mysql_select_db($db, $dbcnx);
if (!$dbsel) {
print mysql_error();
exit;
}
between your SQL statement and your connection routine.
-
10-31-2002, 04:36 PM #10Aspiring Evangelist
- Join Date
- Aug 2002
- Location
- Long Island
- Posts
- 427
In addtion what kind of fields are the following:
$bransatt',
'$avd',
'$kunde',
'$kommentarer',
'$kontakt',
'$overn',
'$grkurs'
if they contain any string/text/char array you should format it this way:
'".$bransatt."', '".$avd."', '".$kunde."', '".$kommentarer."', '".$kontakt."', '".$overn."', '".$grkurs'" ....
JohnJohn Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.
-
10-31-2002, 04:37 PM #11Aspiring Evangelist
- Join Date
- Aug 2002
- Location
- Long Island
- Posts
- 427
I found to have errors doing the other way and find it to work better with the " "
I could be wrong but it's just my exprience
JohnJohn Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.
-
10-31-2002, 07:09 PM #12Newbie
- Join Date
- Oct 2002
- Location
- Norway
- Posts
- 7
Thank you!! it worked... i have some work left though.
But i have another question:
What kind of format can you set a mysql-row?
i know of text date time + but how can i make a multi-lined rows, f.ex. this forum...?
Thanks again.-..
-
10-31-2002, 07:11 PM #13Newbie
- Join Date
- Oct 2002
- Location
- Norway
- Posts
- 7
-
10-31-2002, 07:29 PM #14Aspiring Evangelist
- Join Date
- Aug 2002
- Location
- Long Island
- Posts
- 427
text field is nice.
I have a GREAT front end for MySQL for windows. if you are interested let me know and I'll send you the prog.
I learned alot from it and that's how I build all my database.
It's easier for me to do it that way, even now I know the datatypes and how to do it CLI
JohnJohn Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.
-
11-01-2002, 12:07 PM #15Newbie
- Join Date
- Oct 2002
- Location
- Norway
- Posts
- 7
Yeah, im interrested!
Please send the prog or link to download it
Thank you...
But when i format it as text, and someone enters some text in a textfield like this, the text just comes out as one line, depending on the tables width...
how can i make it as i want?
-
11-01-2002, 12:11 PM #16Aspiring Evangelist
- Join Date
- Aug 2002
- Location
- Long Island
- Posts
- 427
you can use an PHP function called nl2br to format the text as the user entered it.
echo nl2br (stripslashes($row->note));
$row->note being your variable what ever that might be. In my case I pulled the variable from an SQL query.
John
john@inofficenetworks.com (email me to forward the file to you)John Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.
-
11-01-2002, 12:16 PM #17Newbie
- Join Date
- Oct 2002
- Location
- Norway
- Posts
- 7
i dont think you understood me...
like
this
i
am
adding
new
lines....
when i do that is my form the whole thing comes on one line and theres just spaces insted of new lines. i want there to be lines!
hope you understand
-
11-01-2002, 01:10 PM #18Web Hosting Master
- Join Date
- May 2002
- Location
- UK
- Posts
- 2,997
When you retrieve it from the database use the nl2br function! It'll put the carriage returns back in
-
11-01-2002, 01:41 PM #19Newbie
- Join Date
- Oct 2002
- Location
- Norway
- Posts
- 7
oh... ok then..
thanx
-
11-01-2002, 07:01 PM #20Aspiring Evangelist
- Join Date
- Aug 2002
- Location
- Long Island
- Posts
- 427
did it work for you?
John Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.