Welcome! Log In Create A New Profile

Advanced

Insert script inserting three players into database at the same, but two of them are blank

Posted by Rufus Satekge 
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
Insert script inserting three players into database at the same, but two of them are blank
April 23, 2013 02:28PM
Hi

I have a problem with my insert script. Every time I insert a player into the database, three players are inserted, but two of them are blank...
Language: PHP
$query = "INSERT INTO playerinfo(name,surname,contactnumber,email,position,username,password) VALUES ('".$_POST['name']."', '".$_POST['surname']."', '".$_POST['contactnumber']."', '".$_POST['email']."', '".$_POST['position']."', '".$_POST['username']."', '".$_POST['password']."')"; $result = mysql_query($query) or die ("Query failed: " . mysql_error());


Please Help
avatar
Mac
Re: Insert script inserting three players into database at the same, but two of them are blank
April 23, 2013 03:14PM
This script inserts one player at a time, so I do not see your problem. Bad idea to insert a player if there is no auto_increment field.
Re: Insert script inserting three players into database at the same, but two of them are blank
April 24, 2013 06:47AM
My guess would be your insert script is in a loop of some kind... try add an echo "Test";
before your script to see if the echo is displaying 3 times...

this will prove its not the script but another loop of some kind?
would need to try trace it?

as for your comment Mac...
don't understand the bad idea if there is no auto increment?
well understand it, but why did you say it here

my script looks identical (nearly) to this and mine has auto increment.
does the field no "auto increment"
and therefore no need to place it in the script.
The things is, all this problems started after I inserted the following lines of code to suppress the undefined notices
Language: PHP
<?php ini_set( 'error_reporting', E_ALL ^ E_NOTICE );?> <?php ini_set( 'display_errors', '0' );?>
avatar
Mac
Re: Insert script inserting three players into database at the same, but two of them are blank
April 25, 2013 02:28PM
These notices cannot influence the query.There is something else wrong.

@42609852. Well, you want to edit a player at some stage. His query does not allow for an autoincrement id/primary key "type" field to be inserted as the player's unique ID. So how will he target the correct row to update? My wife and I play the same sport, her name is also Bob, she has my surname, we use the same email, she is also a winger for the lady;s soccer club, and because we are forgetful, we use one username and password for all our accounts. So which row will be updated? Mine or hers? She divorces me, but now I am Buthelezi while I am still van der Merwe

player_id , because it is autoincrement, will always be unique (like a passport or ID number - not that the last is foolproof!)
Re: Insert script inserting three players into database at the same, but two of them are blank
April 25, 2013 06:36PM
I am scared to ask...
I feel I am about to embaress myself... but hey, how else do we learn...

this is my query for insert...


Language: PHP
$SQL = "INSERT INTO Players (name, surname, contact_number, email, position,username, password, Picture) VALUES (\"$this->Name\", \"$this->Surname\", \"$this->ContactNo\", \"$this->Email\", \"$this->Position\", \"$this->Username\", \"$this->Password\", \"$this->Picture\")";



also no ID field as during insert it is uniquely created...
but when I update... I take the ID from the player and use it in the where clause

Language: PHP
$SQL = "UPDATE players SET name=\"$this->Name\", surname=\"$this->Surname\", contact_number= \"$this->ContactNo\", email=\"$this->Email\", position=\"$this->Position\", username= \"$this->Username\" WHERE player_id = \"$this->ID\"";

is there something wrong here or that I am missing...
also you comment about you and your wife having same personal detail and playing for 2 diffrent teams, leads me to believe I might have made a mistake in my design or understanding of the site... (FYI hope thats not really the case smile )

am I creating a site for a singular sports team to manage my teams games and players....
or a site for the sport managers to manage multiple teams and multple plauyers from diffrent teams... (If so, I am in big trouble)
avatar
Mac
Re: Insert script inserting three players into database at the same, but two of them are blank
April 26, 2013 08:27AM
Why are you using an OOP approach?

Do not escape the "

Single team
Re: Insert script inserting three players into database at the same, but two of them are blank
April 26, 2013 01:51PM
Mac...
I am confused.... and very worried

I completed 50% of proj in less then a week, and when I saw someone was writing their own framework I though it would be a good opportunity for me to learn...
by doing something more complex....
our books had stuff about classes (and I did classes in python)
and I read up a little on mvc on web....

and also in another topic you said:
"So you can use classes if you want. Generally, I get concerned when all code on a single page is a complete class where you just specified the connection details. So make use of classes, but together with your own code."

should I redo in a NON OOP way?
avatar
Mac
Re: Insert script inserting three players into database at the same, but two of them are blank
April 26, 2013 03:31PM
If you can manage OOP, then do so. If you are in a position to create your own classes (and not just functions), good! You can use pre-written classes, but then I would not like to see a use of a class that does all the work for you. Some existing frameworks, for example, can create all or 95% of the code for you. I want to see evidence that you have written code yourself, according to your logic and assumed skill level. Thus, I had students that hardly passed any subject (I check academic records every now and then), but produces work that simply does not "fit" and that would make even a seasoned programmer ashamed.

A comparative example is in a HTML web design course. Some people, despite warnings, submit a website created with Word (WYSIWIG). My grandmother of 102 can do that.I want to see evidence of your coding skills. If that includes classes you have created yourself -good! If you make use of a pre-written class here and there then good. If you use an existing framework to create pages for you, then I get worried becasue I see no evidence of your programming skills - just of your skills in using an existing framework to do the dirty work for you. If there is a wizard involved in creating the code, then I will award the marks to the developers.
Re: Insert script inserting three players into database at the same, but two of them are blank
April 26, 2013 04:40PM
Firstly Mac... THANK YOU!!!!

I nearly died of heart attack...
was thinking of restarting, and forgetting about other subj... (FYI, if you do look at my other subj... please ignore my Accounting marksconfused smiley)

I did not and never have used a WYSIWIG (not sure I would know how...)
I have not used any framework (accept for JQUERY.. and was only to create a calendar)

I created framework, classes and everything using only notepadd ++ (and my PHP book)
and I am pretty sure you will see that, (as I do not think I am using mvc/classes 100%.... this also worries me
as at times I did not know where to place the method, and just did the querry on controller)

I am going to add a diagram explainng my thought process for the framework,
as I might have made marking a little harder by splitting the work (sorry)
Sorry, only registered users may post in this forum.

Click here to login