PHP - Updating Mysql Database Table
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> Similar TutorialsHi All, Whenever I try to update any piece of PHP code to update a MySQL database, nothing happens. I have tried copying in some of the working codes of a website and tried the same, but no success. I recently installed XAMPP. I am connecting using the correct user id and pass to the database. The scripts are not giving me any error, but just not connecting, that's all. While making such a usage as noted below <FORM name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" > I get the following error Firefox can't find the file at /C:/xampp/htdocs/="<?php.. so on Why does this happen? I am pretty new to this, so please do help. Thanks, Satheesh P R I have the following code, (I'm sorry it's so long an it does more that the question asks.) It's ment to edit, delete and make new links in a mysql database, by also using a link header to home all the links (Like a dropdown menu) And thig manages the links. However then the update, or when the new form is submitted it leaves then titlereg field blank. (The titlereg is the id of the main link, it's called reg in the title_reg database) I know this is complicated and i'm not too good at explaining the problem but any help would be great. I have commented on anything that could help. <?php include "../includes/mysql_connect.php"; include "../includes/info_files.php"; echo "<strong>Links</strong><br />"; echo "Currect links:<br /><br />"; if($_POST['submit']){ $name = mysql_real_escape_string($_POST['name']); $titlereg = mysql_real_escape_string($_POST['titlereg']); $url = mysql_real_escape_string($_POST['url']); $id = mysql_real_escape_string($_POST['id']); mysql_query("UPDATE nav_sub SET name='$name', SET titlereg='$titlereg', SET url='$url' WHERE reg='$id'"); ////////////////////////////////// Here will help, the update MY SQL thingie echo "Link Changed.<br /><br />"; } elseif($_POST['remove']){ $id = mysql_real_escape_string($_POST['id']); mysql_query("DELETE FROM nav_sub WHERE reg='$id'"); echo "Link deleted.<br /><br />"; } else{ $result = mysql_query("SELECT * FROM nav_sub"); while($row = mysql_fetch_array($result)) { echo '<strong>' . $row['name'] . '</strong>'; echo '<form action="" method="post">'; echo 'Name: <input type="text" name="name" value="' . $row['name'] . '" /><br />'; echo 'Link: <input type="text" name="text" value="' . $row['url'] . '" /><br />'; echo 'Navigation title: <select name="titlereg">'; $resultabc = mysql_query("SELECT * FROM nav_title"); while($rowabc = mysql_fetch_array($resultabc)) { echo '<option value="' . $rowabc['reg'] . '">' . $rowabc['name'] . '</option>'; ////////////////////////////////// Here is the option } echo '</select>'; echo '<input type="hidden" name="id" value="' . $row['reg'] . '" />'; echo '<input type="submit" name="submit" value="Change" /> <input type="submit" name="remove" value="Remove" /><br />'; echo '</form>'; } } echo "New link:<br /><br />"; if($_POST['new_submit']){ ////////////////////////////////// Here!!!!!!!!!!!!!!! $result = mysql_query("SELECT * FROM nav_sub"); $new_titlereg = $_POST['new_titlereg']; $new_name = mysql_real_escape_string($_POST['new_name']); $new_url = mysql_real_escape_string($_POST['new_url']); mysql_query("INSERT INTO `nav_sub` (`titlereg` ,`reg` ,`name` ,`url`)VALUES ('$new_titlereg', '', '$new_name', '$new_url')"); ////////////////////////////////// here is the MY SQL statement... echo "Link added.<br /><br />"; } echo '<form action="" method="post">'; echo 'Name: <input type="text" name="new_name" value="" /><br />'; echo 'Url: <input type="text" name="new_url" value="" /> \\\\ If your linking to a page you made, then the url is index.php?catt=(The categrory you put)&page=(The page you put)<br />'; echo 'Navigation title: <select name="new_titlereg">'; $resultab = mysql_query("SELECT * FROM nav_title"); while($rowab = mysql_fetch_array($resultab)) { echo '<option value="' . $rowab['reg'] . '">' . $rowab['name'] . '</option>'; ////////////////////////////////// Here isn't submitting the value in the option } echo '</select>'; echo '<input type="submit" name="new_submit" value="Insert" /><br />'; echo '</form>'; ?> By the way, explain simply as I'm only 13 the below code as I understand should insert a new record into my database, but it's not. <?php $notes = $_POST['notes']; $cnamedb = $_POST['cname']; $username = $_SESSION['username']; mysql_query("INSERT INTO `ccccomma_eve`.`corps` (`id`, `name`, `ticker`, `alliance`, `ceo`, `tax`, `members`, `hq`, `apidate`, `notes`, `notedate`, `updatedby`) VALUES ('', '$cnamedb', '', '', '', '', '', '', '', '$notes', NOW(), '$username'"); echo $cnamedb." Updated"; ?> Any ideas why? Hi guys,
I have a problem with my code.
It connects with the database but it doesn't execute anything.
I am trying to update a value in a table but I really don't know what I am doing wrong.
I am trying to change the price based on the meta_value GF-1370
Thank you very much.
Here is Table (Taken from myphpadmin)
meta_id post_id meta_key meta_value
18538
4356
_sku
GF-1370
18541
4356
_price
2.343
and here is my code:
<?php $link = mysql_connect('server', 'username', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db(wordpress_i12dhflgoa); $sql="update `wp_pzvy_postmeta` set `_price` = 5 WHERE `_sku` = 'GF-1370'"; ?> Hi Forum I have this script below which i thought would update multiple rows in my database, but all it does is refresh and revert back to its original data. Im guessing my problem is in my update script but I cant seem to find where I have gone wrong. Any help would be greatly appreciated. <?php $host="*****"; $username="*****"; $password="*****"; $db_name="*****"; $tbl_name="*****"; // Connect to server and select databse. $db = new PDO('mysql:host=' . $host . ';dbname=' . $db_name, $username, $password); // If there is an update, process it. if (isset($_POST['submit'], $_POST['pageorder']) && is_array($_POST['pageorder'])) { $stmt = $db->prepare("UPDATE `$tbl_name` SET `pageorder`=:pageorder WHERE id=:id"); $stmt->bindParam(':id', $id, PDO::PARAM_INT); $stmt->bindParam(':pageorder', $pageorder, PDO::PARAM_STR); foreach ($_POST['pageorder'] as $id => $pageorder) { $stmt->execute(); } echo '<h1>Updated the records.</h1>'; } // Print the form. echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF']) . '" method="post">'; foreach ($db->query("SELECT `id`, `pageorder`, `pagetitle`, `linklabel` FROM `$tbl_name` ORDER BY `pageorder`") as $row) { echo '<input type="text" pageorder="pageorder[' . (int)$row['id'] . ']" value="'. htmlspecialchars($row['pageorder']) . '" />'; echo '<input type="text" pagetitle="pagetitle[' . (int)$row['id'] . ']" value="'. htmlspecialchars($row['pagetitle']) . '" />'; echo '<input type="text" linklabel="linklabel[' . (int)$row['id'] . ']" value="'. htmlspecialchars($row['linklabel']) . '" /><br />'; } echo '<input type="submit" name="submit" value="Update" /></form>'; ?> I used to be good at this but I changed servers and everything is different... Heres my code so far: Code: [Select] <?php $rated=$_REQUEST['rated']; echo $rated; $rating=$_REQUEST['rating']; echo $rating; // Make a MySQL Connection mysql_connect("localhost", "********", "********") or die(mysql_error()); mysql_select_db("*********") or die(mysql_error()); $result = mysql_query("SELECT * FROM main WHERE username = '$rated'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $votes = $db_field['$rating']; $newvotes = $votes + 1; echo $newvotes; mysql_query("UPDATE main SET $rating = '$newvotes' WHERE username = '$rated'"); ?> Whats going on here is the colomb that I want to update comes as a variable $rated (That works) and then the database selects the row to update with $username (That works) and gets the variable $newvotes by taking the original value of the data its about to update and add 1 to it (That works) Then it updates the field to $newvotes.... I don't know why the update won't go through... there are no errors.... Hi All, I've searched long and hard accross the web for an answer to this and finnally given in and requesting help. Here's what i have, i have a database setup and working fine. What i would like to do is for an administrator to be able to update my users details. It may sound odd, why don't you let your users update their own details? Well the administrators are dispatchers if you like, and my users are the 'dispatchees', for want of a better word. So i would like my administrators to be able to dispatch my users with routes and my users be able to see the routes that have been dispatched to them. I've setup a login area and a page that pulls there routes off the database, depending on their login details, i.e. jack will see his routes and jill will see her's independantly. This works by me editing the appropriate columns/rows of my database using phpmyadmin. What i'd like now is for administrators (who are directed to a seperate page, with more controls) to be able to do the same as me (updating the database) but by using a php form/script. I'd like to be able to select the routes from a second table on the same database if possible, to try and keep everything tidy. So my dispatcher would select Route001 from a drop down list, this would fill in the text fields next to the route field with From To, so my dispatcher would know what route001 actually is from/ too, choose a username (now being driven from my other table) and hit dispatch. My user would login to their area, hit view dispatched routes and it would display Route 001 with the correct information. The login area was a downloaded script i modified to suit and is called Login-Redirect_v1.31_FULL Many thanks in advance, hope you can sort of understand what i want Josh PHP/MySQL ability:Novice Hi guys I hope I am in the right place on this forum, if not I apologise. A have been working with CS-Cart and had so much trouble trying to update product combinations so I searched for help on the data feeds I am using and found that there was a script that would update my products for os-commerce, this has worked out even worse. All I really need is for a script to update one column called amount in a Mysql table by referring to the product_code column, Eg If product_code NS324 is= to 5 ad 5 to the amount column. This sounds simple but I think it might be complex. Here is the Table Generated b\: phpM\Admin 3.4.9 / M\SQL 5.5.20-log SQL quer\: SELECT * FROM `cscart_product_options_inventor\` LIMIT 0, 30 ; Rows: 30 Column1-----------Column2---------------Column3--------------Column4----------Column5-------Column6-------Column7 product_id-----product_code---------combination_hash-----combination-------amount----------temp-----------position --29813--------------NS3455----------- --1447985068-----------738_3059-----------0-----------------N-------------------0 So if I can update the amount column using the product_code would solve all of my problems. So this is what I need to do, I need to add an amount to the amount column related to the product_code NS3455 or update amount or even replace amount it don't matter. Due to the nature of the feeds I receive I cannot use product_id or combination_hash or combination. Please help me do this. Lets see who is the clever one. Thanks for you time Apologies... I'm a noob trying to reverse engineer code. I have a script that can retrieve values from a MySQL database (based on a session login that recognizes which user you are) and places those values into the text fields of a form, pre-populating the form. Code: [Select] <?php mysql_connect('localhost', 'db', 'password'); mysql_select_db('users'); $id = mysql_real_escape_string($_SESSION['userid']); $select = "SELECT * FROM user_info WHERE md5(Member_No) = '$id';"; $query = mysql_query($select); if ($row = mysql_fetch_array($query)) { ?> <form> FIRST name: <input type="text" name="First" value="<?php echo stripslashes($row['First']); ?>" LAST name: <input type="text" name="Last" value="<?php echo stripslashes($row['Last']); ?>" > Birthday: <input type="text" name="Birthday" value="<?php echo stripslashes($row['Birthday']); ?>" <input type="submit" value="Submit"> </form> <?php } ?> I want to be able to connect to that same database and update ALL the values (3 in the example above) with the single click of the form button. I think I was told some time ago that it's not possible to update all the values at once? Thanks, ~Wayne I have a user table that holds email addresses and for testing purposes I am trying to replace every email address with an email address defined in an array. I would like to randomly choose an email address from the array and update the table with this address. When I run the following code it randomly chooses a email address from the array but then updates every row with this one email address. Can you someone please let me know what I am doing wrong. Thanks in advance. Code: [Select] $query = "SELECT * FROM user '"; $result = mysql_query($query); $input = array('email1', 'email2', 'email3', 'email4', 'email5', 'email6', 'email7'); $rand_keys = array_rand($input, 2); $replaceStr = $input[$rand_keys[0]]; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $rand_keys = ""; $rand_keys = array_rand($input, 2); $replaceStr = $input[$rand_keys[0]]; mysql_query("UPDATE user SET email = '$replaceStr'"); } 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? Hi, here's my problem: I am trying to make a simple online buying website and I want to display a table with all the fields for each item. So I got that part down which is to just use mysql_fetch_assoc("SELECT * FROM myTable") and use the html table tags stuff, but now I want to display my images in the table, so here's my code to display my mysql database table in html's table tag along w/ php: <html> <head> <title>My Online buying website project</title> </head> <body> <?php mysql_connect("localhost","root"); mysql_select_db("myTable"); $imagesArray=array("Apple_iPhone3GS.jpg","Apple_iPhone4.jpg","product3.jpg","product4.jpg","product5.jpg"); $result=mysql_query("SELECT Name, Manufacturer, Price, Description, SimSupport FROM myTable"); if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table { print "<table border='border'>"; print "<tr> <th>Name</th> <th>Manufacturer</th> <th>Price</th> <th>Description</th> <th>SimSupport</th> </tr>"; //NB: now output each row of records while($row=mysql_fetch_assoc($result)) { extract($row); print "<tr> <td>$Name</td> <td>$Manufacturer</td> <td>$Price</td> <td>$Description</td><td>$SimSupport</td> </tr>"; }//END WHILE }//END IF ?> </table> </body> </html> *So how do I go about adding my images in this table? Hi friends i need a small help in importing csv files into mySQL database table i tried all possible options but i am no where... here is the example for what i am trying to do Mysql DB name = raw Table name is = dump +--------------------+--------------------+ + Account + Bal + +--------------------+--------------------+ + + + +--------------------+--------------------+ CSV Format 50************13, 11095 When they upload the file it should automatically get inserted into appropriate fields any help would be great i tried all possible scripts found in the net could nothing is happening Not really sure how to get the images I have stored in MySQL into a html form. I can call-up the text fields from the database but it cannot seem to find the index for the images. Here is my code:- <?php session_start(); mysql_connect("localhost","root","abc") or die ("Error! Cannot connect to database"); mysql_select_db("theimageworks") or die ("Cannot find database"); $query = "SELECT * FROM jobs"; $result = mysql_query($query) or die (mysql_error()); ?> <?php //display data in html table echo "<table>"; echo "<tr><td>Username</td><td align='center'>Message</td><td>Product Image</td></tr>"; while($row = mysql_fetch_array($result)) { echo "</td><td>"; echo $row['username']; echo "</td><td>"; echo $row['message']; echo "</td></tr>"; echo $row['image']; } echo "</table>"; ?> The error message I get is "Notice: Undefined index: image in....." Thanks in advance! well I know the standard way of retrieving mysql data was through the following codes: Code: [Select] $query = "SELECT * FROM {$tablename} WHERE columnmame = '{$var}'"; $result = mysql_query($query); $row = mysql_fetch_array($result); This will return all properties inside a table row by an associative array indexed by column names. I am, however, wondering if there is an easier way to retrieve database info from more than one table. For now, what I am doing is: Code: [Select] $result = mysql_query( "SELECT * FROM {$tablename} WHERE columnmame = '{$var}'"); $row = mysql_fetch_array($result); $result2 = mysql_query( "SELECT * FROM {$tablename2} WHERE columnmame2 = '{$var2}'"); $row2 = mysql_fetch_array($result2); which is a bit tedious and can cause problems when two or more coders work on the same project(it will be difficult to tell what is $row1, $row2 and $row3...). Is there away to write a simpler code than the one above? I mean, if it is possible to run mysql_fetch_array only once and retrieve database info from multiple tables? Hi, I'm a researcher (and complete coding noob), and am planning a longitudinal study that requires e-mail follow-up with subjects taking an initial survey. For purposes of ethics/anonymity due to sensitive survey data, I'd like the acquired e-mails to be saved uncoupled from the survey responses; this is simple to deal with, and I use a basic PHP e-mail form, which injects the email address in a table in MySQL in a different server than the one used for the survey. The issue is that the e-mails are saved in the MySQL database in order of injection, thus it is still theoretically possible for me to link the e-mails back to the survey responses (which have a time stamp that I cannot remove). Ideally I would like not to be able (at all) to link the e-mails to the survey responses, and one way to do that (since I don't save the e-mail injection timestamps in MySQL) might be to have the e-mails saved in MySQL in a random order. Not sure if this is possible, and not even sure if this would be via PHP or MySQL side of things. The server is on godaddy and uses Starfield interface for MySQL but I cannot find an option for random insert/saving of table items (emails). They are saved in order of injection. Any solution for this? Thanks, Hello I have an array with data from `mysql` that I would like to output it in a table using twig. The image is an example of want i want to achieve but without any luck. `print_r` of the array data Array ( [Administrator] => Array ( [0] => Array ( [RoleName] => Administrator [PermissionName] => Catalog-View [PermissionId] => 1 ) [1] => Array ( [RoleName] => Administrator [PermissionName] => Catalog-Edit [PermissionId] => 2 ) [2] => Array ( [RoleName] => Administrator [PermissionName] => Catalog-Delete [PermissionId] => 3 ) ) [Moderator] => Array ( [0] => Array ( [RoleName] => Moderator [PermissionName] => Catalog-View [PermissionId] => 1 ) ) ) The `HTML` code: <table> <tr> <thead> <th>Controller - Action</th> {% for permission in permissions %} {% for item in permission %} <th>{{item.RoleName}}</th> {% endfor %} {% endfor %} </thead> </tr> {% for permission in permissions %} {% for item in permission %} <tr> <td>{{item.PermissionName}}</td> <td>{{item.PermissionId}}</td> </tr> {% endfor %} {% endfor %} </table> OUTPUT: <table> <tbody> <tr></tr> </tbody> <thead> <tr> <th>Controller - Action</th> <th>Administrator</th> <th>Administrator</th> <th>Administrator</th> <th>Moderator</th> </tr> </thead> <tbody> <tr> <td>Catalog-View</td> <td>1</td> </tr> <tr> <td>Catalog-Edit</td> <td>2</td> </tr> <tr> <td>Catalog-Delete</td> <td>3</td> </tr> <tr> <td>Catalog-View</td> <td>1</td> </tr> </tbody> </table> Later Edit MySQL Query: SELECT t3.PermissionName, t1.PermissionId, t2.RoleName FROM tbl_user_role_perm AS t1 INNER JOIN tbl_user_roles AS t2 ON t1.RoleId = t2.RoleId INNER JOIN tbl_user_permissions AS t3 ON t1.PermissionId = t3.PermissionId MySQL Dump: -- Dumping structure for table tbl_user_permissions CREATE TABLE IF NOT EXISTS `tbl_user_permissions` ( `PermissionId` int(11) NOT NULL AUTO_INCREMENT, `PermissionName` varchar(50) NOT NULL, `PermissionDescription` varchar(100) NOT NULL, PRIMARY KEY (`PermissionId`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; -- Dumping data for table tbl_user_permissions: ~2 rows (approximately) DELETE FROM `tbl_user_permissions`; /*!40000 ALTER TABLE `tbl_user_permissions` DISABLE KEYS */; INSERT INTO `tbl_user_permissions` (`PermissionId`, `PermissionName`, `PermissionDescription`) VALUES (1, 'Catalog->View', 'View Catalog Method'), (2, 'Catalog->Edit', 'Edit Catalog Method'), (3, 'Catalog->Delete', 'Delete Catalog Method'); /*!40000 ALTER TABLE `tbl_user_permissions` ENABLE KEYS */; -- Dumping structure for table tbl_user_role CREATE TABLE IF NOT EXISTS `tbl_user_role` ( `UserRoleId` int(10) NOT NULL AUTO_INCREMENT, `UserId` int(10) NOT NULL, `RoleId` int(10) unsigned NOT NULL, PRIMARY KEY (`UserRoleId`), KEY `FK_tbl_user_role_tbl_user_roles` (`RoleId`), KEY `UserId` (`UserId`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; -- Dumping data for table tbl_user_role: ~2 rows (approximately) DELETE FROM `tbl_user_role`; /*!40000 ALTER TABLE `tbl_user_role` DISABLE KEYS */; INSERT INTO `tbl_user_role` (`UserRoleId`, `UserId`, `RoleId`) VALUES (1, 13, 22), (2, 14, 22); /*!40000 ALTER TABLE `tbl_user_role` ENABLE KEYS */; -- Dumping structure for table tbl_user_roles CREATE TABLE IF NOT EXISTS `tbl_user_roles` ( `RoleId` int(10) unsigned NOT NULL AUTO_INCREMENT, `RoleName` varchar(50) NOT NULL, `CreatedDate` datetime NOT NULL, `ModifiedDate` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`RoleId`) ) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8; -- Dumping data for table tbl_user_roles: ~7 rows (approximately) DELETE FROM `tbl_user_roles`; /*!40000 ALTER TABLE `tbl_user_roles` DISABLE KEYS */; INSERT INTO `tbl_user_roles` (`RoleId`, `RoleName`, `CreatedDate`, `ModifiedDate`) VALUES (22, 'Administrator', '2014-10-28 09:53:08', NULL), (23, 'Moderator', '2014-10-28 09:53:13', NULL), (24, 'Admin', '2014-10-28 12:22:05', '2014-10-28 12:22:06'), (25, 'User', '2014-10-29 15:10:36', '2014-10-29 15:10:37'), (26, 'SuperUser', '2014-10-29 15:10:45', '2014-10-29 15:10:46'), (27, 'Accountant', '2014-10-29 15:10:53', '2014-10-29 15:10:54'), (28, 'God', '2014-10-29 15:11:02', '2014-10-29 15:11:02'); /*!40000 ALTER TABLE `tbl_user_roles` ENABLE KEYS */; -- Dumping structure for table tbl_user_role_perm CREATE TABLE IF NOT EXISTS `tbl_user_role_perm` ( `RoleId` int(10) unsigned NOT NULL, `PermissionId` int(10) unsigned NOT NULL, KEY `RoleId` (`RoleId`), KEY `PermissionId` (`PermissionId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- Dumping data for table tbl_user_role_perm: ~3 rows (approximately) DELETE FROM `tbl_user_role_perm`; /*!40000 ALTER TABLE `tbl_user_role_perm` DISABLE KEYS */; INSERT INTO `tbl_user_role_perm` (`RoleId`, `PermissionId`) VALUES (22, 2), (22, 1), (23, 1), (22, 3); /*!40000 ALTER TABLE `tbl_user_role_perm` ENABLE KEYS */; /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;Can you help me to make the coding required so that the correct column have the correct permissions? thank you in advance. 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
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 |