PHP - Problem In Updating Data In To The Database +php
hi,
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Sahansevena_ver1\admin\profile\updAdmiInfo.php on line 49 i got this error. here is the coding Code: [Select] <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ $dbuser="root"; $dbpswd="****"; $dbserver="localhost"; $nwuser=$_POST['username']; $c_pw=$_POST['cur_password']; $n_pw=$_POST['conf_password']; //$user=$userName; //$pass=$password; // $dbname="sahansevena"; if($_SERVER['REQUEST_METHOD']=='POST'){ //get username and password from admin login.php $con=mysql_connect($dbserver,$dbuser,$dbpswd); if(!$con){ die('coudnt connect db connection prob'.mysql_error()); }else{ if($c_pw==$n_pw){ $uname=mysql_real_escape_string($username); $pword=mysql_real_escape_string($n_pw); // setDatabase($dbname, $con) ; mysql_select_db($dbname, $con); // $result="update admin set username='$uname',password='$pword'" where limit 0; $result="update admin set username='$uname' , password='$pword', last_logged_date =CURDATE(), last_log_time=CURTIME() where username='$uname' limit 0"; //Checked to see if any rows were returned from the database // If rows were returned, set a session variable to 1 $result=mysql_query($result); if ($result) { $numRow=mysql_numrows($result); if($numRow>0){ //session_start(); //SESSION['admin']="menuka"; echo "data was suaccesfully updated"; /// header ("Location:config/menu.php"); //mysql_close($con); }else{ //session_start(); echo " problem in updating "; //$_SESSION['login'] = ""; //header ("Location:login.php"); } } else { trigger_error(mysql_error(), E_USER_ERROR); } } } }else{ echo 'error message not post methode'; include(login.php); } ?> please check my code and help me to figur out the error thanks in advance, menukadevinda Similar TutorialsHi I making some forms that write to mysql database, Im now in the process of making the update form so the user can update there details on the form, I want it to populate the form with existing data but its not doing it at all. Thanks in advance
Attached Files
delete.php 210bytes
2 downloads
modify.php 4.03KB
4 downloads
index.php 473bytes
3 downloads 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.... Hello all. Please I need help to update customer table. I get the texboxes populated with select query no problem. I have html page with a search box and when the user enter their first name or last name and click search it will call up the search.php file here is the file: This code below populate the textboxes to be updated: Code: [Select] <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("^/[A-Za-z]+/", $_POST['name'])){ $name=$_POST['name']; } } else{ echo "<p>Please enter a search query</p>"; } } //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $name = $_POST['name']; $result = mysql_query ("select * from Customer_Registration where Firstname like '%$name%' or lastname like '%$name%' "); $row = mysql_fetch_row($result); $cf_uid = $row[0]; $Firstname = $row[6]; $lastname = $row[7]; $Address = $row[8]; $Postcode = $row[9]; $Phone = $row[10]; $Email = $row[11]; $Customer_Type = $row[12]; $Computer_type = $row[13]; $Computer_maker = $row[14]; $Model = $row[15]; $OS = $row[16]; $Appointment_date = $row[17]; $Problem = $row[18]; $Solution = $row[19]; $Comment = $row[20]; ?> <form action="updatecus1.php" method="post"> <table width="100%" border="2" cellspacing="0" cellpadding="8"> <tr><td width="45%" class="FormText">Customer ID:</td> <td width="55%"><?php echo $cf_uid;?></td></tr> <tr><td width="45%" class="FormText">First name:</td> <td width="55%"><input name="Firstname" type="text" value="<?php echo $Firstname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Last name:</td> <td width="55%"><input name="lastname" type="text" value="<?php echo $lastname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Address:</td> <td width="55%"><input name="Address" type="text" value="<?php echo $Address; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Postcode:</td> <td width="55%"><input name="Postcode" type="text" value="<?php echo $Postcode; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Phone:</td> <td width="55%"><input name="Phone" type="text" value="<?php echo $Phone; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Email:</td> <td width="55%"><input name="Email" type="text" value="<?php echo $Email; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Customer:</td> <td width="55%"><input name="Customer_type" type="text" value="<?php echo $Customer_Type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Computer :</td> <td width="55%"><input name="Computer_type" type="text" value="<?php echo $Computer_type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Manufactural:</td> <td width="55%"><input name="Computer_maker" type="text" value="<?php echo $Computer_maker; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Model:</td> <td width="55%"><input name="Model" type="text" value="<?php echo $Model; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Operating System:</td> <td width="55%"><input name="First name" type="text" value="<?php echo $OS; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Appointment:</td> <td width="55%"><input name="Operating System" type="text" value="<?php echo $Appointment_date; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Problem:</td> <td width="55%"><textarea name="Problem" rows="10" cols="20" ><?php echo $Problem; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Solution:</td> <td width="55%"><textarea name="Solution" rows="10" cols="20" ><?php echo $Solution; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Comment:</td> <td width="55%"><textarea name="Comment" rows="10" cols="20" ><?php echo $Comment; ?></textarea></td></tr> <td width="55%"><input name="submit" value="submit" type="submit" <br> <input type="Submit" value="Cancel"</br></td> </form> <?php -------------------------------------------------------------------------------------- The update.php file have the following code: Code: [Select] <?php //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); if (isset($_POST['submit'])) { $cf_uid = $_POST['cf_uid']; $Firstname = $_POST['Firstname']; $lastname = $_POST['lastname']; $Address = $_POST['Address']; $Postcode = $_POST['Postcode']; $Phone = $_POST['Phone']; $Email = $_POST['Email']; $Customer_Type = $_POST['Customer_Type']; $Computer_type = $_POST['Computer_type']; $Computer_maker = $_POST['Computer_maker']; $Model = $_POST['Model']; $OS = $_POST['OS']; $Appointment_date = $_POST['Appointment_date']; $Problem = $_POST['Problem']; $Solution = $_POST['Solution']; $Comment = $_POST['Comment']; $query = "UPDATE Customer SET Firstname='$Firstname',lastname='$lastname',Address='$Address',Postcode='$Postcode',Phone='$Phone',Email='$Email',Customer_Type='$Customer_Type',Computer_type='$Computer_type',Computer_maker='$Computer_maker',Model='$Model',OS='$OS', Appointment_date='$Appointment_date',Problem='$Problem',Solution='$Solution',Comment='$Comment' WHERE cf_uid='$cf_uid '"; mysql_query($query) or die(mysql_error()); mysql_close($con); echo "<p>Congrats Record Updated</p>"; } ?> I got congrats record updated but in actual fact no record are updated. Please help MOD EDIT: code tags added. Hey, I have written a script for a very simple PHP wall and comment system. This works fine but the problem I have is displaying the comments. It seems to display the comments associated with the post as well as the comments on the posts above it. I have checked the database and the post ID's are correct. Here is my code: Code: [Select] <?php $wallDisplay = ''; $commentDisplay = ''; $wallDisplaySql = mysql_query("SELECT * FROM wall WHERE to_id='$id' ORDER BY datetime DESC") or die (mysql_error()); while($row = mysql_fetch_array($wallDisplaySql)){ $wallPostId = $row["id"]; $to_id = $row["to_id"]; $from_id = $row["from_id"]; $message = $row["message"]; $dateTime = $row["datetime"]; $getFromData = mysql_query("SELECT username FROM members WHERE id='$from_id'") or die (mysql_error()); while($row2 = mysql_fetch_array($getFromData)){ $wallUsername = $row2['username']; } $displayComments = mysql_query("SELECT * FROM wallComments WHERE wallPostId='$wallPostId' ORDER BY datetime DESC"); while($row3 = mysql_fetch_array($displayComments)){ $wallComment = $row3['comment']; $commentFrom = $row3['from_id']; $commentDate = $row3['datetime']; $getUsername = mysql_query("SELECT username FROM members WHERE id='$commentFrom'"); while($row4 = mysql_fetch_array($getUsername)){ $commentUsername = $row4['username']; } $cheersCheck_pic = "members/$commentFrom/pic1.jpg"; $cheersDefault_pic = "members/0/defaultMemberPic.jpg"; if (file_exists($cheersCheck_pic)) { $cheers_pic = "<img src=\"$cheersCheck_pic?$cacheBuster\" width=\"40px\" />"; } else { $cheers_pic = "<img src=\"$cheersDefault_pic\" width=\"40px\" />"; } $commentDisplay .= '<table width="500px" align="right" cellpadding="4" bgcolor="#FFF"> <tr> <td width="10%" bgcolor="#FFFFFF"><a href="member_profile.php?id=' . $commentFrom . '">' . $cheers_pic . '</a><br /> </td> <td width="90%" bgcolor="#DBE4FD"><a href="member_profile.php?id=' . $commentFrom . '"><span class="blackText">' . $commentUsername . '</span></a> • <span class="blackTetx">' . $commentDate . '<br /><font size="1"></font></span><br /> <span class="blackText">' . $wallComment . '</span></td> </tr> </table>'; } $cheersCheck_pic = "members/$from_id/pic1.jpg"; $cheersDefault_pic = "members/0/defaultMemberPic.jpg"; if (file_exists($cheersCheck_pic)) { $cheers_pic = "<img src=\"$cheersCheck_pic?$cacheBuster\" width=\"40px\" />"; } else { $cheers_pic = "<img src=\"$cheersDefault_pic\" width=\"40px\" />"; } $wallDisplay .= '<table width="100%" align="center" cellpadding="4" bgcolor="#FFF"> <tr> <td width="7%" bgcolor="#FFFFFF"><a href="member_profile.php?id=' . $from_id . '">' . $cheers_pic . '</a><br /> </td> <td width="93%" bgcolor="#DBE4FD"><a href="member_profile.php?id=' . $from_id . '"><span class="blackText">' . $wallUsername . '</span></a> • <span class="blackTetx">' . $dateTime . '<br /><font size="1"></font></span><br /> <span class="blackText">' . $message . '</span></td> </tr> </table> <div id="commentList">' . $commentDisplay . '</div> <div id="comment" align="right"> <form id="comment" name="comment" method="post" action="member_profile.php?id=' .$id. '"> <textarea name="comment" id="comment" rows="1" cols="35"></textarea> <input type="hidden" name="wallPostId" id="wallPostId" value="'. $wallPostId .'" /> <input type="hidden" name="commentFrom" id="commentFrom" value="'. $_SESSION['id'] .'" /> <input type="submit" name="submitComment" id="submitComment" /> </form> </div><br /> '; } ?> I have been looking at it for ages but can think why this is happening. Thanks in advance for any help Hey guys im making a blog and when i make a post it automatically takes the date and created an archive based on what ever i have in the database (date wise) anyways it works almost fine but if i make a date in the same month it duplicates like so: October 2010 October 2010 November 2010 Is there away where i can limit October by 1 but when i come to make a post next year it will still display like so: October 2010 November 2010 December 2010 January 2011 ... October 2011 If i show you the code might make more sense haha:: public function create_archive() { // Loop through the database grabbing all the dates:: $sql = "SELECT blog_date FROM subarc_blog"; $stmt = $this->conn->prepare($sql); $stmt->execute(); $stmt->bind_result($date); $rows = array(); while($row = $stmt->fetch()) { $date = explode("-",$date); $month = date("F",mktime(0,0,0,$date['1'])); $year = $date[0]; $item = array( 'blog_month' => $month, 'blog_year' => $year ); $rows[] = $item; } $stmt->close(); return $rows; } and the sidebar looks like so:: <ul class="sidebar"> <?php $result = $Database->create_archive(); foreach($result as $row) : ?> <li><a href=""><?php echo $row['blog_month'] . " " . $row['blog_year']; ?></a></li> <?php endforeach; ?> </ul> Hope someone can help! I am new in PHP Programming , Please Help me. I have made a data table, then i have connected this table after that I have made a table in my index.php file . but i am facing problem to show data from data table in my index.php file, can you help me to solve this problem?
<?php include "db.php"; ?> <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <title>Post Global Variable</title> </head> <body> <div class="row p-5"> <table class="table table-dark"> <thead> <tr> <th scope="col">#</th> <th scope="col">Name</th> <th scope="col">User Name</th> <th scope="col">Email Address</th> <th scope="col">Password</th> <th scope="col">Phone</th> <th scope="col">Join Date</th> <th scope="col">Action</th> </tr> </thead> <tbody> <?php $myQuery = "SELECT * FROM users"; $allUsers = mysqli_query ($db, $myQuery); while ($row = mysqli_fetch_assoc($allUsers)){ $id= $row['id']; $name= $row['name']; $userName= $row['userName']; $email= $row['email']; $password= $row['password']; $phone= $row['phone']; $join_date= $row['join_date']; ?> <tr> <th scope="row"><?php echo $id; ?></th> <td><?php echo $name; ?></td> <td><?php echo $userName; ?></td> <td><?php echo $email; ?></td> <td><?php echo $password; ?></td> <td><?php echo $phone; ?></td> <td><?php echo $join_date; ?></td> <td><a class="btn btn-success btn-sm" href="#" role="button">Update</a> <a class="btn btn-danger btn-sm" href="#" role="button">Delete</a> </td> </tr> <?php } ?> </tbody> </table> </div> <!-- Optional JavaScript --> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> </body> </html> Edited March 3, 2020 by MH90 I can add and delete data from my table. Now I need to be able to change one or more fields in an entry. So I want to retrieve a row from the db, display that data on a form where the user can change any field and then pass the changed data to an update.php program. I know how to go from form to php. But how do I pass the data from retrieve.php to a form so it will display? Do I use a URL and Get? Can I put the retrieve and form in the same program? Hey guys, I've been doing a little bit of exerementing with PDO's and it seems I can't get it to update the database... I don't know why... Anyway here is the code: index.php Code: [Select] <?php /** * @author Jragon * @copyright 2011 */ require_once('includes/include.php'); $user = new user(); $user->newUser('Jragon', 'blenders', $DBH); echo '=D'; ?> /includes/connect.inc.php Code: [Select] <?php /** * @author Jragon * @copyright 2011 */ //Define connection details //host define('HOST', 'localhost'); //DataBase define('DB', 'rankometer'); //Username define('USER', 'root'); //Password define('PASS', ''); ?> /includes/connect.php Code: [Select] <?php /** * @author Jragon * @copyright 2011 */ //Include connection crap require_once('connect.inc.php'); //connect try { //new PDO $DBH = new PDO("mysql:host=" . HOST . ";dbname=" . DB, USER, PASS); //check for errors } catch(PDOException $e) { echo $e->getMessage(); } ?> /classes/user.class.php Code: [Select] <?php /** * @author Jragon * @copyright 2011 */ class user{ private $username; private $password; private $newPassword; private $salt; private $DBH; public function newUser($user, $pass, $DBH){ //name varibles $this->password = $pass; $this->username = $user; $this->DBH = $DBH; $this->getSalt(); $this->hashPass(); $this->createUser(); } private function getSalt(){ //pick random number $a = rand(1, 100); $b = rand(1, 100); $this->salt = rand($a, $b) * 5; } private function hashPass(){ //encrypt $this->password with md5 and a salt $plainPass = $this->password . $this->salt; $this->newPassword = md5($plainPass); } private function createUser(){ //prepare statement $STH = $this->DBH->prepare(" INSERT INTO `users` ( `user` , `pass` , `salt` ) VALUES ( '$this->username', '$this->newPassword', '$this->salt' ); "); //execute statement $STH->execute(); //prepare statement $STH = $this->DBH->prepare(" INSERT INTO `ranks` ( `rank` ) VALUES ( ); "); //execute statement $STH->execute(); } } ?> SQL dump Code: [Select] -- phpMyAdmin SQL Dump -- version 3.3.9 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Jun 02, 2011 at 06:05 PM -- Server version: 5.5.8 -- PHP Version: 5.3.5 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `cakes` -- -- -------------------------------------------------------- -- -- Table structure for table `cakes` -- CREATE TABLE IF NOT EXISTS `cakes` ( `UID` int(11) NOT NULL AUTO_INCREMENT, `cake` int(11) NOT NULL, PRIMARY KEY (`UID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -- Dumping data for table `cakes` -- -- -------------------------------------------------------- -- -- Table structure for table `users` -- CREATE TABLE IF NOT EXISTS `users` ( `UID` int(11) NOT NULL AUTO_INCREMENT, `userName` varchar(11) NOT NULL, `passWord` varchar(32) NOT NULL, `salt` int(11) NOT NULL, PRIMARY KEY (`UID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `users` -- I have no idea what is going wrong... I don't get an error. All the output I get is '=D'. Thanks -Jragon do you see anything wrong with this update code? i am having trouble setting the acntStatus=1. Code: [Select] <?php mysql_select_db($database_uploader, $uploader); $query = "SELECT * FROM members WHERE uname='$_SESSION[user]'"; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result) or die(mysql_error()); $usedSpace = $row['bandwhitch']; $acntType = $row['acntType']; if ($acntType == 1) { $totalSpace = 500; } else { $totalSpace = 250; } if($usedSpace > $totalSpace) { echo "There is something wrong with your account. Please contact us!"; $usageError = true; mysql_query(sprintf("UPDATE members SET acntStatus='%s' WHERE uname='%d'", mysql_real_escape_string(1), $_SESSION['user'])) or die(mysql_error()); mysql_close($con); } $usagePercent = (round(($usedSpace/$totalSpace), 2)) * 100; // Convert to percentage } ?> Hey all, I've recently been coding a Bank for my game in which users can desposit there money into. But while coding it I've came though a few errors in which I carn't seem to sort <?php session_start(); include_once ("includes/functions.php"); include ("includes/config.php"); require ("crewtop.php"); logincheck(); ini_set ('display_errors', 1); error_reporting (E_ALL); $username = $_SESSION['username']; $getuser = mysql_query("SELECT * FROM users WHERE username='$username'"); $user = mysql_fetch_object($getuser); $themembers = mysql_query("SELECT * FROM users WHERE crew = '$user->crew'"); $ammoutmembers = mysql_num_rows($themembers); $crew = mysql_query("SELECT * FROM crews WHERE name = '$user->crew'"); $crewstuff = mysql_fetch_object($crew); // Got everything needed.... if ($_POST['desposit']){ $desposit = strip_tags($_POST['desposit']); if ($desposit > $user->money){ // *** This Line *** echo ("You haven't got that much Money to Desposit!"); }elseif ($desposit <= $user->money){ if (ereg('[^0-9]',$desposit)){ echo ("Invalid Numbers Posted!"); }elseif(!ereg('[^0-9]',$desposit)){ mysql_query("UPDATE crews SET bank=bank+$desposit WHERE name='$user->crew'"); mysql_query("UPDATE users SET money=money-$desposit WHERE username='$username'"); echo ('You successfully Deposited £".number_format($desposit)."!'); } } } /* Deposit done - Now Withdraw... */ if ($_POST['withdraw']){ $withdraw = strip_tags($_POST['withdraw']); if ($withdraw > $crewstuff->bank){ // *** This Line *** echo ("You don't have that much Money in the Bank!"); }elseif ($withdraw <= $crewstuff->bank){ if (ereg('[^0-9]',$withdraw)){ echo "Invalid Numbers Posted!"; }elseif(!ereg('[^0-9]',$withdraw)){ $leftinbank = $crewstuff->bank - $withdraw; mysql_query("UPDATE crews SET bank=bank-$withdraw WHERE name='$user->crew'"); mysql_query("UPDATE users SET money=money+$withdraw WHERE username='$username'"); echo ('£".number_format($withdraw)." has been Withdraw from the Crew Bank!'); } } } // Withdraw done! ?> <html> <head> <title>Crew Bank || SD</title> <link rel="stylesheet" href="style.css" type="text/css"> </head> <body class='body'> <form action='' method='POST' name='crewbank'> <?php echo ("$username , $user->money"); ?> <?php if ($username != $crewstuff->boss || $username != $crewstuff->coowner || $username != $crewstuff->underboss || $username == $crewstuff->recruiter || $username == $crewstuff->recruiterone || $crewstuff->boss == $username || $crewstuff->coowner == $username || $crewstuff->underboss == $username){ ?> <table width='50%' cellpadding='0' cellspacing='0' border='1' class='table' colspan='2' align='center'> <tr> <td class='header' align='center' colspan='2'>Crew Bank</td> </tr> <tr> <td class='omg' colspan='2' align='center'>You Have <strong>£<?php echo "".number_format($crewstuff->bank).""; ?></strong> in the Crew Bank!</td> </tr> <tr> <td align='center' width='50%'>Deposit:</td><td align='center' width='50%'><input type='text' name='desposit' class='input' id='desposit'></td> </tr> <tr> <td align='center' colspan='2' align='center'><input type='submit' name='desposit' class='button' id='despositmoney' Value='Deposit!'></td> </tr> <?php } // Boss ?> </table> <br /> <?php if ($crewstuff->boss == $username || $crewstuff->coowner == $username || $crewstuff->underboss == $username){ ?> <table width='50%' cellpadding='0' cellspacing='0' border='1' class='table' colspan='2' align='center'> <tr> <td class='header' align='center' colspan='2'>Crew Bank - Withdraw</td> </tr> <tr> <td class='omg' align='center' colspan='2'>You carn't Withdraw more Money then there is in your Bank!</td> </tr> </tr> <tr> <td align='center' width='50%'>Withdraw:</td><td width='50%' align='center'><input type='text' name='withdraw' class='input' id='withdraw'></td> </tr> <tr> <td align='center' colspan='2' align='center'><input type='submit' name='withdraw' class='button' id='withdrawmoney' Value='Withdraw!'></td> </tr> </table> <?php } // Boss .. Underboss ?> </form> </body> </html> The two lines with the Comments on " // *** This Line *** " are the parts I've got a problem with. When a User is either despositing or Withdrawing there money it says there isn't enouth Money in the Bank, or that they don't have enouth Money, even when they have enouth. Anyone see why its saying the Error? Thanks in advance Hey i have this code that should update database on submit of a form. i have multiple rows selected from a database and i need to be able to update each row individually...however currently as the code stands it updates all rows with the data entered into the bottom row. i dont know how to solve this its very frustrating could someone take a look and help me? here is the code <?php session_start(); ?> <a href="adminlogout.php">Logout</a><br /> <?php $id = $_GET['id']; if(!isset($_SESSION['myusername'])) { header("location:adminlogin.php"); } $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $db = 'bank'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); if(isset($_POST['submit'])){ $select = mysql_query("SELECT * FROM accounts WHERE cusid=$id"); $row3 = mysql_fetch_array($select); $update = mysql_query("UPDATE accounts SET balance='".$_POST['balance']."', type='".$_POST['type']."', name='".$_POST['name']."', active='".$_POST['active']."' WHERE cusid=$id"); } $result = mysql_query("SELECT * FROM customer WHERE cusid=$id"); $row2 = mysql_fetch_array($result); echo $row2['name'] . "'s bank accounts" . "<br><br>"; $result2 = mysql_query("SELECT * FROM accounts WHERE cusid=$id"); echo "<form method='post' action='accounts.php?id=$id'>"; while($row = mysql_fetch_array($result2)) { echo "<input type='text' name='accno' style='background-color:lightgrey;' readonly='readonly' value='$row[accno]'>" . "<input type='text' name='name' value='$row[name]'>"; if($row['type'] == "Current"){echo"<select name='type'>" . "<option selected='Selected'>Current</option>" . "<option>Savings</option>" . "</select>";} else{echo"<select name='type'>" . "<option selected='Selected'>Savings</option>" . "<option>Current</option>" . "</select>";} echo"<input type='text' name='balance' value='$row[balance]'>"; if($row['active'] == "No"){ echo "<select name='active'>" . "<option value='No' selected='selected'>No</option>" . "<option value='Yes'>Yes</option>" . "</select>";} elseif($row['active'] == "Yes"){echo "<select name='active'>" . "<option value='Yes' selected='selected'>Yes</option>" . "<option value='No'>No</option>" . "</select>";} echo "<input type='submit' name='submit' value='Update'>" . "<br>"; } echo "</form>"; ?> so my database table already exists but i need to add new columns to the table so this is how the table looks now
CREATE TABLE IF NOT EXISTS `users` ( `id` int(255) NOT NULL AUTO_INCREMENT, `birthday` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1-1-1990', `comment_privacy` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'everyone', `confirm_followers` int(11) NOT NULL DEFAULT '0', `current_city` text COLLATE utf8_unicode_ci NOT NULL, `follow_privacy` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'everyone', `gender` varchar(6) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'male', `hometown` text COLLATE utf8_unicode_ci NOT NULL, `message_privacy` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'everyone', `post_privacy` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'everyone', `timeline_post_privacy` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'everyone', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;and this is what I need it to look.... but every time I insert in the sql to do the update but it does not do it as the table already there... CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL AUTO_INCREMENT NOT NULL, `job_title` mediumtext COLLATE utf8_unicode_ci NOT NULL, `job_at` mediumtext COLLATE utf8_unicode_ci NOT NULL, `birthday` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1-1-1990', `comment_privacy` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'everyone', `confirm_followers` int(11) NOT NULL DEFAULT '0', `current_city` text COLLATE utf8_unicode_ci NOT NULL, `relationship` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Not Applicable', `relationship_to` mediumtext COLLATE utf8_unicode_ci NOT NULL, `follow_privacy` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'everyone', `gender` varchar(6) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'male', `hometown` text COLLATE utf8_unicode_ci NOT NULL, `message_privacy` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'everyone', `post_privacy` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'everyone', `timeline_post_privacy` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'everyone', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;how can I do this update>? its ok i know how to do this.. but the code i sell needs this update but i cant get them to delete there table as there mybe data already in the table Hi I am trying my first OOP update. I have it working exactly as I want except for one thing. For some reason if I try to update the database with the same information (every column exactly the same) it returns 0 affected rows. is there anyway of getting the database to update, even if all columns are exactly the same? Code: Code: [Select] $membershipID = Profile_membership::find_membership_ID($UID); $MID = $membershipID->id; $new_member = Profile_membership::make($MID, $UID, $acc_type, $membership, $upgradeL, $date, $dateUpgraded); if($new_member && $new_member->save()){ $flag = 1; }else{ $message .= "Error: Sorry, there was an error creating your membership. <br> Please try again<br>"; $flag = 0; } $new_member->save() will create the database entry if no ID exists, and will update if an ID does exist. So, I want the save() to return success. If it does, move on else give an error. However, I'm getting the error, if a user accidentally clicks submit, when no fields have been changed. I what it to still update, so $flag will be 1 Thanks Hello, I have been staring at my screen for the last couple of days and have finally run out of solutions. I have the code below where the data is generated form another page. The correct data is displayed but for some reason when I try to alter any data it does not work. I simply get the message, "Your profile has been successfully updated..." but nothing has been changed in the database. I think the code is not connecting to the correct table in the database.. I fail to see why this would be. Any help greatly appreciated. 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) { $row = mysqli_fetch_array($data); } ?> <?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 = '$username' WHERE user_id = '" . $row['user_id'] ."'"; }} else { $query = "UPDATE antique SET name = '$name', phone = '$phone', address1 = '$address1', address2 = '$address2', postcode = '$postcode', " . " email = '$email', webadd = '$webadd', username = '$username' WHERE user_id = '" . $row['user_id'] ."'"; } 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 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="address2">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> why does this code not update database.....any errors you see off the bat? none of the messages are displaying for whether it posts or not......so I think there is something wrong with posting or a loop or something. Code: [Select] <?php session_start(); include "config2.php"; if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; ?> <?php //action: view users ----------------------------------------------------------------------------- if (isset($_GET['viewUsers'])) { //get all active users $query = "SELECT name, username, phone, address, city, state, zip, cell, email, accounttype, badges, password, rank, userid FROM members WHERE userid=userid"; $rs = mysql_query($query); ?> <table width="563" border='1'> <tr> <th width="54">Name</th><th width="84">Username</th><th width="47">Email</th> <th width="148">Access Level</th> <th width="105"> </th> <th width="85"> </th> </tr> <?php //show the users while ($row = mysql_fetch_assoc($rs)) { ?> <tr> <td><?php echo $row['name'];?></td> <td><?php echo $row['username'];?></td> <td><?php echo $row['email'];?></td> <td><?php echo $row['accounttype']?></td> <td> </td> <td><a href='admin.php?edit&id=<?php echo $row['userid'];?>'>Edit</a>, <a href='admin.php?delete&id=<?php echo $row['userid'];?>'>Delete</a></td> </tr> <?php } ?> </table> <?php } //action: edit user ----------------------------------------------------------------------------- if (isset($_GET['edit']) && isset($_GET['id'])) { $userid = (int) $_GET['id']; if ($userid == 0) { die("Invalid ID provided."); } //execution when completed the edit user form and pressed submit button --------------------- if (isset($_POST['editUser'])) { //validate data ------------------------------------------------------------------------ //check empty fields $notRequired = array("email","phone","address", "city", "state","zip","cell" ); //passwords won't be checked, as they are not required foreach ($_POST as $k=>$v) { if ($v == "" && !in_array($k,$notRequired)) { $error[$k] = "<strong>This field is empty</strong>"; } } //escape string $name = "mysql_real_escape_string{$_POST['fname']} {$_POST['last']}"; $phone = mysql_real_escape_string($_POST['phone']); $address = mysql_real_escape_string($_POST['address']); $city = mysql_real_escape_string($_POST['city']); $state = mysql_real_escape_string($_POST['state']); $zip = mysql_real_escape_string($_POST['zip']); $email = mysql_real_escape_string($_POST['email']); $cell = mysql_real_escape_string($_POST['cell']); $username = mysql_real_escape_string($_POST['username']); $last = mysql_real_escape_string($_POST['last']); $first = mysql_real_escape_string($_POST['fname']); //check email validation, the function is available at config.php //check username exists in database $res = mysql_query("SELECT username FROM members WHERE username='".$username."' AND username != '".$username."'"); if (mysql_num_rows($res) == 1) { $error['username'] .= " <strong>Username already existst in database!</strong>"; } //check both passwords are the same when password fields are not empty //end validate data --------------------------------------------------------------------- //save to database when no errors are detected ------------------------------------------ if (count($error) == 0) { $query = "UPDATE members SET username='$username', email='$email', name='".$name."', phone='".$phone."',address='".$address."', city='".$city."',state='".$state."', zip='".$zip."',cell='".$cell."',badges='".$badges."', rank='".$rank."', first='".$first."', last='".$last."' WHERE userid='".$_GET['userid']."'"; $query1 = "UPDATE sessions SET username='".$username."', email='".$email."',name='".$name."', phone='".$phone."',address='".$address."', city='".$city."',state='".$state."', zip='".$zip."',cell='".$cell."',badges='".$badges."', rank='".$rank."' WHERE id='".$userid."'"; //update username session if you edit yourself if ($userid == $_SESSION['auth_admin_userid']) { $_SESSION['auth_admin_username'] = $username; } if (mysql_query($query)|| mysql_query($query1)) { echo "<p><strong>User has been edited and saved to the database.</strong></p>"; } else { echo "<strong>User has NOT been edited and saved into the database. ".mysql_error()."</strong>"; } } } //get user from the database and put data into $_POST variables. $rs = mysql_query("SELECT first, last, username, phone, address, city, state, zip, cell, email, badges, rank, accounttype FROM members WHERE userid = ".$userid.""); if (mysql_num_rows($rs) == 0) { die("User does not exists!"); } $row = mysql_fetch_assoc($rs); $_POST['fname'] = $row['first']; $_POST['last'] = $row['last']; $_POST['username'] = $row['username']; $_POST['phone'] = $row['phone']; $_POST['address'] = $row['address']; $_POST['city'] = $row['city']; $_POST['state'] = $row['state']; $_POST['zip'] = $row['zip']; $_POST['cell'] = $row['cell']; $_POST['email'] = $row['email']; $_POST['badges'] = $row['badges']; $_POST['rank'] = $row['rank']; $_POST['accounttype'] = $row['accounttype']; //if is admin, then $_POST['admin'] exists ?> <form action="admin.php?edit&id=<?php echo $userid; ?>" method="post"> <div id="TabbedPanels1" class="TabbedPanels"> <ul class="TabbedPanelsTabGroup"> <li class="TabbedPanelsTab" tabindex="0">My Info</li> <li class="TabbedPanelsTab" tabindex="0">Merit Badges</li> <li class="TabbedPanelsTab" tabindex="0">Scout Rank</li> </ul> <div class="TabbedPanelsContentGroup"> <div class="TabbedPanelsContent"> <table align="center" cellpadding="8" cellspacing="8"> <tr> <td><div align="right">First Name:</div></td> <td> <input type="text" name="name" value='<?php echo $_POST['fname'];?>' /> <?php echo(isset($error['fname']))?$error['fname']:"";?></td> </tr> <tr> <td><div align="right">Last Name:</div></td> <td> <input type="text" name="name" value='<?php echo $_POST['last'];?>' /> <?php echo(isset($error['last']))?$error['last']:"";?></td> </tr> <tr> <td><div>Phone Number:</div></td> <td><input type="text" name="phone" value='<?php echo $_POST['phone'];?>' /> <?php echo(isset($error['phone']))?$error['phone']:"";?></td> </tr> <tr> <td><div align="right">Address:</div></td> <td><input type="text" name="address" value='<?php echo $_POST['address'];?>' /> <?php echo(isset($error['address']))?$error['address']:"";?></td> </tr> <tr> <td><div align="right">City:</div></td> <td><input type="text" name="city" value='<?php echo $_POST['city'];?>' /> <?php echo(isset($error['city']))?$error['city']:"";?></td> </tr> <tr> <td><div align="right">State:</div></td> <td><input type="text" name="state" value='<?php echo $_POST['state'];?>' /> <?php echo(isset($error['state']))?$error['state']:"";?></td> </tr> <tr> <td><div align="right">Zip Code:</div></td> <td><input type="text" name="zip" value='<?php echo $_POST['zip'];?>' /> <?php echo(isset($error['zip']))?$error['zip']:"";?></td> </tr> <tr> <td><div align="right">Email:</div></td> <td> <input type="text" name="email" value='<?php echo $_POST['email'];?>' /> <?php echo(isset($error['email']))?$error['email']:"";?></td> </tr> <tr> <td><div align="right">Cell Phone:</div></td> <td><input type="text" name="cell" value='<?php echo $_POST['cell'];?>' /> <?php echo(isset($error['cell']))?$error['cell']:"";?></td> </tr> <tr> <td class="aaaaaaa" align="right"><div>Username:</div></td> <td><label for="username"></label> <input type="text" name="username" value='<?php echo $_POST['username'];?>' /> <?php echo(isset($error['username']))?$error['username']:"";?> </td> </tr> <input name="userid" type="hidden" value="<?php echo $userid; ?>" /> </table> <p> </div> <div class="TabbedPanelsContent"> <label for="badges"></label> <input name="badges" type="text" id="badges" value='<?php echo $_POST['badges'];?>' /> <?php echo(isset($error['badges']))?$error['badges']:"";?> </div> <div class="TabbedPanelsContent"> <input name="rank" type="text" id="rank" value='<?php echo $_POST['rank'];?>' /> <?php echo(isset($error['rank']))?$error['rank']:"";?> </div> </div> </div> <input name="editUser" type="submit" value="Save" /> </form> <p> <script type="text/javascript"> var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1"); </script> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <?php } ?> <br /><br /> </div></div> <script type="text/javascript"> var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"}); </script> i have this small problem trying to update the database.... what i have is a members site in which they can view a variety of topics, however i want the user to be able to say delete a topic they are not interested in but still keep that topic open to other users who have not blocked it I'm tying to figure out how to do this, i initially had the following code: $update_db = mysql_query("UPDATE topics SET view='2' WHERE topicID='$topicID'") or die(mysql_error()); I had it set to to 2 meaning that all the topics that were set to 1 were visible to the user, only those they blocked were set to 2 and only be blocked to those users who blocked them not everyone The problem with that was that it blocked it to everyone Can anyone help me? Hi friends, the below code, which I've worked on quite a while, creates a dropdown, selects a record with a link to visit the url of that record. one ? can I update the table b4 closing? -------------------------------------------------- below is code: <?php include ('homedb-connect.php'); ?> <!DOCTYPE><html><head> <title>lookup menu</title> </head> <body><center><b> <form name="form" method="post" action="">
<?php //This creates the drop down box echo "<select name= 'target'>"; echo '<option value="">' . '--- Select account ---' . '</option>'; $query = mysqli_query($conn, "SELECT target FROM infotbl"); if ($query === false) { echo "Something went wrong<br />"; echo mysqli_error($conn); } else { while ($row = mysqli_fetch_array($query)) { echo "<option value='" . $row['target'] . "'>" . $row['target'] . '</option>'; } } echo '</select>'; ?> <input type="submit" name="submit" value="Submit"/> </form><center>
<?php // ============================================== if (isset($_REQUEST['target'])) { $target = $_REQUEST['target']; // =============================================== $fetch = "SELECT id, target, purpose, user, password, email, visits, lastused FROM infotbl WHERE target = '" . mysqli_real_escape_string($conn, $target) . "'"; // ===============================================================================
$result = mysqli_query($conn, $fetch); if (!$result) { echo "Error:" . (mysqli_error($conn)); }
//display the table echo '<table border="1"><tr><td bgcolor="cyan" align="center">lookup menu</td></tr> <tr><td> <table border="1"> <tr> <td>id</td> <td bgcolor="#ccffff"> Target </td> <td bgcolor="violet"> Purpose </td> <td bgcolor="#ccffff"> User </td> <td bgcolor="#ccffff">Password </td> <td bgcolor="#ccffff"> Email </td> <td bgcolor="#cyan"> Visits </td> <td bgcolor="#cyan"> lastused</td> </tr>';
while ($data = mysqli_fetch_row($result)) {
// ========================================================== $url = "http://$target"; $link = '<a href="' . $url . '">' . $data[0] . '</a>'; // ===========================================================
echo ("<tr><td> $link </td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td> <td>$data[4]</td><td>$data[5]</td><td>$data[6]</td><td>$data[7]</td></tr>"); } echo '</table> </td></tr></table>'; } ?> </body></html> ------------------------------------------------------ this is my update code: <?php $target = $_POST["target"]; $visits = 'visits'; $Lastused = 'Lastused'; $sql = "UPDATE receiptno SET visits=visits+1, lastused=NOW() WHERE target=$target"; if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn->error; } $conn->close(); ?> ok it updates the posts table , but not the notifications table , helP! Code: [Select] <?php include("../includes.php"); $session =$logOptions_id; if($session) { $id = $_POST['id']; if(!$id) { $id = $session; } $post = mysql_real_escape_string($_POST['post']); $date = mktime(); $action_type = 0; mysql_query("INSERT INTO posts SET to_id='$id',from_id='$session',post='$post',type='$action_type',date='$date'"); $post_id = mysql_insert_id(); $query = mysql_query("SELECT id,to_id,from_id,post,type,state,date FROM posts WHERE id='$post_id' AND state='0' ORDER BY id DESC LIMIT 15"); print posts($query, "newPost"); if($id!=$session) { mysql_query("INSERT INTO notifications SET user_id='$id', from_id='$session', post_id='$post_id', action_type='$action_type', date='$date'"); } } ?> Hi 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 |