You are here: Re: Basic PHP question... « All PHP « IT news, forums, messages
Re: Basic PHP question...

Posted by Sander on 09/20/05 17:43

"plato" <platoTAKETHISOUT@telpacific.com.au> schreef in bericht
news:43300681@news.rivernet.com.au...
>I think this is more php than sql.
>
> I want to create a form which has a check box which adds entries to a
> database e.g. value= course_1 and also on the form is a number denoting
> places available e.g. value = places_1
> <check box> Course 1 (There are 11 places available)
>
> each time a form with a course selected is submitted the next time the
> form
> is accessed it reduces the places available by 1 until it reaches 0 when
> an
> error message is returned.
>
> Can someone give me an idea of the script I can use to practice this?

What you basically want is a php page that refeshes the free place for a
certain course. So lets just assume you have:
coursename places_avail
course_a 3
course_b 15
course_c 9

You want you'r page to read the course name's, put them in a drop-down list,
and print the availability at the very end.

We can start with just a very simple script like this:
<?PHP

//alter you variables here
$host = "localhost";
$username="";
$password="";
$database="";

// create link to database
$link = mysql_connect($host, $username, $password)
or die("Cannot connect to database");

mysql_select_db($database)
or die("Cannot select database");

//now we make te query which will ask the database for the course
information
//change the my_table to your course table name

$query = "SELECT * FROM my_table";
$result = mysql_query($query)
or die("Query cannot be executed");

//now we are going to print the information to your screen
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("Coursename: %s Availability: %s<br>", $row[0], $row["1"]);
}
?>

It is just that simple. Next you have to do is put them i a drop-down menu.
That is nothing more that changing the printf to something that included the
HTML tag <OPTION>.

You also want to update your page. That is just an update or insert in a
mysql and after refreshing the current page things will work just as you
wanted.

I hope this solves your question. If you need more on this. You know where
to find the answers... here.

Sander Swuste

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация