Welcome! Log In Create A New Profile

Advanced

EDITING

Posted by ronk 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
EDITING
September 20, 2011 02:00PM
hello mac I'm having a problem when i wanna update the content of my table if i click the edit link my edit page appear but without the value of the content as yours does, is it possible for you to explain what function can i use to retrieve the table content.
avatar
Mac
Re: EDITING
September 20, 2011 02:15PM
That is explained at length in the tut letter?
It is not a function - it is just code, specifically a mysql query using the id that you have passed with the link.
Re: EDITING
September 20, 2011 02:24PM
OK thank you mac i will check, i hope it will help.
Re: EDITING
September 23, 2011 11:59AM
Ronk, try as hard as you can, you can unlock that chateau-fort. Maybe it's just a problem of syntax...
All the best.
Re: EDITING
September 26, 2011 10:48AM
hello Mac I'm having a problem of catching the id_x that was created by the link <a href =edit.php?id_x = $id_x &upate = yes>Edit </a> in the list page;
if i hover the cursor on the edit link or delete link it shows me the right id_x of a specific item and if i click on the link it direct me in the edit with the showing the x_id only in the address bar, now the problem is when i echo the x_id to be sure that the link works it doesn't show the id_x, please help i have been trying to sort it out but i couldn't.
avatar
Mac
Re: EDITING
September 27, 2011 06:58AM
If it is passed correctly - as you describe, then it is caught incorrectly. I am not going to post code here - post a selection of yours - how you are catching it for example..
Re: EDITING
September 27, 2011 11:10AM
Language: PHP
$x_id = GET[x_id]; // this is my catching echo " x_id = $x_id" // just wanted to make show that the x_id is catch correctly unfortunately it shows x_id = nothing
avatar
Mac
Re: EDITING
September 27, 2011 12:23PM
Language: PHP
edit.php?x_id=$x_id $x_id = GET[';x_id';]; //in single quotes
Re: EDITING
September 28, 2011 11:06AM
thank you mac but i wrote it between single quote.
look now i delete all my code in the edit page I'm just left with this
Language: PHP
//this is what is displayed in the address bar after clicking one of the edit link http://localhost/portfolio/edit.php?x_id = 0 //the following code is my simplify edit page <?php include(';connect.php';);   $x_id = $_GET[';x_id';]; // catching the x_id from the list page echo" ID = $x_id"; //displaying the value to make sure the x_id is caught correctly in the edit page   ?>

normally it's suppose to display ID = 0

surprisingly it displays ID =

or is there anything wrong with this simple code????
avatar
Mac
Re: EDITING
September 28, 2011 12:43PM
No, there is nothing wrong that I can see. Since it is GET, what does the URL have in it on this page? Does the x_id appear there with a value e.g. ?x_id=2?
Re: EDITING
September 28, 2011 01:22PM
the URL displayed http://localhost/portfolio/edit.php?x_id = 0
Re: EDITING
September 28, 2011 01:30PM
confused smileynow i don't know what to do? I'm stuck because of the id_x is not catch in the edit and delete page. confused smileyconfused smiley
avatar
Mac
Re: EDITING
September 28, 2011 01:52PM
Impossible. It MUST echo the value....
Do you have more entries to test that is passed x_id=1, x_id=2 etc?

OK wait - there are spaces in the URL if that is precisely how you get it - there must not be. Apache is supposed to handle this, but I assume you did something funny on the previous page.

