PHP MySQL - Function -


I wrote a PHP function but it is nothing at a specific point. New to Php and my english, bad, sorry for that

 . & Lt ;? Php function SQLwriteRecent ($ id, $ title, $ link) {$ thief = mysqli_connect ("localhost", "", "", ""); // Check connection if (mysqli_connect_errno ()) {echo "failed to connect to MySQL:". Mysqli_connect_error (); } $ Count = mysqli_query ($ con, "SELECT count fROM recently WHERE sc_stream = '$ id'"); If (! Isset ($ count)) {{mysqli_query ($ con, "INSERT I" (title, link, sc_stream, count) VALUES ('$ title', '$ link', '$ id', $ count) "); Mysqli_close ($ thief); Return 1; } Hold (exception $ E) {return 0; }} And {try {// ------ show here !!!! ------------ // mysqli_query ($ con, "recent SET calculation = $ count WHERE sc_stream = '$ id'" update); Mysqli_close ($ thief); Return 2; } Hold (exception $ E) {return 0; }}}? & Gt;  

The code runs every time up to a specific point (I'll mark it in the code with // ------ here I show it !!!! --- ------- // )

In the SQL table, there is currently no entry, so I should create a new line

in that code What is wrong ?! : (

In view of the logic of what other people have said and what you are doing, It sounds like you have some basic issues.

I have made some variables name changes to make it clear that you are getting a comment that is peppered with the code describing issues. p>

I've ignored SQL injection issues

 . & lt ;? php function SQLwriteRecent ($ id, $ title, $ link) {$ con = mysqli_conne ct ( "localhost", "", "", ""); the // check the connection (mysqli_connect_errno ()) Failed to connect to {echo "MySQL:". mysqli_connect_error ();} $ countQuery = mysqli_query ($ con, "where select number of recent Sc_stream = '$ id'"); $ numberOfRowsReturnedByQuery = mysqli_num_rows ($ count); if ($ numberOfRowsReturnedByQuery & gt; 0) {$ valueOfCountInQuery = $ countQuery [0] [ 'count'];} if ($ numberOfRowsReturnedByQuery == 0) {try {/ / in the situation that I do not think you want to set a value for the recent "" - IE. You did not have the record // But think about it for each other - if you do not have "Recently" records, then how could possibly "$ valueOfCountInQuery" be set? Values ​​('$ title', '$ link', '$ id', $ valueOfCountInQuery)) in mysqli_query ($ thief, "), recently (title, link, sc_stream INSERT count); // There is no point in using "$ valueOfCountInQuery" - maybe you mean "0" (zero) mysqli_close ($ con); Return 1; } Hold (exception $ E) {return 0; }} Else {try {// In this situation it seems that you want to "update" values ​​in IE recently. You had a record and you want to change it. // But think about it for each other - the value of "$ valueOfCountInQuery" is the value derived from "Count" on "Recently". You are setting it at the same price as it already exists! // ------ Show here !!!! ------------ // mysqli_query ($ con, "recent SET calculation = $ valueOfCountInQuery where sc_stream = '$ id'" update); // Redundant mysqli_close ($ con); Return 2; } Hold (exception $ E) {return 0; }}}? & Gt;  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -