PHP - I Want To Send Data From My Local Server Database Table To Different Database With The Same Table
the second database found on the cloud
i try to get JSON data but how to insert and update them to another online database with the same table my php script to return json data <?php include_once('db.php'); $users = array(); $users_data = $db -> prepare('SELECT id, username FROM users'); $users_data -> execute(); while($fetched = $users_data->fetch()) { $users[$fetchedt['id']] = array ( 'id' => $fetched['id'], 'username' => $fetched['name'] ); } echo json_encode($leaders);
i get
{"1":{"id":1,"username":"jeremia"},"2":{"id":2,"username":"Ernest"}} Edited March 24 by mahenda Similar TutorialsHi, I got this script which I would like to send a message to all email addresses in the database or send to approved members only. Once I got the first part of this script working I can get the rest to work when sending to approved members. Here is the form which passes the message to the script. Code: [Select] <?php include_once("data/server.php"); $all = 'unchecked'; $approved = 'unchecked'; if (isset($_POST['Submit1'])) { $selected_radio = $_POST['Mailto']; if ($selected_radio == 'all') { $all = 'checked'; } else if ($selected_radio == 'approved') { $approved = 'checked'; } } ?> <div id="pageNav"> <div id="sectionLinks"> <a href="admin.php?cmd=database&username=admin">Database</a> <a href="admin.php?cmd=uploads&username=admin">Uploads</a> <a href="admin.php?cmd=editTemplate&username=admin">Templates </a> <a href="admin.php?cmd=email&username=admin">Email</a> <a href="admin.php?cmd=messaging&username=admin">Messaging</a> <a href="admin.php?cmd=protected&username=admin">Protected Directory</a> <a href="admin.php?cmd=filesanddir&username=admin">Files and Directories</a> <a href="admin.php?cmd=usertracking&username=admin">User Tracking</a> <a href="admin.php?cmd=advanced&username=admin">Advanced</a> <a href="admin.php?cmd=uploads&username=admin">Uploads</a> <a href="admin.php?cmd=subscriptions&username=admin">Subscriptions</a> <a href="admin.php?cmd=applications&username=admin">Applications</a> <a href="admin.php?cmd=searchForms&username=admin">Search Form Builder</a> <a href="admin.php?cmd=categories&username=admin">Categories</a> <a href="admin.php?cmd=phpBB&username=admin">phpBB</a> <a href="admin.php?cmd=mySQL&username=admin">MySQL</a></div> </div> <div id="content"> <div class="page"> <form action=templates/admin/msgtest.php method=POST> <table> <tr> <td>Your Message:</td> <tr><td> </td><td> </td></tr> <tr><td><TEXTAREA NAME="message" COLS=40 ROWS=6></TEXTAREA></td></tr> </table> <table> <tr> <td><input type = 'Radio' Name ='Mailto' value= 'yes' <?PHP print $all; ?> </td> <td>Send Message to all members</td> </tr> <tr> <td><input type = 'Radio' Name ='Mailto' value= 'yes' <?PHP print $approved; ?> </td> <td>Send Message to Approved members only</td> </tr> <tr><td colspan=2><input type=submit name=submit value=Submit></td></tr> </table> </form> </table> </div> </div> </div> And here is the code I have got so far but it doesnt work Code: [Select] <?php include_once("../../data/server.php"); include("../../data/mysql.php"); if (isset($_POST['Submit1'])) { $selected_radio = $_POST['Mailto']; if ($selected_radio == 'all') { $mysqlPassword = (base64_decode($mysqlpword)); $con = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die(mysql_error()); mysql_select_db("$dbname", $con) or die(mysql_error()); $q2 = "select * from games_newsletter "; $result = mysql_query("SELECT email FROM profiles"); while ($email = mysql_fetch_assoc($result)) { $to = $email; $subject = "Test Message"; $body = "This is a test message"; $headers = "From: payments@tropicsbay.co.uk\r\n" . "X-Mailer: php"; if (mail($to, $subject, $body, $headers)) { // Redirect back to manage page header("Location: admin.php?cmd=messaging"); } else { echo "Approval Message Failed"; } } mysql_close($con); } } ?> As always, any help is much appreciated Paul Hi, For about a month, I have been trying to figure out why my code will not return anything after posting a wwwForm (I have also tried the newer equivalent of this function but I had no luck with that either.) The nameField and passwordField are taken from text boxes within the game and the code used in my login script is copied and pasted from a Register script but I have changed the file location to the login.php file. The register script works fine and I can add new users to my database but the login script only outputs "Form Sent." and not the "present" that should return when the form is returned and it never gets any further than that point meaning that it lets the user through with no consequence if they use an invalid name because the script never returns an answer. What should I do to fix this? Thanks, Unity Code: using System.Collections; using UnityEngine; using UnityEngine.UI; using UnityEngine.Networking; public class Login : MonoBehaviour { public InputField nameField; public InputField passwordField; public Button acceptSubmissionButton; public void CallLogInCoroutine() { StartCoroutine(LogIn()); } IEnumerator LogIn() { WWWForm form = new WWWForm(); form.AddField("username", nameField.text); form.AddField("password", passwordField.text); WWW www = new WWW("http://localhost/sqlconnect/login.php", form); Debug.Log("Form Sent."); yield return www; Debug.Log("Present"); if (www.text[0] == '0') { Debug.Log("Present2"); DatabaseManager.username = nameField.text; DatabaseManager.score = int.Parse(www.text.Split('\t')[1]); Debug.Log("Log In Success."); } else { Debug.Log("User Login Failed. Error #" + www.text); } } public void Validation() { acceptSubmissionButton.interactable = nameField.text.Length >= 7 && passwordField.text.Length >= 8; } } login.php: <?php echo "Test String2"; $con = mysqli_connect('localhost', 'root', 'root', 'computer science coursework'); // check for successful connection. if (mysqli_connect_errno()) { echo "1: Connection failed"; // Error code #1 - connection failed. exit(); } $username = mysqli_escape_string($con, $_POST["username"]); $usernameClean = filter_var($username, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH); $password = $_POST["password"]; if($username != $usernameClean) { echo "7: Illegal Username, Potential SQL Injection Query. Access Denied."; exit(); } // check for if the name already exists. $namecheckquery = "SELECT username, salt, hash, score FROM players WHERE username='" . $usernameClean . "';"; $namecheck = mysqli_query($con, $namecheckquery) or die("2: Name check query failed"); // Error code # 2 - name check query failed. if (mysqli_num_rows($namecheck) != 1) { echo "5: No User With Your Log In Details Were Found Or More Than One User With Your Log In Details Were Found"; // Error code #5 - other than 1 user found with login details exit(); } // get login info from query $existinginfo = mysqli_fetch_assoc($namecheck); $salt = $existinginfo["salt"]; $hash = $existinginfo["hash"]; $loginhash = crypt($password, $salt); if ($hash != $loginhash) { echo "6: Incorrect Password"; // error code #6 - password does not hash to match table exit; } echo "Test String2"; echo"0\t" . $existinginfo["score"]; ?>
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. hi everyone, i just signed up on this forum. I have issue, my clients wants to save time by copying data into a textarea and then letting the script process it and store it in database. the problem is never done that. the data is made up for eg. Title Mr Name Radio86 Address Chiltren House etc.... how do i split this data up and store it in database, btw ive just started programming in php in other words newbie Please help me, thanks in advance how i want to display data from database to look like this : <table width="633" height="224" border="1"> <tr bgcolor="#999900"> <td width="45">Bil</td> <td width="121">Course_name</td> <td width="83">session</td> <td width="83">start_date</td> <td width="83">end_date</td> <td width="83">notes</td> <td width="89">pre-req</td> </tr> <tr bgcolor="#6A7AEA"> <td rowspan="2">1.</td> <td rowspan="2" bgcolor="#6A7AEA">Math</td> <td>1st session </td> <td>1 jan 11 </td> <td>6 jan 11 </td> <td rowspan="2"> </td> <td rowspan="2"><image icon that will link to the oter site> </td> </tr> <tr> <td bgcolor="#6A7AEA">2nd session </td> <td bgcolor="#6A7AEA">8 jan 11 </td> <td bgcolor="#6A7AEA">15 jan 11 </td> </tr> <tr> <td bgcolor="#0066CC">2.</td> <td bgcolor="#0066CC">English</td> <td bgcolor="#0066CC">1st session </td> <td bgcolor="#0066CC">1 feb 11 </td> <td bgcolor="#0066CC">6 feb 11 </td> <td bgcolor="#0066CC"> </td> <td bgcolor="#0066CC"><image icon that will link to the oter site></td> </tr> <tr> <td rowspan="2" bgcolor="#6A7AEA">3.</td> <td rowspan="2" bgcolor="#6A7AEA">Science</td> <td height="29" bgcolor="#6A7AEA">1st session </td> <td bgcolor="#6A7AEA">8 march 11 </td> <td bgcolor="#6A7AEA">15 march 11 </td> <td rowspan="2" bgcolor="#6A7AEA"> </td> <td rowspan="2" bgcolor="#6A7AEA"><image icon that will link to the oter site></td> </tr> <tr> <td bgcolor="#6A7AEA">2nd session</td> <td bgcolor="#6A7AEA">16 march 11 </td> <td bgcolor="#6A7AEA">21 march 11 </td> </tr> </table> ** all the view data is called from database including the icon image thanks... Hello everyone,
i'm Osiris and i'm stuck with this PHP/HTML code, i'm fairly new at this so this might be a dumb question.
i have a database, but i want to output all data into a table from the database using HTML codes.
i had it so far that i could outpust the info in just plain text but it doesn't output in the HTML table.
Can anyone see what i did wrong?
This is my PHP code its in the body section
<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'SELECT `Name`, `Color`, `Type`, `Subtype`, `Power`, `Toughness`, `Manacost`, `Rarity`, `Expansion`, `Foil`, `Stock` FROM `mtgtabel`'; mysql_select_db('mtgstock'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } echo '<table class=mytable>'; echo "<tr><th >Name</th><th >Color</th><th >Type</th><th >Sub Type</th><th >Power</th><th >Toughness</th><th >Converted mana cost</th><th >Rarity</th><th >Expansion</th><th >Foil</th><th >Stock</th></tr>"; while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "<tr><td>"; echo $row['Name'] echo "</td><td>"; echo $row['Color']; echo "</td><td>"; echo $row['Type']; echo "</td><td>"; echo $row['Subtype']; echo "</td><td>"; echo $row['Power']; echo "</td><td>"; echo $row['Toughness']; echo "</td><td>"; echo $row['Manacost']; echo "</td><td>"; echo $row['Rarity']; echo "</td><td>"; echo $row['Expansion']; echo "</td><td>"; echo $row['Foil']; echo "</td><td>"; echo $row['Stock']; echo "</td></tr>"; } echo "</table>"; mysql_close($conn); ?>Thanks in advance! Hey, sorry I'm a newb so prepare for me to do everything wrong even though I read the FAQ.
I'm trying to use a simple php script to input data to register but I get this error:
"Failed to run query: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined" once I fill out the form.
I've seen other people get this error but I seem to have different problems to them and can't figure it out.
My PHP script is just
<?php require("config.inc.php"); //if posted data is not empty if (!empty($_POST)) { if (empty($_POST['username']) || empty($_POST['password'])) { $response["success"] = 0; $response["message"] = "Please Enter Both a Username and Password."; die(json_encode($response)); } $query = " SELECT 1 FROM users WHERE username = :user"; $query_params = array( ':user' => $_POST['username'] ); try { $stmt = $db->prepare($query); $result = $stmt->execute($query_params); } catch (PDOException $ex) { die("Failed to run query: " . $ex->getMessage()); $response["success"] = 0; $response["message"] = "Database Error. Please Try Again!"; die(json_encode($response)); } $row = $stmt->fetch(); if ($row) { die("This username is already in use"); $response["success"] = 0; $response["message"] = "I'm sorry, this username is already in use"; die(json_encode($response)); } $query = "INSERT INTO users ( username, password ) VALUES ( :user, :pass ) "; $query_params = array( ':username' => $_POST['username'], ':password' => $_POST['password'] ); try { $stmt = $db->prepare($query); $result = $stmt->execute($query_params); } catch (PDOException $ex) { die("Failed to run query: " . $ex->getMessage()); $response["success"] = 0; $response["message"] = "Database Error. Please Try Again!"; die(json_encode($response)); } $response["success"] = 1; $response["message"] = "Username Successfully Added!"; echo json_encode($response); } else { ?> <h1>Register</h1> <form action="index.php" method="post"> Username:<br /> <input type="text" name="username" value="" /> <br /><br /> Password:<br /> <input type="password" name="password" value="" /> <br /><br /> <input type="submit" value="Register New User" /> </form> <?php } ?>and the config: <?php $username = "root"; $password = ""; $host = "localhost"; $dbname = "drinkdealz"; $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'); try { $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); } catch(PDOException $ex) { die("Failed to connect to the database: " . $ex->getMessage()); } $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { function undo_magic_quotes_gpc(&$array) { foreach($array as &$value) { if(is_array($value)) { undo_magic_quotes_gpc($value); } else { $value = stripslashes($value); } } } undo_magic_quotes_gpc($_POST); undo_magic_quotes_gpc($_GET); undo_magic_quotes_gpc($_COOKIE); } header('Content-Type: text/html; charset=utf-8'); session_start(); ?>Sorry if I uploaded anything wrong and it's only a localhost so I don't really care about passwords etc (none will be the same when I upload it) So if any of you can even point me in the direction of what to look for that would be brilliant. Cheers, Kieran i have 8 division (div), i want to display 4 rows in 4 division and the remain 4 rows in the next 4 division here is my code structure for carousel
<div class="nyie-outer"> second row third row
fourth row fifth row sixth row seven throw eighth row
</div><!--/.second four rows here-->
sql code
CREATE TABLE product( php code
<?php how can i echo that result in those rows
Hi All, I have a table (with an ID of example) that can be seen he http://tinyurl.com/cfla7wp The following script calls jeditable.js and makes the Telephone & Mobile columns editable. Once edited, the table shows the new value plus a * symbol. Code: [Select] <script type="text/javascript"> $(document).ready(function() { /* Init DataTables */ var oTable = $('#example').dataTable(); /* Apply the jEditable handlers to the table */ $('td:eq(4), td:eq(5)', oTable.fnGetNodes()).editable( 'update_table_tenants.php', { "callback": function( sValue, y ) { var aPos = oTable.fnGetPosition( this ); oTable.fnUpdate( sValue, aPos[0], aPos[1] ); }, "submitdata": function ( value, settings ) { return { "row_id": this.parentNode.getAttribute("1"), "column": oTable.fnGetPosition( this )[2] }; }, "height": "14px" } ); } ); </script> What I need to do however is add the value entered into my database, but I do not know how to do this. I believe I need to do something like: UPDATE my_table VALUE whatever column has been edited in the table WHERE tenID is the same as the row selected in the table i.e. if I update the MOBILE NUMBER of the person called BILL GATES it would find his tenID, update numMobile in the table called my_table All help appreciated Dave Ok, I got someone to help me fix this but he had no idea what the error was... I have 2 tables, one called points and the other called members. In members i have got: id name In points i have got: id memberid promo I have the following code: Code: [Select] <?php $con = mysql_connect("localhost","slay2day_User","slay2day"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("slay2day_database",$con); $sqlquery="SELECT Sum(points.promo) AS score, members.name, members.id = points.memberid Order By members.name ASC"; $result=mysql_query($sqlquery,$con); while ($row = mysql_fetch_array($result)) { //get data $id = $row['id']; $name = $row['name']; $score = $row['score']; echo "<b>Name:</b> $name<br />"; echo "<b>Points: </b> $score<br />" ; echo "<b>Rank: </b>"; if ($name == 'Kcroto1'): echo 'The Awesome Leader'; else: if ($points >= '50'): echo 'General'; elseif ($points >= '20'): echo 'Captain!'; elseif ($points >= '10'): echo 'lieutenant'; elseif ($points >= '5'): echo 'Sergeant'; elseif ($points >= '2'): echo 'Corporal'; else: echo 'Recruit'; endif; endif; echo '<br /><br />'; } ?> I am getting the following error when i do the query in mysql: Code: [Select] #1109 - Unknown table 'points' in field list And when i open the webpage i get the following error: Code: [Select] Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/slay2day/public_html/points/members.php on line 18 Please Help me? im trying to write a script takes an xml files with tv show info, splits it into the show and the eppisode info and the place it into a table, i have got it to proccess all the info and print it out on a web page, but i cant, for the life of me, get it to insert said data into the table, it seems to be just ignoring the code and prints out the data as if nothing happens, no errors or anything. here is my code (abit messy but im only just starting and its my test.php) Code: [Select] <?php $tvdb_mirror = "http://www.thetvdb.com/api/"; $tvdb_time = "http://www.thetvdb.com/api/Updates.php?type=none"; $dbname = "mediadb"; $dbuser = "root"; $dbpass = ""; $dbserv = "127.0.0.1"; $rss = simplexml_load_file('sample.xml'); $showName = "Show Name = ".$rss->Series->SeriesName; print $showName; print "<br />Show Discription = ".$rss->Series->Overview; print "<br />"; mysql_connect('127.0.0.1', 'root', ''); @mysql_select_db('mediadb') or die("Unable to select database"); foreach ($rss->Episode as $item) { $seasonnum = $item->Combined_season; $EpisodeNumber = $item->EpisodeNumber; if($EpisodeNumber < 10){ $EpisodeNumber = "0".$EpisodeNumber; }; $EpisodeName = $item->EpisodeName; $Overview = $item->Overview; $airdate = $item->FirstAired; $tvdbid = $item ->id; $query = "INSERT INTO eppisodes VALUES('', '1', ".$EpisodeName.", ".$Overview.", ".$airdate.", '1', ".$tvdbid.", '-1', ".$seasonnum.", ".$EpisodeNumber.")"; mysql_query($query); print "<br />".$showName." - ".$seasonnum."x".$EpisodeNumber." - ".$EpisodeName." Overview:<br />".$Overview; } mysql_close(); ?> i am a noob @ php and mysql, but i have doubke and triple checked the names of the db and table. here is an sql dump of my db Code: [Select] -- phpMyAdmin SQL Dump -- version 3.3.5 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: Nov 13, 2010 at 12:48 PM -- Server version: 5.1.49 -- PHP Version: 5.3.3 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `mediadb` -- -- -------------------------------------------------------- -- -- Table structure for table `eppisodes` -- CREATE TABLE IF NOT EXISTS `eppisodes` ( `id` int(11) NOT NULL AUTO_INCREMENT, `showID` int(11) NOT NULL, `eppname` varchar(255) NOT NULL, `eppdesc` longtext NOT NULL, `airdate` date NOT NULL, `format` int(11) NOT NULL, `tvdbid` varchar(20) NOT NULL, `dohave` tinyint(1) NOT NULL, `season` varchar(2) NOT NULL, `eppisode` varchar(3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -- Dumping data for table `eppisodes` -- -- -------------------------------------------------------- -- -- Table structure for table `shows` -- CREATE TABLE IF NOT EXISTS `shows` ( `id` int(100) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `description` longtext NOT NULL, `TVDBID` int(100) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `shows` -- INSERT INTO `shows` (`id`, `name`, `description`, `TVDBID`) VALUES (1, 'higogo', 'some info', 67546); any help would be very much appericiated. fyi im running win7 with easyPHP 5.3.3 with php 5.3.3, mysql 5.1.49 apache 2.2.16 this is my sql code Code: [Select] <?php $query = "SELECT Player, SUM(GLI) AS 'gli', SUM(Goals) AS 'goals', SUM(Saves) AS 'saves', SUM(SOG) AS 'sog', SUM(Assists) AS'assists', SUM(CK) AS 'ck', SUM(YC) AS 'yc', SUM(RC) AS 'rc' FROM pinkpanther_stats GROUP BY Player; "; ?> their are 11 separate players and i want to set variables $adam_glie and $tyler_glie equal to the glie column for that player(the player being the first part of the variable) and i dont have any idea how to go about doing this Code: [Select] mysql_query("SELECT $field FROM iNettuts WHERE user_id='1'") or die (mysql_error()); And I have a table named iNettuts.... in my database, my db is called "forum" But I get the error... Code: [Select] Table 'forum.iNettuts' doesn't exist Makes no sense? This works on localhost, but when I transfer to a life server on my VPS, it seems to bring this error. any idea? ty Good morning: This is the output of my test database table: 2011-05-30 Chevrolet Monte Carol 1975 9000 15000 James Bond's 007-1212 james@bond.com B I am setting the rocord for bond's most active movies. 2011-05-31 Dodge Stratus 2008 5000 7500 James Cagney 555-1818 jc@hollywood.com S This is not going to be the best of time's. Ain't it? Within my table I have two important fields--the record date-created field shown on the left and the (hidden) EXPIRED field--on which the UPDATE function depends. This is my code for (wherein lies the problem) UPDATING the record within my table and setting the EXPIRED field to 'Y' for filtering and easy deletion of the record(s). Code: [Select] <?php // Connect to database. include("connect.php"); // Access the database @mysql_select_db($database,$con) or die( "Unable to select database"); $result = mysql_query("SELECT * FROM Autos"); //read all records into array while($row = mysql_fetch_array($result)) //loop through array { if (1 - strcmp(date("Y-m-d"),$row['DateCreated']) == 0) //compare current date with record date and act when result is zero { mysql_query("UPDATE Autos SET Expired = 'Y' WHERE Expired == 'N'"); //if ready to expire then update table EXPIRED field } else { if ($row['BuyerSeller'] == 'B') { echo "Contact buyer below"; } elseif ($row['BuyerSeller'] == 'S') { echo "Contact seller below"; } echo "<br />"; echo $row['DateCreated'] . " " . $row['Make'] . " " . $row['Model'] . " " . $row['Year'] . " " . $row['MinPrice'] . " " . $row['MaxPrice'] . " " . $row['POC'] . " " . $row['POCPhone'] . " " . $row['POCEmail'] . " " . $row['Notes']; echo "<br />"; } } mysql_close($con) ?> Lastly, does the mysql_close function with the single parameter $con also close the database? MOD EDIT: code tags added. For the last few days I have been trying to work out why my code does not update the MySQL database table. Having tried several variation I have the below but cannot see anything wrong. The rest of the program produces the correct results (displaying what is currently on the table) showing it is connecting to the correct table but altering the table is not working. Any help greatly appreciated. The few lines in question a Code: [Select] // Update the profile data in the database if (!$error) { if (!empty($name)&& !empty($phone) && !empty($address1) && !empty($address2)) { // Only set the picture column if there is a new picture if (!empty($new_picture)) { //if (!empty($postcode)){ $query = "UPDATE antique SET name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', picture = '$new_picture', username = '" . $_SESSION['username'] . "' WHERE name = '" . $row['name'] ."'"; }} else { $query = "UPDATE antique SET name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', username = '" . $_SESSION['username'] . "' WHERE name = '" . $row['name'] ."'"; } mysqli_query($dbc, $query) or die("<br>Query $query<br>Failed with error: " . mysqli_error($dbc) . '<br>On line: ' . __LINE__); The whole program is below Code: [Select] <?php error_reporting(E_ALL); session_start(); ?> <?php require_once('appvars.php'); require_once('connectvars1.php'); // Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); if (!isset($_GET['user_id'])) { $query = "SELECT * FROM antique WHERE user_id = '" . $_SESSION['user_id'] . "'"; } else { $query = "SELECT * FROM antique WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo '<table>'; if (!empty($row['name'])) { echo '<tr><td class="label">Name:</td><td>' . $row['name'] . '</td></tr>'; } if (!empty($row['phone'])) { echo '<tr><td class="label">Phone:</td><td>' . $row['phone'] . ' </td></tr>'; } if (!empty($row['address1'])) { echo '<tr><td class="label">Address1:</td><td>' . $row['address1'] . ' </td></tr>'; } if (!empty($row['address2'])) { echo '<tr><td class="label">Address2:</td><td>' . $row['address2'] . ' </td></tr>'; } if (!empty($row['postcode'])) { echo '<tr><td class="label">Postcode:</td><td>' . $row['postcode'] . ' </td></tr>'; } if (!empty($row['webadd'])) { echo '<tr><td class="label">Web address:</td><td>' . $row['webadd'] . ' </td></tr>'; } if (!empty($row['email'])) { echo '<tr><td class="label">Email:</td><td>' . $row['email'] . ' </td></tr>'; } if (!empty($row['username'])) { echo '<tr><td class="label">Username:</td><td>' . $row['username'] . ' </td></tr>'; } if (!empty($row['user_id'])) { echo '<tr><td class="label">User ID:</td><td>' . $row['user_id'] . ' </td></tr>'; } echo '</table>'; //echo '<class = "label">USER ID: ' . $_SESSION['user_id'] . ''; if (!isset($_GET['postcode']) || ($_SESSION['postcode'] == $_GET['postcode'])) { echo '<p>Would you like to <a href="index5.php">Go to Homepage</a>?</p>'; } } // End of check for a single row of user results else { echo '<p class="error">There was a bit of a problem accessing your profile.</p>'; } ?> <hr> <?php require_once('appvars.php'); require_once('connectvars1.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<p class="login">Please <a href="login1.php">log in</a> to access this page.</p>'; exit(); } // Connect to the database $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name); if (isset($_POST['submit'])) { // Grab the profile data from the POST $name = mysqli_real_escape_string($dbc, trim($_POST['name'])); $phone = mysqli_real_escape_string($dbc, trim($_POST['phone'])); $address1 = mysqli_real_escape_string($dbc, trim($_POST['address1'])); $address2 = mysqli_real_escape_string($dbc, trim($_POST['address2'])); $postcode = mysqli_real_escape_string($dbc, trim($_POST['postcode'])); $webadd = mysqli_real_escape_string($dbc, trim($_POST['webadd'])); $email = mysqli_real_escape_string($dbc, trim($_POST['email'])); $old_picture = mysqli_real_escape_string($dbc, trim($_POST['old_picture'])); $new_picture = mysqli_real_escape_string($dbc, trim($_FILES['new_picture']['name'])); $new_picture_type = $_FILES['new_picture']['type']; $new_picture_size = $_FILES['new_picture']['size']; $username = mysqli_real_escape_string($dbc, trim($_POST['username'])); $user_id = mysqli_real_escape_string($dbc, trim($_POST['user_id'])); if (!empty($_FILES['new_picture']['tmp_name'])) {list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']); } //list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']); $error = false; // Validate and move the uploaded picture file, if necessary if (!empty($new_picture)) { if ((($new_picture_type == 'image/gif') || ($new_picture_type == 'image/jpeg') || ($new_picture_type == 'image/pjpeg') || ($new_picture_type == 'image/png')) && ($new_picture_size > 0) && ($new_picture_size <= MM_MAXFILESIZE) && ($new_picture_width <= MM_MAXIMGWIDTH) && ($new_picture_height <= MM_MAXIMGHEIGHT)) { if ($_FILES['new_picture']['error'] == 0) { // Move the file to the target upload folder $target = MM_UPLOADPATH . basename($new_picture); if (move_uploaded_file($_FILES['new_picture']['tmp_name'], $target)) { // The new picture file move was successful, now make sure any old picture is deleted if (!empty($old_picture) && ($old_picture != $new_picture)) { } } else { // The new picture file move failed, so delete the temporary file and set the error flag @unlink($_FILES['new_picture']['tmp_name']); $error = true; echo '<p class="error">Sorry, there was a problem uploading your picture.</p>'; } } } else { // The new picture file is not valid, so delete the temporary file and set the error flag @unlink($_FILES['new_picture']['tmp_name']); $error = true; echo '<p class="error">Your picture must be a GIF, JPEG, or PNG image file no greater than ' . (MM_MAXFILESIZE / 1024) . ' KB and ' . MM_MAXIMGWIDTH . 'x' . MM_MAXIMGHEIGHT . ' pixels in size.</p>'; } } $error = false; // Update the profile data in the database if (!$error) { if (!empty($name)&& !empty($phone) && !empty($address1) && !empty($address2)) { // Only set the picture column if there is a new picture if (!empty($new_picture)) { //if (!empty($postcode)){ $query = "UPDATE antique SET name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', picture = '$new_picture', username = '" . $_SESSION['username'] . "' WHERE name = '" . $row['name'] ."'"; }} else { $query = "UPDATE antique SET name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', username = '" . $_SESSION['username'] . "' WHERE name = '" . $row['name'] ."'"; } mysqli_query($dbc, $query) or die("<br>Query $query<br>Failed with error: " . mysqli_error($dbc) . '<br>On line: ' . __LINE__); // Confirm success with the user echo '<p>Your profile has been successfully updated. Would you like to <a href="viewprofile4.php">view your profile</a>?</p>'; mysqli_close($dbc); exit(); } else { echo '<p class="error">You must enter all of the profile data (the picture is optional).</p>'; } } // End of check for form submission else { // Grab the profile data from the database $query="SELECT * FROM antique WHERE user_id= '" . $row['user_id'] . "'"; $data = mysqli_query($dbc, $query); $row = mysqli_fetch_array($data); if ($row != NULL) { $name = $row['name']; $phone = $row['phone']; $address1 = $row['address1']; $address2 = $row['address2']; $postcode = $row['postcode']; $email = $row['email']; $webadd = $row['webadd']; $old_picture = $row['picture']; $username = $_SESSION['username']; $user_id = $row['user_id']; } else { echo '<p class="error">There was a problem accessing your profile.</p>'; } } mysqli_close($dbc); ?> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MM_MAXFILESIZE; ?>" /> <fieldset> <legend>Personal Information</legend> <label for="name">Name:</label> <input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br /> <label for="phone">Phone:</label> <input type="text" id="phone" name="phone" value="<?php if (!empty($phone)) echo $phone; ?>" /><br /> <label for="address1">Address1:</label> <input type="text" id="address1" name="address1" value="<?php if (!empty($address1)) echo $address1; ?>" /><br /> <label for="address2">Address2:</label> <input type="text" id="address2" name="address2" value="<?php if (!empty($address2)) echo $address2; ?>" /><br /> <label for="postcode">Postcode:</label> <input type="text" id="postcode" name="postcode" value="<?php if (!empty($postcode)) echo $postcode; ?>" /><br /> <label for="email">Email:</label> <input type="text" id="email" name="email" value="<?php if (!empty($email)) { echo $email; } else { echo 'No email entered';} ?>" /><br /> <label for="webadd">Web address:</label> <input type="text" id="webadd" name="webadd" value="<?php if (!empty($webadd)) { echo $webadd; } else { echo 'No web address entered';} ?>" /><br /> <input type="hidden" name="old_picture" value="<?php if (!empty($old_picture)) echo $old_picture; ?>" /> <label for="new_picture">Pictu </label> <input type="file" id="new_picture" name="new_picture" /> <?php if (!empty($old_picture)) { echo '<img class="profile" src="' . MM_UPLOADPATH . $old_picture . '" alt="Profile Picture" style: height=100px;" />'; } ?> <br /> <label for="username">Username:</label> <input type="text" id="username" name="username" value="<?php if (!empty($username)) echo $username; ?>" /><br /> <label for="user_id">User ID:</label> <input type="text" id="user_id" name="user_id" value="<?php echo '' . $row['user_id'] . '' ; ?>" /><br /> </fieldset> <input type="submit" value="Save Profile" name="submit" /> </form> <?php echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout3.php">Log out</a>.</p>'); echo '<class = "label">USER ID: ' . $row['user_id'] . ''; ?> <p><a href="index.php">Return to homepage</a></p> <?php require_once('footer.php'); ?> </body> </html> Hello forum. I'm new here, but I've been reading and finding useful things for a while now. I'm still new to PHP and I need a little help. I'm doing a school project and I have some things I want to do, but do not know how to write it down in PHP. I think I'll ask a lot of questions this week, and I hope I will get some help.. For start I want to ask this: I've been using Code: [Select] mysql_fetch_array() for doing loops and populating check-boxes. And everything's working fine.. but what I want is to control the actual loop by clicking buttons. Let's say first time a while-do is run, my check-boxes get populated from the database and every other loop the next data from the table is added.. pretty straightforward. I want to be able to populate once, then click "next" and the new data to be added and so on.. Code: [Select] <?php $tema = mysql_query("SELECT * from questions")or die(mysql_error()); function answer1($string) { $string1 = explode("/", $string); echo $string1[0]; } function answer2($string) { $string1 = explode("/", $string); echo $string1[1]; } while ($row=mysql_fetch_array($tema)) { echo mysql_fetch_array($tema); $tip=$row["tip"]; if ($tip==2) { $id=$row['prasanje_id']; $question=$row['question']; $answer=$row['answer']; ?> <label> <?php echo $question?></label><br> <input type="checkbox" name="CheckboxGroup1" value="checkbox" id="CheckboxGroup1_0" /> <?php answer1($tekst) ?></label> <label> <input type="checkbox" name="CheckboxGroup1" value="checkbox" id="CheckboxGroup1_1" /> <?php answer2($tekst) ?></label> <?php } } ?>I want an alternative to the while-do loop.. Is it possible to do this? Thanks!! Hi everyone, wondering if any one could help me, probably simple to most. I am using an API from a video game and I am trying to insert the xml data I get back in to a MYSQL database table. but can't seem to figure it out. I created a simple echo foreach row which works, but I cannot seem to figure it out how to insert in to DB table. also the rows are attributes don't know if that makes a difference? Code: [Select] xml = simplexml_load_file('file.xml'); foreach ($xml->result->rowset->row as $row) { echo '<tr class="' . $row['ownerName2'] . '">' . '<td>' . $row['date'] . '</td>' . '<td>' . $row['ownerName1'] . '</td>' . '<td>' . $row['ownerName2'] . '</td>' . '<td>' . $row['amount'] . '<b>ISK</b>' . '</td>' . '<td>' . $row['balance'] . '<b>ISK</b></td>' . '<td>' . $row['reason'] . ' </td>' . '</tr>'; }; This is the structure of the xml document if you need to have a look. Code: [Select] <result> <rowset name="entries" key="refID" columns="date,refID,refTypeID,ownerName1,ownerID1,ownerName2,ownerID2,argName1,argID1,amount,balance,reason"> <row date="2011-09-16 14:19:00" refID="4873095949" refTypeID="37" ownerName1="name" ownerID1="435353535" ownerName2="name" ownerID2="2342523523" argName1="name" argID1="325235252" amount="-1101525.00" balance="0.00" reason="DESC:"/> <row date="2011-09-16 14:19:00" refID="4873095949" refTypeID="37" ownerName1="name" ownerID1="435353535" ownerName2="name" ownerID2="2342523523" argName1="name" argID1="325235252" amount="-1101525.00" balance="0.00" reason="DESC:"/> <row date="2011-09-16 14:19:00" refID="4873095949" refTypeID="37" ownerName1="name" ownerID1="435353535" ownerName2="name" ownerID2="2342523523" argName1="name" argID1="325235252" amount="-1101525.00" balance="0.00" reason="DESC:"/> </rowset> </result> Thanks in advance. Hi all. I'm working on a PHP application that will serve several clients. After a discussion on another thread about compliance, I've decided that using tables with a client specific prefix would be the safest way to go. However, I'm having a lot of trouble wrapping my head around what the database connection script would look like. I have a generic one that connects with host, user, pwd, and db as arguments but I'm not sure how to modify it to incorporate the table prefix requirement. Thoughts on how I can incorporate the aforementioned requirement and enhance the script in general? function connect_mysql($host,$user,$pass,$database){ $conn=mysql_connect($host,$user,$pass)or die('Cannot create link'); mysql_select_db($database)or die('Cannot select database'); }; Hi guys i have another question about my shopping cart.
I have in my sql database table called products. It consist of 4 columns (product_id, description, quantity, price).
Now on my index page, I want to call just one product from cell, which would have special price. But i don't know how to call one single product.
So my code looks like that:
<?php $sql="SELECT product_id FROM Products"; $query=mysql_query($sql); $row=mysql_fetch_array($query); ?><table > <tr><img src="Images/Image.jpg" width="380" height="300" /> </tr> <tr> <td><a href="index.php?page=index&action=add&id=<?php echo $row['product_id']?>">Add to cart</a></td> </tr> <?php ?> </table>This code display me first product but i would like to call 3 product how would i do that, so i have 6 products and i would like to call product N.3 to my index page. My code calls the first one, how would it call the third. |