PHP - Is This Mix Of Php And Mysql Translatable Into Pure Mysql ?
I have following piece of code below, and I would like to be able to express it pure SQL, something that could go into a .sql file :
$request_string='SELECT topic_forum_id FROM topic_table WHERE topic_id= 2014'; $query=database->prepare($request_string); $query->execute(); $data=$query->fetch(); $query->closeCursor(); $forum=$data['topic_forum_id']; $request_string='INSERT INTO post_table (post_topic,post_forum) VALUES (2014,:forum)'; $query=database->prepare($request_string); $query->bindValue(':forum',$forum,PDO::PARAM_INT); $query->execute(); $data=$query->fetch(); $query->closeCursor();Is it possible ? Similar Tutorialscreate table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that Hello everyone, Sorry if this has been answered but if it has I can't find it anywhere. So, from the begining then. Lets say I had a member table and in it I wanted to store what their top 3 interests are. Their$ row has all the usual things to identify them userID and password etc.. and I had a further 3 columns which were labled top3_1 top3_2 & top3_3 to put each of their interests in from a post form. If instead I wanted to store this data as a PHP Array instead (using 1 column instead of 3) is there a way to store it as readable data when you open the PHPmyadmin? At the moment all it says is array and when I call it back to the browser (say on a page where they could review and update their interests) it displays 'a' as top3_01 'r' as top3_02 and 'r' as top3_03 (in each putting what would be 'array' as it appears in the table if there were 5 results. Does anyone know what I mean? For example - If we had a form which collected the top 3 interests to put in a table called users, Code: [Select] <form action="back_to_same_page_for_processing.php" method="post" enctype="multipart/form-data"> <input name="top3_01" type="text" value="enter interest number 1 here" /> <input name="top3_02" type="text" value="enter interest number 2 here" /> <input name="top3_03" type="text" value="enter interest number 3 here" /> <input type="submit" name="update_button" value=" Save and Update! " /> </form> // If my quick code example for this form is not correct dont worry its not the point im getting at :) And they put 'bowling' in top3_01, 'running' in top3_02 and 'diving' in top3_03 and we catch that on the same page with some PHP at the top --> Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' With me so far? If I had a table which had 3 columns (1 for each interest) I could put something like - Code: [Select] include('connect_msql.php'); mysql_query("Select * FROM users WHERE id='$id' AND blah blah blah"); mysql_query("UPDATE users SET top3_01='$top3_01', top3_02='$top3_02', top3_03='$top3_03' WHERE id='$id'"); And hopefully if ive got it right, it will put them each in their own little column. Easy enough huh? But heres the thing, I want to put all these into an array to be stored in the 1 column (say called 'top3') and whats more have them clearly readable in PHPmyadmin and editable from there yet still be able to be called back an rendered on page when requested. Continuing the example then, assuming ive changed the table for the 'top3' column instead of individual colums, I could put something like this - Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' $top3_array = array($top3_01,$top3_02,$top3_03); include('connect_msql.php'); mysql_query("UPDATE members SET top3='$top3_array' WHERE id='$id' AND blah blah blah"); But it will appear in the column as 'Array' and when its called for using a query it will render the literal string. a r r in each field instead. Now I know you can use the 'serialize()' & 'unserialize()' funtcions but it makes the entry in the database practically unreadable. Is there a way to make it readable and editable without having to create a content management system? If so please let me know and I'll be your friend forever, lol, ok maybe not but I'd really appreciate the help anyways. The other thing is, If you can do this or something like it, how am I to add entries to that array to go back into the data base? I hope ive explained myself enough here, but if not say so and I'll have another go. Thanks very much people, L-PLate (P.s if I sort this out on my own ill post it all here) So i have this php as shown below. It should make a list of comments with comment replies below their comment respectively. The problem is that it only goes through and shows 1 comment and all the comment replies for that one comment. It should be showing all comments i have in the db for that article. If i remove the second while then it shows all the comments correctly but no comment replies then... How do i get this script to loop through the db for every comment but also loop through every comment reply for that $row[id]? If anyone has a better / more efficient way of what I am trying to do, please explain or show example (i am open to anything)... Code: [Select] // what article are we showing? $article_to_show_id = $_GET['article_id']; $active_is_set_text = "1"; // Active Column text that makes it okay to show // Finding the article $search_for_article = mysql_query("SELECT * FROM articles WHERE id = '$article_to_show_id' AND active = '$active_is_set_text'"); while($row = mysql_fetch_array($search_for_article)) { // format the last updated date right $update_date_edit = $row[update_date]; $update_date_edit = date('F j, Y \a\t h:ia', $update_date_edit); $row[update_date] = $update_date_edit; // format the submit updat date right $submit_date_edit = $row[submit_date]; $submit_date_edit = date('F j, Y \a\t h:ia', $submit_date_edit); $row[submit_date] = $submit_date_edit; echo ' <div> ', $row[title] ,' </div> <div> by: ', $row[author] ,' on ', $row[submit_date] ,' </div> <div> ', $row[content] ,' </div> <div> Last Updated: ', $row[update_date] ,' </div> <form action="article_reply.php" method="post"> <input type="hidden" name="article_id" value="', $row[id] ,'" /> <button name="article_reply" type="submit" value="submit">Reply</button> </form> '; } $comment_count = 0; $comment_reply_count = 0; // Finding all of the comments $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '0'"); while($row_comment = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_comment[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_comment[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT:<br> <div> By: ', $row_comment[username] ,' on ', $row_comment[comment_date] ,' </div> <div> ', $row_comment[comment] ,' </div> '; $comment_count++; // Finding all of the comment replies if any $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '$row_comment[id]'"); while($row_two = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_two[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_two[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT REPLY:<br> <div> By: ', $row_two[username] ,' on ', $row_two[comment_date] ,' </div> <div> ', $row_two[comment] ,' </div> '; $comment_reply_count++; } } Need some help I have 2 tables in a database and I need to search the first table and use the results from that search, to search another table, can this be done? and if it can how would you recommend that I go about it? Thanks For Your Help Guys! I have found a point in my site where the user may wish to go back a page. Using the back button in the browser works perfectly fine. However, for aesthetical reasons and for "obvious function" reasons i need to create a button on the page which goes back a step in the browsers history. I know I can do this with Javascript, but I would rather get it done with php first. Therefore is it possible to create a back button in PHP. The back button in question will go back one step in the browsers history to the same .php it is currently on but in a previous state. I found this from google, http://www.webmasterworld.com/forum88/870.htm, but then found there was some js in the answers. I cannot find any other posts similar to this in php freaks I'm trying to convert a grayscale image to pure black and white in php using the GD library. The purpose would be to detect the cervical cells within the image. I'll leave the php code and a matlab one (i wrote this code in matlab and i'm trying to obtain the same result in php). Basically, im having troubles accessing each individual pixel's color and modifying it. MATLAB: clear all, clc, close all; I = imread('celule.jpg'); imshow(I) title('original'); a=rgb2gray(I); figure; imshow(a) title('grayscale'); s=size(a); for i=1:s(1) for j=1:s(2) if a(i,j)>190 a(i,j)=0; else a(i,j)=255; end end end figure; imshow(a) title('pure black and white'); PHP: <?php $im = imagecreatefromjpeg("celule.jpg"); function imagetograyscale($im) { if (imageistruecolor($im)) { imagetruecolortopalette($im, false, 256); } for ($c = 0; $c < imagecolorstotal($im); $c++) { $col = imagecolorsforindex($im, $c); $gray = round(0.299 * $col['red'] + 0.587 * $col['green'] + 0.114 * $col['blue']); imagecolorset($im, $c, $gray, $gray, $gray); } } imagetograyscale($im); //imagefilter($im, IMG_FILTER_CONTRAST, -255); //i'm not looking for this effect header('Content-type: image/jpeg'); imagejpeg($im); $C = imagesx($im); //width $L = imagesy($im); //height echo "Dimensiuni imagine: latime $C, inaltime $L <br>"; //scanning through the image for($x = 0; $x < $L; $x++) { //each line for($y = 0; $y < $C; $y++) { //each collumn // pixel color at (x, y) $color = imagecolorat($im, $y, $x); $color = imagecolorsforindex($im, $color); //getting rgb values $RED[$x][$y] = $color["red"]; //each rgb component $GREEN[$x][$y] = $color["green"]; $BLUE[$x][$y] = $color["blue"]; } } ?> image "celule.jpg": https://i.ibb.co/6Ffj6sc/celule.jpg Hey Guys I need some help, I have these two tables: (vouchers) (login) I also, have this page. (redeem.php) What i need, is when a user types in a voucher code, i adds 100 credits to there user account. My Logged in Session is currently: Quote $username = $_SESSION['loggedinsuccesfully']; Also, when the voucher has been used, the status of the voucher needs to change to 1 (means it cant be used again) If anyone can offer me this code, i will appreciate it. Thanks again fCooper94 Hey guys I need some help for making some things work. This is my index.php and as you can see I have a table of my sql table and a drop list. Now when I press Add to chart on the table on my website, it goes to the cart. But when I select a item from the drop list and click on Add to chart, there only happens an increment of the quantity but the item does not go to the cart. http://fhcs.be/cart-demo2/index.php this is my website where you can check the problem out. Thanks Guys!!!! Code: [Select] <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo · Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="booklist"> <h1>Books In Our Store</h1> <?php $sql = 'SELECT * FROM products ORDER BY id'; $result = $db->query($sql); $output[] = '<ul>'; while ($row = $result->fetch()) { $output[] = '<li>"'.$row['name'].': €'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output[] = '</ul>'; echo join('',$output); ?> <? $Link = mysql_connect("fhcs.be.mysql","fhcs_be","xxxx"); $Query = "SELECT * FROM products"; $DBName = "fhcs_be"; $results = mysql_db_query($DBName, $Query, $Link); ?> Select a name <select name = "drop1" size="1"> <Option Value=" ">Select One:</option> <? //Begins PHP for($u=0;$u<mysql_num_rows($results); $u++) { $ID=mysql_result($results,$u,'name'); ?> <option value="<? echo($ID); ?>"><? echo($ID); ?></option><? //Begins PHP //Begins PHP } ?> </select> <? //Begins PHP if (mysql_db_query ($DBName, $Query, $Link)) { } else { print ("FAILURE<BR>\n"); } mysql_close ($Link); ?> </div> </body> </html> Hi im having problems with this can any one point me the right way please Code: [Select] if(isset($_GET['pageID'])){ $id = $_GET['pageID']; } ?> <?php if(isset($_POST['submit'])){ $title = $_POST['title']; $keywords = $_POST['keywords']; $description = $_POST['description']; $menu = $_POST['menu']; $content = $_POST['content']; $query = mysql_query("UPDATE 'page' SET title='$title', keywords='$keywords', description='$description', menu='$menu', content='$content' WHERE 'pageID'= $id"); } ?> Hi im trying to make it get the server from the toplist data by the server owner, after that i want it to check if theres more then 1 server if there is i want it to add all the votes together and if there isnt more then 1 i want it to show the votes <?php $votes = mysql_query("SELECT * FROM toplist WHERE serverowner='{$_SESSION['user']}'") or die(mysql_error()); while($vote = mysql_fetch_array($votes)) { if(mysql_num_rows($vote) > 1 { //gets the server votes and adds them } else { $servervotes = $vote['votes']; } echo $servervotes; ?> } Hi im trying to count the number of rows in my notifications My code So far list($total_server) = mysql_fetch_row(mysql_query("SELECT COUNT(id) FROM users WHERE notifications")); hello i am making a online cook for people to register and make and online cookbook on there account i want them to be able to add recipes and be able to see them on there file, i know how it would connect to the database and how to send the information but what tables would i use and what fields? this is my basic site now www.lachlanmcgrath.net, if you can help please reply here or even e-mail me at lmcgr44@me.com thank-you for your help Hi all, I have a question concerning building the Admin area. Let's say there are 3 pages. Page 1: "staff.php" (login/register page) Page 2: "staffproc.php" (process forms) Page 3: "adminManage.php" (Manage the content, edit, delete, add, etc.) I need to link the login page to the admin page so no one can access "adminManage.php" without providing the Login details. How??? Will I just include the login page into the admin? Any response will be appreciated!! Umm.. Yeah, this MySQL line needs some reviewing list($total_banned_servers) = mysql_fetch_row(mysql_query("SELECT COUNT(id) FROM `toplist` WHERE banned='1' && serverowner=". $_SESSION['user'] ."")); Hi all I am am trying to use the following piece of code to import a CSV file into a mySQL database: Code: [Select] $filename = $_FILES['sel_file']['tmp_name']; $handle = fopen($filename, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { mysql_query("INSERT INTO user SET id = '".$userid."', name = '".$data[0]."', email = '".$data[1]."', phone = '".$data[2]."'") or die(mysql_error()); } fclose($handle); It works great except it only imports one line in the CSV file. How do I get it to keep adding the lines into the DB? My CSV looks like this: Pete Naylor,test@mail.com,0800101101 Bob Jones,bob@mail.com,08700123123 Many thanks for for help Pete Just want to ask how to create a login system using these wml and php? i have a background on connecting html php and the database.. but in these wml i am confused.. can someone help me? What i'ved got here is Wap Proof for wap emulator to test my codes.. You can download it here http://www.wap-proof.com/ i have tried this code but i gets me to error.. // login.php <?php # Header Info header('Content-Type: text/vnd.wap.wml', true); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); # Version Type print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; # Import config file include "/home/jamieb/private/conf.php"; # Connect to database mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); ?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <!-- THIS IS THE LOGIN CARD --> <card id="login" title="Login"> <p> <do type="accept" label="Login"> <go href="process.php" method="post"> <postfield name="userName" value="$userName" /> <postfield name="password" value="$password" /> </go> </do> </p> <p> User Name: <input title="userName" name="userName" /> <br /> Password : <input title="password" name="password" type="password" /> <br /> </p> </card> </wml> // process.php <?php # Header Info header('Content-Type: text/vnd.wap.wml', true); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); # Version Type print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; # Import config file include "/home/jamieb/private/conf.php"; # Connect to database mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); # Verify the user $sql = mysql_query("SELECT userName,nickName FROM table WHERE userName = '".strtolower($_POST['userName'])."' AND password = '".md5($_POST['password'])."'"); $row = mysql_num_rows($sql); $login = mysql_fetch_array($sql); $user = md5($login['userName']); $nick = $login['nickName']; if ($row == 0): ?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card id="failed" title="Login Failed"> <p> Sorry, username or password incorrect! </p> <p> <anchor>Home <go href="index.php#menu" /> </anchor> <do type="prev" label="Back"><prev/></do></p> </card> </wml> <?php exit; else: ?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card id="success" title="Login Success"> <p> <do type="accept" label="Admin"> <go href="admin.php" method="post"> <postfield name="session" value="<?php echo "$user"; ?>" /> </go> </do> </p> <p>Welcome <?php echo "$nick"; ?>, please enter the admin area.</p> </card> </wml> <?php endif; ?> My problem here is it doesn't open anything on the wap proof.. or if i ever open it i can't see the submit button.. can someone give some login scripts using php wml? thanks I have a Database with two tables "users" and "Logins" and I'm trying to figure out how to check the cookie ID and use a mysql query to check if ID from the cookie matches UID in the "Logins" table and get all the data with a matching ID and UID. How exactly would I go about doing this? -edit- Fixed spelling -edit- Need help with php/sql. When I add a drink to the cart, only the quantity increases, but the item does not go to the cart. Check it out on my website http://fhcs.be/cart-demo2/ This is a part of my index.php <h1>Drinks</h1> <? $Link = mysql_connect("xxxx","xxxx","xxxx"); $Query = "SELECT * FROM products"; $DBName = "xxxx"; $results = mysql_db_query($DBName, $Query, $Link); ?> <select name = "drop1" size="1" id="drop1"> <Option Value=" ">Select Drink:</option> <? //Begins PHP for($u=0;$u<mysql_num_rows($results); $u++) { $id=mysql_result($results,$u,'name'); ?> <option value="<? echo($id); ?>"><? echo($id); ?></option><? //Begins PHP //Begins PHP } ?> </select> <? //Begins PHP if (mysql_db_query ($DBName, $Query, $Link)) { } else { print ("FAILURE<BR>\n"); } mysql_close ($Link); ?> <a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a> //button to add to chart And this is a part of my cart.php <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; |