PHP - Getting Specific Data From A Mysql Table
I am trying to get specific data from a MySQL table but cannot seem to find a proper command.
Code: [Select] $link = mysqli_connect('#####', '########', '########'); $user = $_SESSION['username']; $email = mysqli_query($link,"select email from members where username='$user'"); echo $email; Specifically, I am trying to get the email address stored for the user specified by the session, and display that address. However, I do not get any output with the current code, and am not sure what to try next. I have tried mysqli_fetch_row() but it only returns an error. Similar TutorialsI am not sure if the title is correct; I tried my best.
I'm a PHP/MySQL beginner and I really need some help.
I have a small script that I am using for sending SMS. I recently added a phonebook. The problem with the phonebook right now is that it's available to all users, i.e. they can all update and delete all rows. What I would like to do is make it so that each user can update and delete only their own contacts.
I have a table call contacts. Inside that table there is first name, last name, company and phonenumber.
How can I accomplish this with PHP & MySQL?
CREATE TABLE IF NOT EXISTS `contacts` ( `contact_id` int(10) NOT NULL AUTO_INCREMENT, `firstname` varchar(255) NOT NULL, `lastname` varchar(255) NOT NULL, `company` varchar(255) NOT NULL, `cell_no` text NOT NULL, PRIMARY KEY (`contact_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `users_name` varchar(30) NOT NULL, `uname` varchar(30) NOT NULL, `u_pass` varchar(60) NOT NULL, `utype` varchar(30) NOT NULL, `timezone` varchar(30) NOT NULL, `uapi_user` varchar(30) NOT NULL, `uapi_pass` varchar(60) NOT NULL, PRIMARY KEY (`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ; <?php if (isset($_POST['submit'])){ //form has been submitted1 $firstname = trim($_POST['firstname']); $lastname = trim($_POST['lastname']); $company = trim($_POST['company']); $cellno = trim($_POST['cell_no']); if($firstname == ''){ echo '<div class="alert alert-danger">First Name is not Valid!</div>'; exit; }elseif($lastname == ''){ echo '<div class="alert alert-danger">Last Name is not Valid!</div>'; exit; }elseif($company == ''){ echo '<div class="alert alert-danger">Company is not Valid!</div>'; exit; }elseif($cellno == ''){ echo '<div class="alert alert-danger">Cellphone Number is not Valid!</div>'; exit; }else{ $query = "Select cell_no from contacts where cell_no = '".$cellno."' "; $result = mysql_query($query); if (!mysql_num_rows($result)) { $sql = "INSERT INTO contacts(firstname, lastname, company, cell_no) values('{$firstname}','{$lastname}', '{$company}', '{$cellno}')"; $result = mysql_query($sql); confirm_query($result); //echo '<div class="alert alert-success">Successfully added.</div>'; //exit; ?> <script type="text/javascript"> window.location = "contact_list.php"; </script> <?php } else{ echo '<div class="alert alert-danger">Username. already exist!.</div>'; echo '<p><a href="new_contact.php" class="btn btn-success"> Back </a></p>'; exit; }} }else{ $firstname = ""; $lastname = ""; $company = ""; $cellno = ""; } ?> Hi guys ..
please help me .. I don't know how to do this and I tried but there were no satisfied results..
I want to retrieve a Title (ing_title) from a database called k_db2 , in a table called content_langs
depending on its ID , which called ing_contID
example: if ing_contID=1 , then show the ing_title with this id ing_contID
the above code should be in a php file ..
then I want to include this php file inside the header of my website..
by importing the ing_contID from the database and depending on it the title should be shown..
I really tried but I couldn't find any solution ..
if you could help me in the first part of this problem I'll be glad ..
Hello,
First of all I'd like to say thank you for all the great information on the forums, I've been reading a lot on here lately.
I've started to make a website where users can log in and submit items to a database, which is then displayed on another page.
If Tom and Bill both post 10 items, all 20 items will be displayed on the "listings" page, however on the main log in screen Tom will only see his own 10 items and Bill will see his own 10 items.
This is all working perfectly, however, I now need to add a delete button so that they can delete specific items.
I have loosely followed this tutorial here to get the table to display as I want it (amongst a few other things, such as the user logins) http://www.wickham43...mphptomysql.php
I've added the delete button in the PHP loop for each row, I just can't figure out how to delete the specific row when clicked.
Any help would be really appreciated
Edited by eklem, 22 October 2014 - 08:10 AM. SELECT * FROM `booking_tbl` WHERE booking_status = 'Check In' AND departure_date_time = NOW()"I use the datetime datatype for the departure_date_time so i can get data from that data because it checking the date and time but i want it to check on the date from the datetime datatype So how can i get the data only with that date without the time in the mysql datetime datatype 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'])) Hi guys, How do I call the 2nd row of 'TSuperQuestion'? Code: [Select] <?PHP $con = mysql_connect("localhost","ph6theo", "xxxx"); if (!$con) { die('Could not connect: ' . mysql_error("oop")); } mysql_select_db("ph6theo_testDB") or die(mysql_error()); $result = mysql_query("SELECT * FROM QANDATable "); $row = mysql_fetch_array($result); echo $row['TSuperQuestion']; ?> Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. I have a script that is supposed to allow a user to add their details to a members table in the database. It acts as if the user has been added to the database by stating the thank you message, but there is no entry into the database. I can connect to the database and have another script running OK that allows me to view all of the information in the members table with a loop (this data was entered using php my admin's GUI). Here is the script that is supposed to add the member. Any help would be greatly appreciated. <?php error_reporting(-1); $user_name = "root"; $password = ""; $database = "test"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "INSERT INTO members (fname, sname, email, password, gender) VALUES ('$_POST[fname]','$_POST[sname]','$_POST[email]','$_POST[password]','$_POST[gender]')"; $result = mysql_query($SQL); mysql_close($db_handle); print "Thanks for joining us ".$_POST['fname']."."; } else { print "Database NOT Found"; mysql_close($db_handle); } ?> Hello, can someone help me with my proggraming problem please. Am new in this so i still have lots problems. I need to put all data from my MySQL table in one table in html. There is catch... i need to design output to give me table with x rows and 3 columns, so it means while reading data from database it need put every 4th in new row. And if there isnt 3 data (or better say if there isnt 3 full <td>) in row code will automatically add empty <td> or 2 in table. So...did somebody do this before or have some code ? All i got for now is Code: [Select] $td ='<td align="center"><img src="'.$row['name'].'.png" /> <p style="font-family:Verdana, Geneva, sans-serif; font-size:15px"> Number: <b style="font-size:40px;">'.$row['serial'].'</b></p> <br><img width="90" height="29" src="'.$logo.'"/></td>'; $tr ='<tr>'.$td.'</tr>'; $html='<table border="1" align="center">'.$tr.'</table>'; Thanks. Hello, I know i'm new, i hope it wont stop you guys from putting 5 minutes of your time to help me out. I need a script to get some data from mysql and put this into a table. i have a mysql database called "denora" In there is a table called "chan" In table chan are the columns: chanid (unique number), channel, currentusers, mode_ls I would like the script to make a html table that lists the top10 channels (most "currentusers" on top) And when "mode_ls" is "Y" it must not be shown (secret channel) My knowledge of php and mysql arent that great so i really hope someone takes the time to help me uit Kind regards Stefan I have MySQL table with the following fields: user=>varchar product=>varchar Amount=>int Date=>date Note=>tinytext I can't add value to these field by the following php code: $date = date("Y.m.d"); $query = "INSERT INTO order VALUES ('farhad', 'Mango', '10', '$date', 'hello')"; $result = mysql_query($query) or die(mysql_error()); I receive the following warning: Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for '2.0/DST' instead in C:\inetpub\wwwroot\Okern\~order.php on line 10 Call Stack: 0.0047 325856 1. {main}() C:\inetpub\wwwroot\Okern\~order.php:0 0.0274 344912 2. date() C:\inetpub\wwwroot\Okern\~order.php:10 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 'order VALUES ('farhad', 'Mango', '10', '2011.04.17', 'hello')' at line 1 Can you add a WHERE clause in $row? For example: $row['city_display'] WHERE city_display = 1 $row['city_display'] WHERE city_display = 2 etc... How can this be done? Hi all, I'm new to php/myslq and I'm going crazy trying to figure this one out I'm building a personal calendar and I want to display the data into a HTML table. Code: [Select] //query the database $query = "SELECT * FROM tbl_events WHERE event_day=$day AND event_month=$month AND event_year=$year"; $query = mysql_query($query); //build the table echo '<table>'; for ($y = 0; $y < 6; $y++){ echo '<tr><td>'; //insert the data here echo '</td></tr>'; } echo '</table>'; When I store the events into the database, I assign a slot for each one depending on the hour. I don't want to use more than 6 events daily, hence the for loop. The problem I have is how to I insert the data into the designed <td>? In a particular day I could have only 2 events: event 1 - slot 2, event 2 - slot 6. I want to be able to enter each event into its own cell I hope I'm making myself clear enough. Sorry for any English mistakes if any. Thank you Hello guys, im using this code atm and it's working, but the new rows created are put in the end of the table. I want them to stack up from the beginning pushing older rows down. What should i do to make that work? <?php $con = mysql_connect("localhost","*****","*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ananaz_se", $con); $sql="INSERT INTO stuff (adult, namn, url) VALUES ('$_POST[adult]','$_POST[namn]','$_POST[url]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 row added"; mysql_close($con) ?> I have members.php: <?php /********************************************************************** Filename: members.php Version: $Id: members.php 17 2007-04-09 09:40:35Z Jez $ Description: This file displays the members screen once they've logged in. **********************************************************************/ /* Members script: */ include_once("config.php"); // Check user logged in already: checkLoggedIn("yes"); doCSS(); print("Welcome to the members page <b>".$_SESSION["login"]."</b><br>\n"); print("Your password is: <b>".$_SESSION["password"]."</b><br>\n"); print("<a href=\"logout.php"."\">Logout</a>"); ?> and functions.php: <?php /********************************************************************** Filename: functions.php Description: This file contains main stock of functions. This file is automatically 'include()'d by every page that include()'s the file 'config.php'. This has the benefit that every page that includes 'config.php' will have access to all of the functions in this file. **********************************************************************/ /******************************************************\ * Function Name : connectToDB() * * Task : create connection to db * * Arguments : none * * Globals: all defined in config.php * * Returns : none, sets $link * \******************************************************/ function connectToDB() { global $link, $dbhost, $dbuser, $dbpass, $dbname; /* Database connection: The PHP function mysql_pconnect() connects to a MySQL database with the arguments it is given. mysql_pconnect() creates a persistent database connection which can save some time when a number of mysql connections are made to the same db with the same user/password/dbhost triple. Further, when the execution of the PHP script ends, the connection to the database is NOT closed. In some rare cases this can cause problems. Alternatively mysql_connect() can be used and takes the same arguments as mysql_pconnect(). However mysql_connect() does not maintain a persistent connection - every call to mysql_connect() creates a new db connection. On a busy server this can significantly increase the amount of time taken to execute queries on the db. */ ($link = mysql_pconnect("$dbhost", "$dbuser", "$dbpass")) || die("Couldn't connect to MySQL"); // select db: mysql_select_db("$dbname", $link) || die("Couldn't open db: $dbname. Error if any was: ".mysql_error() ); } // end func dbConnect(); /******************************************************\ * Function Name : newUser($login, $pass) * * Task : Create a new user entry in the users table based on args passed * * Arguments : string($login, $pass) * * Returns : int($id), $id of new user * \******************************************************/ function newUser($login, $password) { /* Creating a New User Record in the DB: In this function we create a new user record in the db. We first build a query and save it into the $query variable. The query statement says: 'Insert the value of $login and $password into the 'login' and 'password' columns in the 'users' table' */ global $link; $query="INSERT INTO users (login, password) VALUES('$login', '$password')"; $result=mysql_query($query, $link) or die("Died inserting login info into db. Error returned if any: ".mysql_error()); return true; } // end func newUser($login, $pass) /******************************************************\ * Function Name : displayErrors($messages) * * Task : display a list of errors * * Arguments : array $messages * * Returns : none * \******************************************************/ function displayErrors($messages) { /* Error Handling functions: An error handling function is useful to have in any project. This particular function takes an array of messages, and for each message displays it in a list using HTML <ul><li></li></ul> tags. */ print("<b>There were problems with the previous action. Following is a list of the error messages generated:</b>\n<ul>\n"); foreach($messages as $msg){ print("<li>$msg</li>\n"); } print("</ul>\n"); } // end func displayErrors($messages) /******************************************************\ * Function Name : checkLoggedIn($status) * * Task : check if a user is (isn't) logged in depending on $status * * Arguments : quasi(!) boolean $status - "yes" or "no" * * Returns : * \******************************************************/ function checkLoggedIn($status){ /* Function to check whether a user is logged in or not: This is a function that checks if a user is already logged in or not, depending on the value of $status which is passed in as an argument. If $status is 'yes', we check if the user is already logged in; If $status is 'no', we check if the user is NOT already logged in. */ switch($status){ // if yes, check user is logged in: // ie for actions where, yes, user must be logged in(!) case "yes": if(!isset($_SESSION["loggedIn"])){ header("Location: login.php"); exit; } break; // if no, check NOT logged in: // ie for actions where user can't already be logged in // (ie for joining up or logging in) case "no": /* The '===' operator differs slightly from the '==' equality operator. $a === $b if and only if $a is equal to $b AND $a is the same variable type as $b. for example, if: $a="2"; <-- $a is a string here $b=2; <-- $b is an integer here then this test returns false: if($a===$b) whereas this test returns true: if($a==$b) */ if(isset($_SESSION["loggedIn"]) && $_SESSION["loggedIn"] === true ){ header("Location: members.php"); } break; } // if got here, all ok, return true: return true; } // end func checkLoggedIn($status) /******************************************************\ * Function Name : checkPass($login, $password) * * Task : check login/passwd match that stored in db * * Arguments : string($login, $password); * * Returns : array $row - array of member details on success * false on failure \******************************************************/ function checkPass($login, $password) { /* Password checking function: This is a simple function that takes the $login name and $password that a user submits in a form and checks that a row exists in the database whe the value of the 'login' column is the same as the value in $login and the value of the 'password' column is the same as the value in $password If exactly one row is returned, then that row of data is returned. If no row is found, the function returns 'false'. */ global $link; $query="SELECT login, password FROM users WHERE login='$login' and password='$password'"; $result=mysql_query($query, $link) or die("checkPass fatal error: ".mysql_error()); // Check exactly one row is found: if(mysql_num_rows($result)==1) { $row=mysql_fetch_array($result); return $row; } //Bad Login: return false; } // end func checkPass($login, $password) /******************************************************\ * Function Name : cleanMemberSession($login, $pass) * * Task : populate a session variable * * Arguments : string $login, string $pass taken from users table in db. * * Returns : none * \******************************************************/ function cleanMemberSession($login, $password) { /* Member session initialization function: This function initializes 3 session variables: $login, $password and $loggedIn. $login and $password are used on member pages (where you could allow the user to change their password for example). $loggedIn is a simple boolean variable which indicates whether or not the user is currently logged in. */ $_SESSION["login"]=$login; $_SESSION["password"]=$password; $_SESSION["loggedIn"]=true; } // end func cleanMemberSession($login, $pass) /******************************************************\ * Function Name : flushMemberSession($session) * * Task : unset session variables and destroy session * * Arguments : array $session * * Returns : true * \******************************************************/ function flushMemberSession() { /* Member session destruction function: This function unsets all the session variables initialized above and then destroys the current session. */ // use unset to destroy the session variables unset($_SESSION["login"]); unset($_SESSION["password"]); unset($_SESSION["loggedIn"]); // and use session_destroy to destroy all data associated // with current session: session_destroy(); return true; } // send func flushMemberSession() /******************************************************\ * Function Name : doCSS() * * Task : output the CSS for the screens * * Arguments : * * Returns : * \******************************************************/ function doCSS() { /* CSS Output: This function simply outputs some cascading style sheet data for markup by the user's browser. */ ?> <style type="text/css"> body{font-family: Arial, Helvetica; font-size: 10pt} h1{font-size: 12pt} </style> <?php } // end func doCSS() # function validates HTML form field data passed to it: function field_validator($field_descr, $field_data, $field_type, $min_length="", $max_length="", $field_required=1) { /* Field validator: This is a handy function for validating the data passed to us from a user's <form> fields. Using this function we can check a certain type of data was passed to us (email, digit, number, etc) and that the data was of a certain length. */ # array for storing error messages global $messages; # first, if no data and field is not required, just return now: if(!$field_data && !$field_required){ return; } # initialize a flag variable - used to flag whether data is valid or not $field_ok=false; # this is the regexp for email validation: $email_regexp="^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|"; $email_regexp.="(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; # a hash array of "types of data" pointing to "regexps" used to validate the data: $data_types=array( "email"=>$email_regexp, "digit"=>"^[0-9]$", "number"=>"^[0-9]+$", "alpha"=>"^[a-zA-Z]+$", "alpha_space"=>"^[a-zA-Z ]+$", "alphanumeric"=>"^[a-zA-Z0-9]+$", "alphanumeric_space"=>"^[a-zA-Z0-9 ]+$", "string"=>"" ); # check for required fields if ($field_required && empty($field_data)) { $messages[] = "$field_descr is a required field."; return; } # if field type is a string, no need to check regexp: if ($field_type == "string") { $field_ok = true; } else { # Check the field data against the regexp pattern: $field_ok = ereg($data_types[$field_type], $field_data); } # if field data is bad, add message: if (!$field_ok) { $messages[] = "Please enter a valid $field_descr."; return; } # field data min length checking: if ($field_ok && ($min_length > 0)) { if (strlen($field_data) < $min_length) { $messages[] = "$field_descr is invalid, it should be at least $min_length character(s)."; return; } } # field data max length checking: if ($field_ok && ($max_length > 0)) { if (strlen($field_data) > $max_length) { $messages[] = "$field_descr is invalid, it should be less than $max_length characters."; return; } } } ?> The db has an table users with id, login, password, site Question how can i get inf from "site" raw for logged user on members.php ( as a link). Pls help thanks
Hello, I have the problem that only one user is displayed in the table require('connection/db1.php'); // Teilnehmerliste $query = 'SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); //fetch $result2 = $start->fetch(); // Zählung der Datensätze $count = $start->rowCount(); <table class="table"> <thead> <tr> <th scope="col">User</th> <th scope="col">Datum</th> <th scope="col"><a class="btn btn-primary" href="convoy_user.php?id=<?php echo $result['id']; ?>&action=part" role="button">Teilnehmen</a></th> </tr> </thead> <tbody> <tr> <th scope="row"><?php echo $result2['name']; ?></th> <td><?php echo $result2['date']; ?></td> </tr> </tbody> </table>
Ok I was wondering is there a way I can select a mysql database, and order it but only show data of a certain criteria: for example Mysql database: ID | User | XP | Won | Lost 1 Freid 100 1 4 2 Smic 300 5 4 3 Retna 300 3 2 4 OBW 200 3 2 And then some php code that will retrieve this information but only display the users that have lost = 4 in a list. In other words some php code that will only list the players Freid and Smic from the msql database becuase they have Lost = 4 the code would not show Retna or OBW becuase there Lost is not = to 4 Any help would be great thanks Freid001 Hi, I am extracting data from a mysql db to then edit and update back into the db and use below to list items first - Code: [Select] <?php // Connect to server and select database. mysql_connect('localhost', 'xxxxxxxxx', 'xxxxxxxxxxxxx') or die("Error: ".mysql_error()); mysql_select_db("xxxxxxxxx"); $sql="SELECT * FROM properties"; $result=mysql_query($sql); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td> <table width="400" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><strong>List data from mysql </strong> </td> </tr> <tr> <td align="center"><strong>Name</strong></td> <td align="center"><strong>Lastname</strong></td> <td align="center"><strong>Email</strong></td> <td align="center"><strong>Update</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><? echo $rows['Property_Rating']; ?></td> <td align="center"><a href="update.php?id=<? echo $rows['ID']; ?>">update</a></td> </tr> <?php } ?> </table> </td> </tr> </table> <?php mysql_close(); ?> I then go next page where I show data and allow editing - <?php // Connect to server and select database. mysql_connect('localhost', 'xxxxxxxxx', 'xxxxxxxxxxxxx') or die("Error: ".mysql_error()); mysql_select_db("xxxxxxxxx"); // get value of id that sent from address bar $id=$_GET['id']; // Retrieve data from database $sql="SELECT * FROM properties WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="update_ac.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><strong>Update data in mysql</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>Property_Name</strong></td> <td align="center"><strong>roperty_Rating</strong></td> <td align="center"><strong>Property_Address</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="Property_Rating" type="text" id="Property_Rating" value="<? echo $rows['Property_Rating']; ?>"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td> <td align="center"><input type="submit" name="Submit" value="Submit"></td> <td> </td> </tr> </table> </td> </form> </tr> </table> <? // close connection mysql_close(); ?> And then the update page - <?php // Connect to server and select database. mysql_connect('localhost', 'xxxxxxxxx', 'xxxxxxxxxxxxx') or die("Error: ".mysql_error()); mysql_select_db("xxxxxxxxx"); // update data in mysql database $sql="UPDATE properties SET Property_Name='$Property_Name' WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successful"; } else { echo "ERROR"; } ?> Everything seems ok but when I edit the data and submit I get the success message but data not changed in db. Any ideas? Thanks. MOD EDIT: code tags added. Hi I have a table (applicant) and I am looking at producing a pdf displaying various items of data from this table. I have succeeded in getting the look I want but in my query I use a fixed applicantid (in this case an id of 4). What I want to be able to do is to have the id cary according to the url. In other words, when someone comes from one web page to this one and the url is of the format .../pdf_production.php?applicantid=42. I'm not sure I've explained that very well but I hope someone can help - I think this is the last thing I need to sort out. Many thanks in advance. The code I have so far is: <?php require_once('../Connections/process.php'); ?> <?php require_once('../tcpdf/config/lang/eng.php'); require_once('../tcpdf/tcpdf.php'); // get data from users table mysql_select_db($database_process, $process); $result = mysql_query("SELECT * FROM applicant WHERE applicantid = '4'"); while($row = mysql_fetch_array($result)) { $appid = $row['applicantid']; $idcode = $row['idcode']; $type = $row['type']; $company = $row['company']; $email = $row['email']; } // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // --------------------------------------------------------- // set font $pdf->SetFont('dejavusans', '', 10); // add a page $pdf->AddPage(); // create some HTML content $txt = <<<EOD Below are the details I require Company type: $type Company Name: $company Company email: $email EOD; // output the HTML content // $pdf->writeHTML($htmlcontent, true, 0, true, 0); $pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0); // $pdf->writeHTML($inlinecss, true, 0, true, 0); // reset pointer to the last page // $pdf->lastPage(); //Close and output PDF document $pdf->Output('example_006.pdf', 'I'); //============================================================+ // END OF FILE //============================================================+ ?> I have a few tables in a project and i'm linking pages together via PK/FK's. i have a main table with client names, ID, CLIENT NAME, ETC i have a table with communications COMMID, ID, CONTACT NAMES, ETC and another of communication history. COMMHISTORYID, COMMID, DATE, TIME, ETC I'm not sure how to write the query so that i can view/update information from all 3 tables on the same webpage page using php/mysql. I'd appreciate any assistance you may provide. thanks. |