
|
View Full Version : Can you help me? Im a newb.... Some PHP stuff here... You PHP-gurus click right here!
amess 10-30-2002, 07:39 PM 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...:eek:
Rich2k 10-30-2002, 07:44 PM How about
$result = mysql_query("SELECT * FROM course");
$recordcount = mysql_num_rows($result);
if ($recordcount >= 20) {
echo ("This course is full");
}
However for 'good' sql that is cross compatible you should really use something like the following (but it can be faster to use the above if you have already called the table course)
$recordcount = mysql_result(mysql_query("SELECT COUNT(id) FROM course"),0);
if ($recordcount >= 20) {
echo ("This course is full");
}
ChickenSteak 10-31-2002, 02:22 AM You got to it before I did rich :). Well done.
jtrovato 10-31-2002, 08:24 AM 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.
Rich2k 10-31-2002, 08:59 AM It's the initial row number.
jtrovato 10-31-2002, 09:00 AM thanks never used that
Rich2k 10-31-2002, 09:50 AM 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])
amess 10-31-2002, 11:11 AM 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>");
}
}
?>
________________________________________________
Rich2k 10-31-2002, 12:03 PM 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.
jtrovato 10-31-2002, 04:36 PM 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'" ....
John
jtrovato 10-31-2002, 04:37 PM 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
John
amess 10-31-2002, 07:09 PM 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.-..
amess 10-31-2002, 07:11 PM :homer:
jtrovato 10-31-2002, 07:29 PM 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
John
amess 11-01-2002, 12:07 PM 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?
jtrovato 11-01-2002, 12:11 PM 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)
amess 11-01-2002, 12:16 PM 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
Rich2k 11-01-2002, 01:10 PM When you retrieve it from the database use the nl2br function! It'll put the carriage returns back in
amess 11-01-2002, 01:41 PM oh... ok then..
thanx
jtrovato 11-01-2002, 07:01 PM did it work for you?
|