PHP - Php Mysql Help Needed!
Im trying to get a code to find an id by name and then find a value by id
this kinda works can you help? <?php $con = mysql_connect("localhost","root","password"; if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ryanteck", $con); $result = mysql_query("SELECT * FROM forum_members WHERE member_name='ryan'"); while($row = mysql_fetch_array($result)) { echo $row['member_name'] . "s Id is " . $row['id_member']; echo "<br />"; $result2 = mysql_query("SELECT * FROM forum_themes WHERE id_member= $id && variable= 'cust_uberis'"); while($row = mysql_fetch_array($result2)) or die (mysql_error()); { echo $id . "Uber Island Is " . $row['value']; echo "<br />"; } } ?> Similar TutorialsMy hosts version of php just seems to automatically add the backslashes. Adding the escape string just seems to add like 3 of them rather than 1 Is this command out-of-date? Code: [Select] <?php $verificate = $_GET["ver"]; $username = $_GET["user"]; $password = $_GET["pass"]; $dbh = mysql_connect("localhost","XXXXXX_dtbusre","my database password here") or die(mysql_error()); mysql_select_db("databasename_zxq_dtb") or die(mysql_error()); $sql = "SELECT loggedin FROM entityTable WHERE username=$username"; $result = mysql_query($sql) or die(mysql_error()); while ($line = mysql_fetch_array($result)){ echo $line[0]."\t".$line[1]."\n"; } mysql_close($dbh); if($verificate === "144356455343"){ echo "SURE"; } else{ echo "NOPE"; } ?> I get this: Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Hei everyone. I am new on php development and i do not have budget on offering a course so i am trying to learn my self. i need some help on the following : i want to create infopanel.php where the script will get info from. For example if user logs in the script will have to call : <?php include '/incl/infopanel.php' ; ?>The info panel to load all details from database: <?php $name='$myname'; $sur_name='$sname'; $age='$myage'; $country='$mycountry'; ?>So the info with my has to be from database . so can some one help me how to call all information from database to a specific file that i will not have to call always information on every page I hope i have been so clean with my request Here is my HTML code: Code: [Select] <html> <head> <title>Simple Search Form</title> </head> <body> <form name="searchform" method="get" action="/search.php"> Select Gender: <select name="gender"> <option value="Male">Male</option> <option value="Female">Female</option> </select> Select City: <select name="gender"> <option value="all">All Cities</option> <option value="newyork">New York</option> <option value="toronto">Toronto</option> <option value="london">London</option> <option value="paris">Paris</option> </select> <form> </body> </html> Here is my PHP code: <?php // get the data from the search form # get the gender (male or female) $gender = $_GET['gender']; # get the city $city = $_GET['city']; // connect to mysql and select db mysql_connect('localhost', 'root', 'pass') or die(mysql_error()); mysql_select_db($test_db); // send query $query = mysql_query("SELECT * FROM `visitors_location` WHERE gender='$gender' AND city='$city'"); $count = mysql_num_rows($query); // display data while ( $show = mysql_fetch_assoc($query) ) { echo $gender . " " . $city; } ?> My script basically shows # of males or females in a specific city. How can I show all males in all cities? In other words, let's say I want to show # of Females from all those 4 cities combined. I don't know how to do that. Can someone please help me? Hi, Ive stumbled apon a Mongo database connected to a broadcast script. I would like to change it to a Mysql database can anybody please show me an example how it will look in Mysql format
<?php /* Require the PHP wrapper for the Mxit API */ require_once ('MxitAPI.php'); /* Function to count the number of users in MongoDB */ function count_users() { $mongo = new Mongo('127.0.0.1'); $collection = $mongo->sampleapp->users; $collection->ensureIndex(array('uid' => 1)); return $collection->count(); } /* Function to get batches of users from MongoDB */ function get_users($skip=0, $limit=50) { $mongo = new Mongo('127.0.0.1'); $collection = $mongo->sampleapp->users; $collection->ensureIndex(array('mxitid' => 1, 'created_at' => 1)); $users = $collection->find()->sort(array('created_at' => 1))->skip($skip)->limit($limit); return iterator_to_array($users); } /* Instantiate the Mxit API */ $api = new MxitAPI($key, $secret); /* Set up the message */ $message = "(\*) Congratulations to our winners (\*)\n\n"; $message .= "1st place - Michael with 100 points\n"; $message .= "2nd place - Sipho with 50 points\n"; $message .= "3nd place - Carla with 25 points\n\n"; $message .= 'Good Luck! :) $Click here$'; /* Mxit Markup is included in the message, so set ContainsMarkup to true */ $contains_markup = 'true'; /* Count the number of users in the database */ $count = count_users(); /* Initialise the variable that counts how many messages have been sent */ $sent = 0; /* Keep looping through the user list, until the number of messages sent equals the number of users */ while ($sent < $count) { /* Get users in batches of 50 */ $users = get_users($sent, 50); /* The list where the user MxitIDs will be stored */ $list = array(); foreach ($users as $user) { $list[] = $user['mxitid']; $sent++; } /* If there is a problem getting an access token, retry */ $access_token = NULL; while (is_null($access_token)) { /* We are sending a message so request access to the message/send scope */ $api->get_app_token('message/send'); $token = $api->get_token(); $access_token = $token['access_token']; // Only attempt to send a message if we have a valid auth token if (!is_null($access_token)) { $users = implode(',', $list); echo "\n$sent: $users\n"; $api->send_message($app, $users, $message, $contains_markup); } } } echo "\n\nBroadcast to $sent users\n\n"; Hi! I hope somebody can help me what im do wrong. i have checked that the data from the file is in $source_file but nothing imports to the database Code: [Select] <?php include('config.php'); include('opendb.php'); if(isset($_POST['upload'])) { $source_file = @$_POST['userfile']; //$source_file = fopen('http://localhost/test/upload/test.csv', 'r'); $target_table = 'foretag'; function csv_file_to_mysql_table($source_file, $target_table, $max_line_length=10000) { if (($handle = fopen("$source_file", "r")) !== FALSE) { $columns = fgetcsv($handle, $max_line_length, ","); foreach ($columns as $column) { $column = str_replace(".","",$column); } $insert_query_prefix = "INSERT INTO $target_table (".join(",",$columns).")\nVALUES"; while (($data = fgetcsv($handle, $max_line_length, ";")) !== FALSE) { while (count($data)<count($columns)) array_push($data, NULL); $query = "$insert_query_prefix (".join(",",quote_all_array($data)).");"; mysql_query($query); } fclose($handle); } } function quote_all_array($values) { foreach ($values as $key=>$value) if (is_array($value)) $values[$key] = quote_all_array($value); else $values[$key] = quote_all($value); return $values; } function quote_all($value) { if (is_null($value)) return "NULL"; $value = "'" . mysql_real_escape_string($value) . "'"; return $value; } } include('closedb.php'); echo "<br>done<br>"; ?> I have a webpage where the candidates can attach their resumes and send to the admin.These attachments are saved in the mysql db as blob datatype.In another webpage the admin needs to download all this resumes and see the content. How will i code for that. Hello. I'm a newbie so sorry if this isn't the best forum to post my problem.
I am using a MySQL and PHP to create a web app. I have authentication, and I can register users. I also have a form that users provide information and it is successfully inserting data into a table in my database.
I will use fictional fields for my database table called meal_info:
username
dateStartedDiet
numberMealsPerDay
costPerMeal
Problem: Select user-specific data from the MySQL database, using Session username to select only the current user's data, then display it and do some calculations.
Here is thecode at the top, and I am fairly sure it's working:
session_start(); //execute commone code
require("common.php"); //includes code to connect to database, etc.
if(empty($_SESSION['user'])) I'm attempting to implement a simple social networking system but at the moment am confused about how to create a multiple query which will display a certain user's friends list. The database contains four tables, the two tables that I'm using at the moment at 'usersTable' and 'friendshipsTable' are detailed below. usersTable | Table that stores all the user data UserID | Default primary key Forename | Surname | Username | Password | Email Address | friendshipTable | Table that stores information about friendships between users FriendshipID | Default primary key userID_1 | UserID userID_2 | UserID Status | Either Pending or Confirmed. The user's id is parsed into the url, and then saved into a variable. blah.com/userprofile.php?id=6 $id = $_GET['id']; I am familiar with creating simple queries, but can't quite work out how to set up multiple table queries. What the query needs to do is to check the userID that is parsed with the url, and then check the friendshipsTable by checking if either the userID_1 or userID_2 field matches the userID to grab the records from the table where there is a match. The next step is to check to see if the friendship is 'Confirmed' or 'Pending' and if it is 'Pending' to ignore it. Once the records have then been chosen I need the query to then check the value in either userID_1 or userID_2 that doesn't match userID and then pull the user's username and name from the usersTable so it can be displayed on a webpage. I've no idea hoe much I may or may not be overcomplicating this, an example of the code that I've got so far for this query can be found below, but that's as far as I've got at the moment. $displayFriends = mysql_query("SELECT * FROM friendshipTable, usersTable WHERE friendshipTable.userID_1='$id' OR friendshipTable.userID_2='$id' "); Cheers for any help. I am creating a site to display some products. For ease of updating I want it to run off a MySQL database. I have created the database and php scripts to output and input data etc. I know want to show that data in my web pages. My question is.... Is it best to insert HTML into the php output script to display the information and make the site look how I want....OR ....... should I create a template of the site in HTML and then somehow call the php output script (and the particular row of the database...) Basically... should I put the html code into the php - OR - put the php into the HTML?? I hope this make sense...... thanks This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=333523.0 create 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) i have a piece of code which subtracts credits every time a button is clicked. the original code works fine. I have since added a bonus_credit column, where i want it to function like this. if buy_credit = 0 and bonus_credit>0 then subtract from the bonus credit, but still do everything else its supposed to do.. here is the original code i had $selRes=mysql_query("SELECT buy_credit from user where id='".$hb_id."' and buy_credit>0"); if(mysql_affected_rows()>0) { $b_comm=0; $bc_updqry=mysql_query("UPDATE user set buy_credit=buy_credit-1 where id='".$hb_id."'"); $updqry=mysql_query("UPDATE cars set b_fee_paid_status='1' where id='".$aid."'"); } here is my modified code, but it doesn't seem to subtract from buy_credit if buy_credit is >0.. it should only kick in the bonus_credit usage if buy_credit is 0 $selRes=mysql_query("SELECT buy_credit,bonus_credit from user where id='".$hb_id."' and buy_credit>0 OR bonus_credit>0"); if(mysql_affected_rows()>0) { $b_comm=0; if($selRes['buy_credit']!=0) { $bc_updqry=mysql_query("UPDATE user set buy_credit=buy_credit-1 where id='".$hb_id."'"); } else { $bc_updqry=mysql_query("UPDATE user set bonus_credit=bonus_credit-1 where id='".$hb_id."'"); } $updqry=mysql_query("UPDATE cars set b_fee_paid_status='1' where id='".$aid."'"); } your help is appreciated. i need help with mysql.php this keeps coming up when i try to log into my game Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in /home/tassie12/domains/kronicalwars.co.cc/public_html/mysql.php on line 2 Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/tassie12/domains/kronicalwars.co.cc/public_html/mysql.php on line 3 Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/tassie12/domains/kronicalwars.co.cc/public_html/authenticate.php on line 30 Access denied for user 'root'@'localhost' (using password: YES) can someone send me the code for mysql.php for mccodes and tell me where to put the database user and pass? Hello Forum, please can someone help me solve this error in the code below, thanks Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\XAMPP\xampp\htdocs\testingSite\addtobasket.php on line 10 Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\XAMPP\xampp\htdocs\testingSite\addtobasket.php on line 11 <?php session_start(); require("db.php"); require("function.php"); $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir); $prodsql = "SELECT * FROM products WHERE id =" .$_GET['id'] . "'"; $prodres = mysql_query($prodsql); $numrows = mysql_num_rows($prodres); $prodrow = mysql_fetch_assoc($prodres); if($numrows == 0) { header("Location: ". $config_basedir); } else { if($_POST['submit']) { if($_SESSION['SESS_ORDERNUM']) { $itemsql = "INSERT INTO orderitems(order_id, product_id, quantity) VALUES (" . $_SESSION['SESS_ORDERNUM'] . "," . $_GET['id'] . "," . $_POST['amountBox'] .")"; mysql_query($itemsql); } else { if($_SESSION['SESSION_LOGGEDIN']) { $sql = "INSERT INTO orders(customer_id, registered, date) VALUES (" . $_SESSION['SESS_USERID'] . ", 1, NOW())"; mysql_query($sql); session_register("SESS_ORDERNUM"); $_SESSION['SESS_ORDERNUM'] = mysql_insert_id(); $itemsql = "INSERT INTO orderitems(order_id, product_id, quantity) VALUES (" . $_SESSION['SESS_ORDERNUM'] .",". $_GET['id'] . "," . $_POST['amountBox'] . ")"; mysql_query($itemsql); } else { $sql = "INSERT INTO orders(registered, date, session) VALUES(" ."o, NOW(),'" . session_id() . "')"; mysql_query($sql); session_registered("SESS_ORDERNUM"); $_SESSION['SESS_ORDERNUM'] = mysql_insert_id(); $itemsql = "INSERT INTO orderitems(order_id, product_id, quantity) VALUES(" . $_SESSION['SESS_ORDERNUM'] . "," .$_GET['id'] . "," . $_POST['amountBox'] . ")"; mysql_query($itemsql); } } $totalprice = $prodrow['price'] * $_POST['amountBox']; $updsql = "UPDATE orders SET total + ". $totalprice . " WHERE id = " . $_SESSION['SESS_ORDERNUM'] . ";"; mysql_query($updres); header("Location: " . $config_basedir . "showcart.php"); } else { require("header.php"); echo "<form action='addtobasket.php?id=" .$_GET['id'] . "' method='POST'>"; echo "<table cellpadding='10'>"; echo "<tr>"; if(empty($prodrow['image'])) { echo "<td><img src='./images.dummy.jpg' width='50' alt='" . $prodrow['name'] . "'></td>"; } else { echo "<td><img src=' ./images/" . $prodrow['image'] . "' width='50' alt='" . $prodrow['name'] . "'></td>"; } echo "<td>" . $prodrow['name'] ."</td>"; echo "<td>Select Quantity <select name='amountBox'>"; for($i=1;$i<=100;$i++) { echo "<option>" . $i . "</option>"; } echo "</select></td>"; echo "<td><strong>£" . sprintf('%.2f', $prodrow['price']) . "</strong></td>"; echo "<td><input type='submit' name='submit' value='Add to basket'></td>"; echo "</tr>"; echo "</table>"; echo "<form>"; } } require("footer.php"); ?> Ok, first let me say hello, and thanks for viewing this. I do not know very much about PHP at all, and therein lies the problem... I was editing a php document for my friends website. All I was doing was adding a line of code so that his site would include a favicon. I right-clicked on the website and viewed his source, and copied all the code into notepad, added the string of code for the favicon, and uploaded it to his FTP. Unfortunately when I did that I overwrote some of the PHP code I believe...it didn't copy that when I viewed the site source. I want to make it right for my friend and fix his website but I have NOOOO idea what to do... So I have turned to this forum for help... This is my friends website: thcklan . com The "recent topics" and "recent posts" at the top, the "hackers banned from our servers," and the "announcements" no longer update properly... It's like they are frozen at the state they were in when I copied the site's source code... I feel like an utter jack arse for ruining my buds front page. Please, I am asking you from deep within my heart, HELP ME, point me in the right direction, or guide me in some way to make it right to my good friend and fix his site! Hello everyone,
I run a small url shorting service.
I have bought the script and everything which short long urls. And i want to use a php code in one of the pages.
Let me explain you in detail first.
My site is https://786.pw and user goes there and enter the long url and the short url becomes something like https://786.pw/shorturl ( for example)
Now when this short url which is https://786.pw/shorturl is hit the user is redirected to the original long url. And thats how it is supposed to work.
But in between i have the option to show a splash page which can be a advertisement or a timer or anything "
The code of splash.php is :-
<?php defined("APP") or die() // Media Page ?> <?php include_once("analyticstracking.php") ?> <section> <div class="container splash"> <?php echo $this->ads(728,FALSE) ?> <div class="row"> <div class="col-md-4 thumb"> <div class="panel panel-dark panel-body"> <img src="<?php echo $url->short ?>/i"> </div> </div> <div class="col-md-8"> <div class="panel panel-default panel-body"> <h2> <?php if (!empty($url->meta_title)): ?> <?php echo $url->meta_title ?> <?php else: ?> <?php echo e("You are about to be redirected to another page.") ?> <?php endif ?> </h2> <p class="description"> <?php if (!empty($url->meta_description)): ?> <?php echo $url->meta_description ?> <?php endif ?> </p> <br> <div class="row"> <div class="col-sm-6"> <a href="<?php echo $this->config["url"] ?>/?r=<?php echo base64_encode($url->url) ?>" class="btn btn-primary btn-block redirect" rel="nofollow"><?php echo e("Redirect me"); ?></a> </div> <div class="col-sm-6"> <a href="<?php echo $this->config["url"] ?>" class="btn btn-default btn-block" rel="nofollow"><?php echo e("Take me to your homepage") ?></a></a> </div> </div> <hr> <p class="disclaimer"> <?php echo e("You are about to be redirected to another page. We are not responsible for the content of that page or the consequences it may have on you.") ?> </p> </div> </div> </div> </div> </section>Now, I want to add solve media php script in it. Which means any user who is using our url shortner service needs to complete the captcha before he can be finally directed to the destination url. The script supports solvemedia captcha solving. I spoke to the creator of this script and he told me this. "You will need to have some basic php knowledge to achieve this. |