deleting the displayed key from database in php -
So this key is the cheap script to me, now I want to get deleted keys from the database. How do I give it to work within the code written?
So $ is the key key that will be sent to you and displayed in the browser, but I want this key to be removed from the database after it is sent and displayed, it can not be shown second time to another user. .
& lt ;? Mail Php // fill email "& lt; form method = 'post' action =". $ _SERVER ['PHP_SELF'] "Email: & lt; input name = 'email' & gt; & lt; / input & gt; & lt; br & gt; & lt; input type = 'submit' Value = 'get your key' name = 'submit'>
"; If (empty ($ _ POST ["email"])) {resonant "Please enter an email address"; } Else {// Get key from database $ key = dispres (); $ Mail = $ = $ _POST for input input input ["email"]; $ Theme = 'your exam key'; $ Message = 'your key is:' $ Key; $ Header = 'you go there!'; Mail ($ $ $ $ theme, $ message, $ headers); Echo "Your code has been sent to your email:" $ _POST ["Email"] "\ R"; Copy $ key; } Function dars () {// database connect $ db_host = 'localhost'; $ Db_user = 'root'; $ Db_pwd = 'pwd'; $ Database = 'c3keys'; $ Table = 'test'; If (! Mysql_connect ($ db_host, $ db_user, $ db_pwd)) dies ("Can not connect to database"); If (! Mysql_select_db ($ database)) die ("database can not be selected"); // result from resistor = mysql_query ("select * FROM {$ table}" RAND () LIMIT 1); $ Line = mysql_fetch_row ($ result); $ Result = implode ('|', $ line); Return result; // Delete the key from the database // it started as mysqli_query ("remove test from test where test = '$ key'"); // 1) Remember IP address for use? & Gt; 1- You are using both mysql and mysqli stick together with one.
1- ..
2- Your removal query is after the return, so it will never run.
What is the 3- $ key? I do not know where you set it.
Stop using mysql_ * These functions have been excluded Use MySkyi or PDO with prepared statements.
Explanation point 1:
In your code at the beginning of your dispersion function, you have mysql_connect
, Mysql_select_db
and Mysql_query
If you used mysqli_query
in the last action for the query that you deleted, then you 'like you associated with mysql adapter Was there.
Explanation point 2:
You have the result of return;
After that you have mysqli_query ("..."); PHP will not execute the code because when it sees
return
for PHP and any other programming language, it means that the function is done, nothing else to do this. , You can not find any line that does not perform after return
explanation point 3:
. Function like $ of
is not basically empty $ of
, I think you are using $ result
in that code Ry. And if you use $ result
, your delete will still not work, because $ result
is a string where you have joined it in all your fields and < Code>. The pipe trail between each other and hence the column test
will never equal to your $ result you should replace with the actual value of $ column column that you want to delete:
$ row = mysql_fetch_row ($ result); $ Test_i_want_to_delete = $ line [0]; // where 0 is the number of `test` column in your DB table, starting with counting from 0 = the resultant = intestine (';', $ line); Mysql_query ("Remove test from test =" $ test_i_want_to_delete ""); Explanation point 4: If you are just starting to learn PHP, then it would be better for you that any unforeseen functions will be removed completely, so the future releases therefore mysql _ * < Instead of using the / code> function, take a look at or and use a specially prepared statement.
I hope my answer will help to clean some stuff.
Comments
Post a Comment