You are here: Re: Decrementing a number... « All PHP « IT news, forums, messages
Re: Decrementing a number...

Posted by plato on 10/10/22 11:27

"Sander" <sander is settled at cartel in nl> wrote in message
news:4334f052$0$24791$ba620dc5@text.nova.planet.nl...
>
> > <?PHP
> >
> > //alter you variables here
> > //alter you variables here
> > $host = "localhost";
> > $username="";
> > $password="";
> > $database="paul";
> >
> > $submit = $_POST['submit'];
> > $course = $_POST['course'];
> >
> > //
> > $link = mysql_connect($host, $username, $password)
> > or die("Cannot connect to database");
> >
> > mysql_select_db($database)
> > or die("Cannot select database");
> > print("Debug: $course<br>");
> >
> > //check if we can update the database
> > if($submit)
> > {
> > $result = mysql_query("update test set places=places-1 where
> > number='$course'")
> > or die("Update cannot be executed");
> >
> > print("Changed database<br>");
> > }
> >
> >
> > //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 test ";
> > $result = mysql_query($query)
> > or die("Query cannot be executed");
> >
> > print("<FORM method=post>\n");
> > print("<SELECT name=course>\n");
> > //now we are going to print the information to your screen
> > while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
> > printf("<OPTION value='%s'> %s (%s places available)</OPTION>\n",
> > $row['course'],$row['course'],$row['places']);
> > }
> > print("</SELECTED>\n");
> > print("<INPUT name='submit' type='submit'>\n");
> > print("</FORM>\n");
> > ?>
> > The result:
> > Debug: Course 1
> > Update cannot be executed
> >
> > Not sure what is wrong... don't know why the db won't update. Any ideas
I
> > can try/check?
> >
> > thanks
> >
> > plato
> >
> >
>
> Dude,
>
> I told you before. You copied and pasted my code directly but it has
> different fieldnames in the MySQL than you have in you MySQL.
>
> Here look at this 2 sentences:
> 1. $result = mysql_query("update test set places=places-1 where
> number='$course'")
>
> 2. printf("<OPTION value='%s'> %s (%s places available)</OPTION>\n",
> $row['course'],$row['course'],$row['places']);
>
>
> Line 1:
> You want to update your table named test and lowers the value places in
the
> database with 1. The update criteria is after the "where" in this line and
> it says that php has to perform this action only if in your database there
> is a record called number and it has a value of posted in $course. I bet
you
> have to rename the word " number" to "course".
>
> Line 2:
> In line 2 you can see that you read the records course and places. So if
> that is giving you any output change the word "number" in the update
> statement to "course"
>
> Sander
>
Thanks Sander,

Yes you're right... I missed that one... works great now...thanks heaps..

cheers

Plato

 

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

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