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

Posted by plato on 09/21/05 02:45

"plato" <platoTAKETHISOUT@telpacific.com.au> wrote in message
news:433082c3@news.rivernet.com.au...
>
> "Sander" <swuste zit bij cartel.nl> wrote in message
> news:43301fef$0$11867$ba620dc5@text.nova.planet.nl...
> >
> > "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
> >
> Thanks Sander I will give it a go...much appreciated.
>
OK this is what I have done:

Here is my database details:
SQL-query:
INSERT INTO `course` ( `number` , `places` )
VALUES (
CHAR( 'Course 1' ) , '9'
), (
'Course 2', '11'
);
I ran this php script:
<?PHP

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

// 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 the query which will ask the database for the course
information
//change the my_table to your course table name

$query = "SELECT * FROM course";
$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 ("number: %s places: %s<br>", $row[0], $row["1"]);
}
?>
And I get this error:
Parse error: syntax error, unexpected T_VARIABLE in c:\wamp\www\paul.php on
line 20

Comments?

 

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

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