Language: PHP
edit.php?x_id=0 // no spaces edit.php?x_id = 0 // spaces!
Re: EDITING
September 30, 2011 12:34PM
thank you mac that was the only error now I'm done with my portfolio.thank you very much.thumbs upsmile
Re: EDITING
October 04, 2011 10:46AM
Hi Mac,i just want to as if i would be wrong to add the if statements that i have used on the insert page to the update page,eg-On the insert page i want the page to be submited when all the fields are not empty,would i be wrong if iuse this on tha update page so that the user does not update the field with empty values.
avatar
Mac
Re: EDITING
October 04, 2011 12:34PM
You can add what you want - I prescribe a way to do it and there are many ways.
Re: EDITING
October 07, 2011 03:17PM
i have try to edit but it give the ease part, is it that the code is wrong or the logic is not correct, here is the code, "my id = shop_name"
Language: PHP
if (isset($_GET[';shop_name';]) && is_numeric($_GET[';shop_name';]) && $_GET[';shop_name';] > 0) { // query db $shop_name = $_GET[';shop_name';]; $result = mysql_query("SELECT * FROM stock WHERE shop_name=$shop_name") or die(mysql_error()); $row = mysql_fetch_array($result);
avatar
Mac
Re: EDITING
October 07, 2011 05:03PM
shop_name is larger than zero? There is a function is_not_empty, else you have to find the string length (strlen function) first and compare that to zero.
Re: EDITING
October 15, 2011 11:01PM
Hello Mac
I'm almost done with my portfolio but I'm experiencing problems with my mysql Update syntax. I've done lots of checking but I can't seem to find the problem. This is the error I keep getting:

"Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('item' = Streamers, 'printed'=Yes, 'notice'=2 days, 'quantity'=20, 'price'=R45.' at line 1"

And this is my code

Language: PHP
$query = "UPDATE supplies SET (item = $item, printed=$printed, notice=$notice, quantity=$quantity, price=$price) WHERE sup_id = $supID"; $result = mysql_query($query) or die("Query failed: ".mysql_error());
Re: EDITING
October 15, 2011 11:52PM
OK. Never mind. I found the problem. I changed my code from this:
Language: PHP
$query = "UPDATE supplies SET (item = $item, printed=$printed, notice=$notice, quantity=$quantity, price=$price) WHERE sup_id = $supID"; $result = mysql_query($query) or die("Query failed: ".mysql_error());

To this:
Language: PHP
$query = "UPDATE supplies SET (item = ';$item';, printed=';$printed';, notice=';$notice';, quantity=';$quantity';, price=';$price';) WHERE sup_id = ';$supID';"; $result = mysql_query($query) or die("Query failed: ".mysql_error());
I'm not sure how to explain it, but the spaces in the values I put into the text fields caused problems with mysql. Just like how they cause problems when you send from mysql to php.
avatar
Mac
Re: EDITING
October 17, 2011 06:36AM
This has been answered elsewhere, which brings home the point I am trying to push all along - read the forum before you post queries in case the solution is already available.....thumbs up
Re: EDITING
October 17, 2011 09:00AM
I did look. I must have obviously looked in the wrong places. But I really did spend at least half an hour reading through older posts, but found nothing about it. Anyway. I solved the problem now and its all good. I must saying I'm really enjoying doing this portfolio. Its such a nice feeling watching your work coming together and your website doing what you want to do. Just sweet.grinning smiley
avatar
Mac
Re: EDITING
October 17, 2011 02:45PM
Good. That is what I want to achieve. It is empowering.
Re: EDITING
October 20, 2011 01:42PM
Hi guys

I am having challenges getting my edit and delete_yes pages working. My edit code does bring the information onto the form for the user to edit and update but when the user clicks on Update he is taken back to the declaration of the cd_id - $cd_id=$_GET["cd_id"]; - and told of the undefined index cd_id. The database does not get updated. It could be a small error, but I dont seem to be finding it. My code is as follows:


Language: PHP
//include connection <?PHP   //declaration of variables   $result = mysql_query("UPDATE music SET cd_title=';$cd_title';, artist_name=';$artist_name';, artist_surname=';$artist_surname';,price=';$price'; WHERE cd_id=';$cd_id';") or die(mysql_error());     ?> <html> <body>   <FORM METHOD = ';POST'; ACTION ="edit.php" > <?php   $cd_id=$_GET["cd_id"]; if (isset($_GET["cd_id"])) {   //echo the cd_id value to test if you caught it from the list/database }   $result = mysql_query("SELECT * FROM music WHERE cd_id =';$cd_id';") or die(mysql_error()); $rows = mysql_num_rows($result);   while ($row=mysql_fetch_array($result)){ $cd_id=$row[';cd_id';]; $cd_title=$row[';cd_title';]; $artist_name=$row[';artist_name';]; $artist_isurname=$row[';artist_surname';]; $price=$row[';price';];   echo "CD Title:"; echo "<INPUT NAME = ';cd_title'; TYPE = ';TEXT'; VALUE = ';",$row[';cd_title';],"';>"; //echo the artist name //echo the artist surname //echo the price } ?> </FORM> </body> </html>

Please help, my website address is as follows, even though is not functioning properly as yet, www.33845476.orgfree.com
Re: EDITING
October 20, 2011 04:53PM
Hi guys

Please help, my edit and delete_yes pages are not working properly. The edit code does bring the information from the list/database onto the update form but when the user clicks on the update button he gets told about the cd_id undefined index on the declaration before the if statement. As a result the database does not get updated. My code is as follows:

Language: PHP
//connect to the database <?php //declare variables $result = mysql_query("UPDATE music SET cd_title=';$cd_title';, artist_name=';$artist_name';, artist_surname=';$artist_surname';,price=';$price'; WHERE cd_id=';$cd_id';") or die(mysql_error()); ?>   //the form starts here with method as post and action as edit.php   <?php $cd_id = $_GET["cd_id"]; if (isset ($_GET["cd_id"])){ //echo the cd_id value to test if you caught it from the list/database. It echoes properly } $result = mysql_query("SELECT*FROM music WHERE cd_id = ';$cd_id';") or die(mysql_error();   $rows=mysql_num_rows($result);     while ($row=mysql_fetch_array($result)){ $cd_id=$row[';cd_id';]; $cd_title=$row[';cd_title';]; $artist_name=$row[';artist_name';]; $artist_isurname=$row[';artist_surname';]; $price=$row[';price';];   echo "CD Title:"; //echo "form elements with VALUE = '; ",$row[';cd_title';]," ';   //echo the other elements the same way //with the hidden element here } ?> //end the form

Is it something to do with the order in which I put my code?

I have also uploaded what I have already done and my site details are as follows: www.33845476.orgfree.com
avatar
Mac
Re: EDITING
October 20, 2011 08:02PM
Undefined index is discussed elsewhere. Read the forum!
Sorry, only registered users may post in this forum.

Click here to login