Welcome! Log In Create A New Profile

Advanced

UPDATE Statement

Posted by ginosimon 
Announcements Last Post
Announcement : Programming Students at UNISA School of Computing 06/19/2019 02:01PM
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
avatar UPDATE Statement
May 02, 2013 09:55AM
Hello,

May I please have some advice regarding the edit.php page which needs to give the coach the ability to edit existing player information. I am able to update and display a form with player information in edit.php. When I click submit button,the information is 'passed' to my update_data.php script which is then supposed to run my UPDATE statement. This does not seem to be working no matter all the tweaking, Googling and research I have done. The player data for the edit.php form is passed in the URL from my list_players.php page. I am able to grab the player_id with the GET method in my edit.php page, however I am not able to pass that player_id to my update_data.php script and therefore run the UPDATE statement successfully. Sorry I am at work and do not have access to my source code at the moment. I was hoping that I could get some feedback or guidance to solve this issue and complete my portfolio. Thank you.

"It is not the will to win, but the will to prepare to win that makes the difference."
avatar
Mac
Re: UPDATE Statement
May 02, 2013 10:13AM
Well, your update statement can have errors in it? Have you looked at what information is sent with the URL?
avatar Re: UPDATE Statement
May 02, 2013 10:30AM
Hello Mac,

The information passed in the URL from list_players.php is done so with the Edit hyperlink:
Language: PHP
<td><a href=edit.php?player_id=$player_id>Edit</a></td>

I then use the following code in my edit.php page to display the infomation in my form:
Language: PHP
$player_id = $_GET['player_id'] $query = "SELECT * FROM player_info WHERE player_id = '$player_id'";

Once the information is displayed in the form I use the Submit button to send the infomation edited in the fields to update_data.php. This is more or less what my code looks like in the update statement:
Language: PHP
//database connection details... $player_id = $_GET['player_id']; $query = UPDATE player_info SET name = $_POST['name'], surname = $_POST['surname']... WHERE player_id = '$player_id'";

Any feedback will be much appreciated. Thank you.

"It is not the will to win, but the will to prepare to win that makes the difference."
Re: UPDATE Statement
May 02, 2013 11:32AM
I am not 100% sure what is wrong here, but I would start by copying you SQL and running the query straight in mySQL,
(I found the cause of allot of errors on my side by doing that)

if it runs... (at least you know its not your query)
also echo you $_POST[] to make sure correct data is being received...

this might be a stupid suggestion but try adding ' ' around the $_POST[]
I did mine a little different by using a variable and setting it to the POST value and using the variable in thee SQL...
avatar Re: UPDATE Statement
May 02, 2013 12:03PM
Thank you. I will try that when I get home.

"It is not the will to win, but the will to prepare to win that makes the difference."
avatar Re: UPDATE Statement
May 02, 2013 01:13PM
You can also try to set variables at the beginning of the <?php (this might not be needed depending on your code structure, but might as well do it anyway for testing purposes)

for instance:

$name_value = "";
$surname_value ="";

and so forth

Then before you do the update, transfer the POST values to your variables:

$name_value = $_POST['name']
$surname_value = $_POST['surname']

You can also then echo these variables to see if they have values. Afterwards you can use the variables in your UPDATE player_info SET... statement instead of the POST method.

It is a long way of doing it, but it might just help you troubleshoot and find the fault somewhere. Also, it's easier to type when using the variables so you are less likely to have a wrong ' or space somewhere.
avatar Re: UPDATE Statement
May 02, 2013 02:53PM
Great suggestion. Thank you. Will let you know if I have any success tonight.

"It is not the will to win, but the will to prepare to win that makes the difference."
avatar Re: UPDATE Statement
May 02, 2013 09:36PM
Thank you all for the feedback and input. A few commas and apostrophes in the right places made the difference. Thank you again.

"It is not the will to win, but the will to prepare to win that makes the difference."
Re: UPDATE Statement
May 14, 2013 12:28AM
Hi All,

Do you know if there is a setting in mysql that prevents an UPDATE statement from moving past the first column.

Language: SQL
UPDATE student SET sname='',init='',fname='',title='',msname='',dob='',gen='',lang='',idno='',telh='',telw='',cel='',fax='',email='',address='',contact_flag='' WHERE sno=''

When this statement is tested in mysql, the first column 'sname' is updated but an error for the 2nd column 'init' is encountered. If I remove the 'sname' and start with 'init' then the error refers to the next column 'fname'.

so frustratingsad smiley
Re: UPDATE Statement
May 14, 2013 12:50AM
Gremlins at work.

Now working.
avatar Re: UPDATE Statement
May 14, 2013 08:39AM
Hi 77928490

I had the same problem with two of my three tables, way back when I started the portfolio. It would update or insert into the first column but none of the rest. After quite an amount of struggling I simply deleted and re-did the tables in the database, and then it just worked. (I didn't change any of my code) I honestly believe this is a bug in mysql somewhere.
Re: UPDATE Statement
May 14, 2013 08:51AM
Thank you.

I tend to agree with you. Looks like a bug. I never did anything except keep on testing the SQL statement. Then 'vuala', it worked.

Good luck. I am almost done.
avatar Re: UPDATE Statement
May 14, 2013 10:43AM
Hello, just my two cents worth but I believe that 'init' is a keyword of sorts in MySQL and hence the issue. I see init a lot in the configuration files, etc. I named one of my tables 'select' and had major problems, could not understand why my SQL statements were not executing, then I changed the name of the table to 'selection_table' and everything worked fine. I think the major thing is to avoid using keywords in places where their use may cause a conflict in MySQL.

"It is not the will to win, but the will to prepare to win that makes the difference."
Re: UPDATE Statement
May 14, 2013 11:40AM
hahaha, that is hilarious,
yep you cant name a table SELECT

init is short for initialization....

when you work with classes (you will in python)
then you name the class and if you add a method or function with the name
__init__
it will run automatically when the object is instantiated
so...
so when you create an object it will always run that __init__ method
avatar Re: UPDATE Statement
May 14, 2013 12:10PM
Lol. Just one of the many incredibly stupid things I did before realising that the problem had nothing to do with my code but rather my naming conventions. Lol. I am familiar with init from Python.

"It is not the will to win, but the will to prepare to win that makes the difference."
avatar Re: UPDATE Statement
May 14, 2013 03:24PM
Heh, didn't even notice the init thing. But in my case I seriously deleted and redid the tables with the same names and columns without altering the code and it worked :-s
Sorry, only registered users may post in this forum.

Click here to login