jimfog
-
Posts
1,803 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by jimfog
-
-
Ok then.
It seems I should throw away the calendar produced with PHP(meaning the output).
I intend using backbone as a framework.
The thing Is I have no idea how these restful interfaces work.
The question is how easy or difficult it is to learn them provided of course that I know js.
I will build the calendar based on what both of you mentioned.
-
I have 4 input elements and 4 labels,one for each.
In addition each of these label elements have for attributes.
I want to target and hide a specific label, the one having for='"wwwaddress" but I cannot, instead all labels are hidden.
See the fiddle here:
http://jsfiddle.net/fiddlehunt/5rSdf/
What am I doing wrong?
-
Ι am not using PDO, but MySqli.
-
Τhis is the code I have concluded(based on an example from the PHP manual).Tell me what you think. So far it works OK but I have not tested it for all scenarios yet:
$all_query_ok=true; $connection->autocommit(FALSE); $result1 = $connection->query('update users set password ="NULL",hash="NULL",email="NULL",usertype="5" where users.email="'.$sessionmail.'"')?null:$all_query_ok=false; $result2= $connection->query('delete from favorites where (select users.user_ID from users where favorites.userID=users.user_ID)')?null:$all_query_ok=false; if($all_query_ok) {$connection->commit(); return $accoudel='1'; $connection->autocommit(TRUE); } else {$connection->rollback(); $connection->autocommit(TRUE); return false; }
-
I want to create a trigger.
This trigger requires a variable related to a user in order to be carried out.
So, the question is if I can put the trigger in a function in a PHP script and perform it the usual way queries are performed...mysqli->query
-
I am using php to produce the html output of the calendar(days, months etc).
Do you think this is going to pose any problem after I add ajax. I problem I mean in the interactivity of the application.
My intention is to be as interactive as Outook.com with js/ajax of course.
I am just think if I made I mistake to produce the html with PHP.
-
I have build a calendar using PHP.
The question is by using ajax can I make it as interactive as outlook.com.
What I want to say, is if the reason outlook.com manages to be so interactive is maybe because is built entirely on javascript.
Can a PHP calendar really gets a boost if ajax is used?
-
You only use rollback if you actually want to roll the transaction back. You are sending the first query, and then immediately rolling it back (basically canceling it), then running the second query, and then committing that one. So the first query never takes effect because you always roll it back. You need to check for errors with the queries and roll back the entire transaction if any query had an error, that is what rollback is for. Rollback is like undo for queries that have not been committed yet.
Αm I going to check the for errors with the usual way?
meaning...if(!$result){......rollback}.
result is the variable where the query is stored.
-
This is the code I finally concluded:
$connection->autocommit(FALSE); $result1 = $connection->query("insert into users values (NULL,'" .$name. "','" .$lastname . "','".$email."','". $passwd."','". $hash."','4')"); $connection->rollback(); $result2=$connection->query("insert into business_users values('".$connection->insedress."','".$url ."','".$phone. "','".$city. "','".$municipality. "','".$buztype. "')"); $connection->commit(); $connection->autocommit(TRUE);
Τhe reason I am showing it is that I encountered an error where the data of the first query entered the db while of the second's(there was a foreign key violation) did not.
Since I am using rollback this should not be the case.
By seeing the code above is the use of the rollback a correct one?
Furthermore...if a there was an error in the transaction(meaning the queries were not performed) what error checking mechanism should I use to be notified about it?
-
Yes. rollback was the missing "link".
-
Anyway...I tried to experiment with a transaction but it does not work and I cannot understand why...here is the code:
$connection->autocommit(FALSE); $result1 = $connection->query("insert into users values (NULL,'" .$name. "','" .$lastname . "','".$email."','". $passwd."','". $hash."','4')"); $result2=$connection->query("insert into business_users values('".$connection->insert_id."','" .$address."','".$url ."','".$phone. "','".$city. "','".$municipality. "','".$buztype. "')"); $connection->commit(); $connection->autocommit(TRUE);
I messed the 2nd query on purpose. It does not executed....but according to transactions definition neither the first query should.
The 1st query though does execute. So we have the problem now of partial data in the db.
Any ideas what might be wrong?
-
Depends what you want to do. You only need to disable autocommit if you are using transactions, so if you're not using transactions and don't want to call commit after every query then turn autocommit back on.
So, by calling commit does that mean also that autocommit is set to true?
Here is a code example where I want to apply a transaction to these 2 queries only
$connection->autocommit(FALSE);; $result1 = $connection->query("insert into users values (NULL,'" .$name. "','" .$lastname . "','".$email."','". $passwd."','". $hash."','4')"); $result2=$connection->query("insert into business_users values('".$connection->insert_id."','" .$address."','".$url ."','".$phone. "','".$city. "','".$municipality. "','".$buztype. "')"); $connection->commit();
-
I have one last q. After the commit, should I set autocommit(TRUE)?
It is not stated clearly in the manual what to do after the transaction is finished.
-
You can use autocommit and commit to set up transactions.
I finally did the above...set autocommit(FALSE).
-
The mysqli class does not have a method called begin_transaction:
Τhen what is this?
-
I got a glimpse on transactions.
One question I have is if with transactions error checking code such as the one below have any sense any more:
if (!$result1){ throw new Exception('Αδυναμία εκτέλεσης εντολής'); return false;}
Is the above pointless now?
I tried to use the mysqli->begin_transaction method but I got "Fatal error" Call to undefined method".
Why that? I have PHP 5.4.4 on my system
-
You need to look into "Transaction"
Aren't these only for financial stuff?
Are there any serious performance penalties in using them?
-
So far when it comes error handling with queries in a function I follow the following logic:
$result1 = $connection->query("insert into users values (NULL,'" .$name. "','" .$lastname . "','".$email."','". $passwd."','". $hash."','". $usertype."')"); if (!$result1) { throw new Exception('error'); } else{$result2=$connection->query("insert into business_users values ('".$connection->insert_id."','" .$address."','".$url ."','".$phone. "','".$city. "','".$municipality. "','".$buztype. "')"); } if(!$result2) { throw new Exception('error'); return false;}
The problem with the above flow is that the first query might finish successfully while the second might not.
The goal is that if one of them fails the other should not run at all...more specifically I do not want the the first query running if the second fails, something which the above code fails to do.
Even if the 2nd insertion fails the 1st will be performed.
I do not want partial entries in the DB...what control structure I should follow so that both insertions take place or none of them.
-
forget it...I found it.
-
I am trying to run a query and I get the above error.
Usually, and as far as I know. the above error appear when you are trying to get something out of the db.
Here I am just trying to insert data coming from a form with the POST method.
Here is the function that tries to make the insertion-it is for registering a user to the site.
function register_enduser($post,$connection) { $name = $connection->real_escape_string($_POST['name']); $lastname = $connection->real_escape_string($_POST['lastname']); $email = $connection->real_escape_string($_POST['e-mail']); $pass_hashed = password::hash($_POST['password']); $passwd = $connection->real_escape_string( $pass_hashed); $usertype= $_POST['usertype'];// dump($post); $connection->set_charset("utf8"); $result = $connection->query("select * from users where email='" . $email . "'"); if (!$result) { throw new Exception('Error'); return false; } elseif ($result->num_rows > 0) { $errorclass['existentemail'] = 'There is already such an email.'; return false; } else { $result1 = $connection->query("insert into users values (NULL,'".$name."','".$lastname ."','".$email."','".$passwd."','".$pass_hashed. "', '".$usertype. "')")or die($connection); } if (!$result1) { throw new Exception('error.'); return false; } return true; }
The error appear in the $result1 query, the second query performed, not the first one.
-
Yes, id_ref or better still 'user_type_id' as to help apply a description to go with user_type_id such as 'regular' or 'business', in a new table would be the foreign key
user_type_id | user_type_descrip
1 | regular
2 | business
to relate to a primary key use main_user_type_id in main table
||main_name | main_user_type_id ||
||tom | 1 || would be regular
||bill | 2 || would be business
||harry | 1 || would be regular
feel such a ######, should have known ###### would be treated as swear word and blocked out! so used Bill instead of, wait for it D_I_C_K
So, the table below(the one with main names) will reference the table with user_types(from main_user_type_id column-to-user_type_id column)
-
Yes!, you can create another table which will hold the relative id ref and another column describing type of user, but you could, as you only have two, just write php code that would show a description depending on value retrieved. AND even mysql functions such as CASE, which will give result depending on column value, this result is then applied to an alias field name.
When you say "relative id ref" I suppose you do not imply the existence of a foreign key cause, that is not needed here(if I am correct).
You also mention something PHP code. Does that mean that for two values I might not need a table at all-how exactly I am going to distinguish the users, give an example.
The db MUST store info regarding the type of users
-
I know that enum is a column type but since enum is of the integer type there must be a table which will say
that for example, a value of 1 means regular user and value of 2 means business user.
And in the users table there will be a column that will have a value of 1 or 2 depending the type of user we are dealing with.
Do you agree?
-
If there are only ever 2 values then I use a 1 digit tinyint (i.e., a bit), or else I use an enum.
I assume it will be a separate table...the one with the enum values....and it will have a foreign key referencing the user(regular users business users) table.
Concluding, the only thing that worries is the fact that much code now must be revised in order to be adjusted to the new db design model proposed.
hiding a specific label
in JavaScript
Posted
Everything is done js.EITHER WAY.
I do not understand your first question.
I am just trying to hide the label, forget the input element for now