Jump to content

aHMAD_SQaLli

Members
  • Posts

    36
  • Joined

  • Last visited

Everything posted by aHMAD_SQaLli

  1. Hello sorry for the English if it's horrible so, I was wondering what is the best (fastest, secure) way to load a php script, is it to load the script in a function in the top and run it, or to execute each if ,else in the middle of the code. example 1 <?php function load_script(){ if (isset($_POST['query'])){ $php = $_POST['query']; # do things .... } else { # do things .... } # rest of the script ... } ?> <html> <head> <title></title> </head> <body> <?php load_script(); ?> </body> </html> example 2 <?php function load_script(){ if (isset($_POST['query'])){ $php = $_POST['query']; # do things .... } else { # do things .... } # rest of the script ... } ?> <html> <head> <title></title> </head> <body> <?php load_script(); ?> </body> </html> Thanks, Have a good day !
  2. Hello every one $db_mysqli_connect = mysqli_connect("localhost", "root", "root", "PSE_database"); if (mysqli_connect_errno($db_mysqli_connect)) { echo 'Some error occurred during connection to the database';} $LIKE = "rammstein"; if ($stmt = mysqli_prepare($db_mysqli_connect, "SELECT document_title FROM pse_docs WHERE document_title LIKE ?")) { mysqli_stmt_bind_param($stmt, "s", $LIKE); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); if(mysqli_num_rows($result) !== 0) { while ($row = mysqli_fetch_assoc($result)){ echo $row['document_title']. "<br>"; } } else { echo "Not Found"; } } else { trigger_error('Unable query users table: ' . mysqli_error($db_mysqli_connect)); } mysqli_free_result($result); mysqli_stmt_close($stmt); mysqli_close($db_mysqli_connect); this code does not work, it returns nothing, btw, document title is Rammstein ! Thanks.
  3. ok, I tried using another query SELECT users.username, topics.topic_body FROM `users` LEFT JOIN topics ON topics.topic_author = users.id WHERE topics.id=? order by topic_edit_time ASC I have 5 row in it but it display just 4 and ignoring the first however the first code works great EDIT ::: here is the code if ($stmt = mysqli_prepare($link, "SELECT users.username, topics.topic_body FROM `users` LEFT JOIN topics ON topics.topic_author = users.id WHERE topics.id=? order by topic_edit_time ASC")) { mysqli_stmt_bind_param($stmt, "s", $tid); mysqli_stmt_execute($stmt); /* the columns returned in the query will be bound to these variables when calling mysqli_stmt_fetch */ mysqli_stmt_bind_result($stmt, $username, $replay); /* mysqli_stmt_fetch returns FALSE if no rows where returned */ if(mysqli_stmt_fetch($stmt)) { while (mysqli_stmt_fetch($stmt)) { echo 'author: <b>[' . $username . ']</b> replay: <b>[' . $replay. ']</b> '; } } else { echo "Not Found"; } } else { /* prepared query failed */ trigger_error('Unable query users table: ' . mysqli_error($link)); }
  4. Hello Im using XAMPP v 1.8.2 /// PHP: 5.4.4 /// phpmyadmin v 3.5.2 I m having trouble with this script it gives this error message Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, object given in C:\xampp\htdocs\mysqli.php on line 43 line 43 is if(mysqli_num_rows($stmt) !== 0){ Here is the script $tid = 1; if ($stmt = mysqli_prepare($link, "SELECT id, username FROM users WHERE id=? ")) { mysqli_stmt_bind_param($stmt, "s", $tid); mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $id, $username); mysqli_stmt_fetch($stmt); if(mysqli_num_rows($stmt) !== 0){ while (mysqli_stmt_fetch($stmt)) { echo "id: <b>[" . $id . "]</b> username: <b>[" . $username. "]</b><br> " ; } } else { echo "Not Found"; } mysqli_stmt_close($stmt);} /* close connection */ mysqli_close($link); THANKS
  5. Hello every one so, I've been using mysql for almost 2years and I've heard that using MySQLi is more secure and I m still new in the prepared statement thing that's why I was wandering how to do this prepared statement with arrays ?? in an example I have this code, how can I execute it with prepared statement ? $sql = mysqli_query($con, "SELECT users.regdate, topics.topic_body FROM `users` LEFT JOIN topics ON topics.topic_author = users.id WHERE topics.id=1 order by topic_edit_time ASC"); if( mysqli_num_rows($sql)>0 ) { while($row = mysqli_fetch_array($sql)) { echo htmlentities($row['regdate']) . "<br>" ; echo htmlentities($row['topic_body']); } } else { echo 'not found'; } Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.