Announcements | Last Post | |
---|---|---|
SoC Curricula | 09/30/2017 01:08PM | |
Demarcation or scoping of examinations and assessment | 02/13/2017 07:59AM | |
School of Computing Short Learning Programmes | 11/24/2014 08:37AM | |
Unisa contact information | 07/28/2011 01:28PM |
GET and POST September 02, 2011 12:16PM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Then you can only catch the form variables with $_GET, as inLanguage: PHPecho "<a href=edit.php?book_id=$book_id&update=yes>Edit</a>";
Language: PHP$book_id=$_GET[';book_id';];
See? 564,155263 was passed to this page (Here they did no associated it with a name as they handle it differently, but you get the point). Now you can see what you've sent was in fact sent, and therefore you know where to look for errors.Language: HTMLhttp://osprey.unisa.ac.za/phorum/read.php?564,155263
Re: GET and POST September 02, 2011 09:56PM |
Registered: 12 years ago Posts: 20 Rating: 0 |
Anonymous User
Re: GET and POST September 03, 2011 12:25PM |
Rating: 0 |
Re: GET and POST September 04, 2011 06:08PM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Anonymous User
Re: GET and POST September 13, 2011 09:07AM |
Rating: 0 |
Re: GET and POST September 13, 2011 10:12AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Language: PHP$car_id = $_GET[';car_id';]; echo "car_id = $car_id"; $sql = "SELECT car_name, model, year, price FROM cars WHERE car_id = ';$car_id';"; $result = mysql_query($sql) $num_rows=mysql_num_rows($sql); echo "$num_rows"; //shows how many rows were found // while loop { //form }
Re: GET and POST September 13, 2011 11:36AM |
Registered: 12 years ago Posts: 25 Rating: 0 |
Re: GET and POST September 14, 2011 08:53AM |
Registered: 12 years ago Posts: 42 Rating: 0 |
Re: GET and POST September 14, 2011 11:02AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: GET and POST September 15, 2011 12:22AM |
Registered: 12 years ago Posts: 54 Rating: 0 |
but it does not print the info, its just prints "$manufacturer"Language: PHP<td>Manufacturer</td><td><input name="manufacturer" type="text" value="<?php echo ';$manufacturer';;?>"> </input></td
Language: PHP<?php $car_id= $_GET[';car_id';]; $manufacturer = $_GET[';manufacturer';]; $make = $_GET[';make';]; $year = $_GET[';year';]; $price = $_GET[';price';]; $sql = "SELECT manufacturer, make, year, price FROM cars WHERE car_id = ';$car_id';"; $result = mysql_query($sql) ?> // then i have my form <form Method="POST" ACTION="edit.php"> <table border="2" align="center"> <tr> <td>Manufacturer</td><td><input name="manufacturer" type="text" value="<?php echo ';$manufacturer';;?>"> </input></td> </tr>
Re: GET and POST September 15, 2011 06:54AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Language: PHP$manufacturer = "BMW"; value="<?php echo ';$manufacturer';;?>"> //will print $manufacturer value="<?php echo "$manufacturer";?>"> //will print BMW. String are in double quotes
Language: PHP$value=';21';; //or $value="21"; or $value=21; // numeric value value="<?php echo "$value";?>"> //will print the 21 value="<?php echo ';$value';; ?>"> //will print $value
Re: GET and POST September 15, 2011 10:48AM |
Registered: 12 years ago Posts: 54 Rating: 0 |
Re: GET and POST September 15, 2011 11:02AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Language: PHP$car_id= $_GET[';car_id';]; //this is OK $manufacturer = $_GET[';manufacturer';]; //you did not pass this so why put it here? $make = $_GET[';make';]; //you did not pass this so why put it here? $year = $_GET[';year';]; //you did not pass this so why put it here? $price = $_GET[';price';]; //you did not pass this so why put it here? $sql = "SELECT manufacturer, make, year, price FROM cars WHERE car_id = ';$car_id';"; //you only passed the car_id, and use that to get the rest of the information from the db. $result = mysql_query($sql) //here you get the values of manufacturer, make, etc.
Re: GET and POST September 16, 2011 12:10AM |
Registered: 12 years ago Posts: 54 Rating: 0 |
Language: PHP$car_id= $_GET[';car_id';]; $query = "SELECT manufacturer, make, year, price FROM cars WHERE car_id = ';$car_id';"; $result = mysql_query($query); while($row = mysql_fetch_array(result)){ $manufacturer = $row[';manufacturer';]; $make = $row[';make';]; $year = $row[';year';]; $price = $row[';price';]; } //I tried putting an echo statement here to test the variable, eg the $manufacturer but it prints nothing
Language: PHP//Then I have my form <input name="manufacturer" type="text" value="<?php echo "$manufacturer";?>"></input>
Re: GET and POST September 16, 2011 07:05AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Language: PHP$car_id= $_GET[';car_id';]; //does the URL show the id e.g. edit.php?car_id=12 // if so, echo "$car_id"; to see if it is caught. // is the connection to the db working? The "or die..." part will tell you if there is a problem mysql_connect("localhost", "admin", "1admin") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $query = "SELECT manufacturer, make, year, price FROM cars WHERE car_id = ';$car_id';"; $result = mysql_query($query) or die mysql_error()); // another or die test while($row = mysql_fetch_array(result)){ $manufacturer = $row[';manufacturer';]; $make = $row[';make';]; $year = $row[';year';]; $price = $row[';price';]; //and so on
Re: GET and POST September 16, 2011 12:12PM |
Registered: 12 years ago Posts: 54 Rating: 0 |
in my include ('connect.php'; so it would have print an error already.Language: PHP$connection = mysql_connect ("localhost","root","") or die ("Couldn';t connect to server"); $db = mysql_select_db("carsales", $connection) or die ("Couldn';t select database");
Re: GET and POST September 16, 2011 12:20PM |
Registered: 12 years ago Posts: 4 Rating: 0 |
Re: GET and POST September 16, 2011 01:54PM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: GET and POST September 16, 2011 03:13PM |
Registered: 12 years ago Posts: 54 Rating: 0 |
Anonymous User
Re: GET and POST September 16, 2011 03:20PM |
Rating: 0 |
Re: GET and POST September 17, 2011 03:21PM |
Registered: 12 years ago Posts: 54 Rating: 0 |
The echo in the value field of my form does not print anything in the text box of my form, please help...also will it be better to put the while loop inside the form?Language: PHPwhile($row = mysql_fetch_array(result)){ $manufacturer = $row[';manufacturer';]; $make = $row[';make';]; $year = $row[';year';]; $price = $row[';price';]; //I tried putting and echo here for $manufacturer but it does not print anything.
Re: GET and POST September 18, 2011 11:44PM |
Registered: 12 years ago Posts: 54 Rating: 0 |
Re: GET and POST September 19, 2011 06:45AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: GET and POST September 19, 2011 04:08PM |
Registered: 12 years ago Posts: 42 Rating: 0 |
Language: PHP$car_id = $_GET[';car_id';]; if(isset($_REQUEST["update"])){ $sql = "UPDATE cars SET car_name=';$car_name';, model=';$model';, year=';$year';, price=';$price'; WHERE car_id=';$car_id';"; $results = mysql_query($sql); } // select query display fine //while loop{ } } ?> <form method="GET" action="edit.php"><center> Car name : <input type= "text" > Model : <input type= "text" > Year : <input type= "text" > Price : <input type= "text"> <input type="submit" name="update" value="Update"> </form>
Re: GET and POST September 19, 2011 05:22PM |
Registered: 12 years ago Posts: 31 Rating: 0 |
Re: GET and POST September 20, 2011 06:51AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: GET and POST September 20, 2011 08:44AM |
Registered: 12 years ago Posts: 31 Rating: 0 |
Re: GET and POST September 20, 2011 09:37AM |
Registered: 12 years ago Posts: 42 Rating: 0 |
Re: GET and POST September 20, 2011 10:49AM |
Registered: 12 years ago Posts: 31 Rating: 0 |
Re: GET and POST September 20, 2011 02:44PM |
Registered: 12 years ago Posts: 42 Rating: 0 |
Re: GET and POST September 20, 2011 04:31PM |
Registered: 12 years ago Posts: 42 Rating: 0 |
Re: GET and POST September 21, 2011 10:04AM |
Registered: 12 years ago Posts: 31 Rating: 0 |
Re: GET and POST September 22, 2011 09:06AM |
Registered: 12 years ago Posts: 42 Rating: 0 |
Re: GET and POST September 22, 2011 09:30AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: GET and POST September 23, 2011 12:45PM |
Registered: 12 years ago Posts: 17 Rating: 0 |
Re: GET and POST September 26, 2011 06:42AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: GET and POST September 26, 2011 01:36PM |
Registered: 12 years ago Posts: 17 Rating: 0 |
Language: PHP//get the id //select frm the database using the id //while loop { //get the fields using id } if (isset($_GET[';id';])== "Yes"){ //put the delete code }
Re: GET and POST September 26, 2011 03:57PM |
Registered: 12 years ago Posts: 39 Rating: 0 |
Re: GET and POST September 26, 2011 03:59PM |
Registered: 12 years ago Posts: 39 Rating: 0 |
Re: GET and POST September 27, 2011 06:52AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Language: PHPthe link is send e.g. ?id=$id&delete=yes if delete ==yes { do you want to delete? <a href=... ?delete=absolutely&id=$id>Yes <a href=...list.php>No</a> }elseif delete==absolutely { delete }
Re: GET and POST September 27, 2011 06:53AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: GET and POST September 29, 2011 11:10AM |
Registered: 12 years ago Posts: 17 Rating: 0 |
Re: UPDATING September 30, 2011 02:51PM |
Registered: 12 years ago Posts: 20 Rating: 0 |
now here is the update sql:Language: PHP
Language: PHPelseif($_submit[code="php"] =$_GET[';update';]) // IF THE FORM WAS SUBMITTED WITH UPDATED INFORMATION, THEN UPDATE THE DB { $SQL="UPDATE my_discs SET category=';$category'; WHERE disc_id=';$disc_id';" ; $result=mysql_query($SQL)or die("query failed:" .mysql_error()); }
Re: GET and POST October 03, 2011 07:08AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: GET and POST October 03, 2011 08:57AM |
Registered: 12 years ago Posts: 17 Rating: 0 |
Re: GET and POST October 03, 2011 10:13AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: DELETE October 03, 2011 11:36AM |
Registered: 12 years ago Posts: 20 Rating: 0 |
Please help i'm only left with this page.Language: PHPif(isset($_GET[';disc_id';])){ $disc_id =$_GET[';disc_id';]; if (delete=="yes") { $error="do you want to delete? <a href=';delete.php';>Yes </a><a href=';list.php';>No</a></p>"; }elseif (delete=="absolutely") { $sql= "SELECT * FROM my_discs WHERE disc_id=';$disc_id';"; $sql="DELETE FROM my_discs WHERE disc_id=';$disc_id';";//delete all from the table named my_discs $result = mysql_query($sql)or die("query failed:" .mysql_error()); }
Re: GET and POST October 03, 2011 12:05PM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: GET and POST October 03, 2011 12:54PM |
Registered: 12 years ago Posts: 42 Rating: 0 |