PHP - Moved: Updating Query
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=334445.0 Similar Tutorialswhy is it not updating? <?php $_POST['email']; $_POST['submit']; if (isset($_POST['submit'])) { /*$sql =" UPDATE class_members SET email ='".$_POST['email']."', WHERE S_UID ='".$_POST['mem_id']."' ";*/ $result = mysql_query("UPDATE class_members SET email ='".$_POST['email']."', WHERE mem_id='".$_POST['mem_id']."'") or die(mysql_error()); } ?> Hi all, for my website ive got a fuel station which ive coded so users can fill up there there car fuel tanks, but the code all works part from one part of it. The code: The part of the code which isnt working: <?php $usermoney = $fetch->money; $costs2 = $fetch_fuelstation->price * $fueldiff; if ($costs2 > $usermoney){ echo "You dont have enouth money."; } elseif ($costs2 <= $usermoney){ $nmoney = $usermoney - $costs2; mysql_query("UPDATE users SET money='$nmoney' WHERE username='$username'") or die (mysql_error()); } ?> Ive got a varibal called $usermoney which selects the users current money from the database, but what im trying todo is take the fuel price away from there current money, but its not subtracting the money as it should. Anyone see why its not taking the money? Thanks. Hey Guys, Ive been searching for a while, but havent really come up with any answers. At the minute i have a page where i can add a new topic to a database, but i want to be able to update the query on another page if that makes sense So as an example say i have this below thats just been inserted into the database with an ID of 2. <?php // Details $id = $_POST['id']; $title = $_POST['title']; $detail = $_POST['detail']; mysql_connect("localhost", "web148", "123") or die(mysql_error()); mysql_select_db("web148") or die(mysql_error()); mysql_query("SET names 'utf8'"); mysql_query("INSERT into sunnyargues(ID, title, body) VALUES ('2', ''超级马里奥意大利再遭种族歧视', '当被问及在友谊赛上的不友好一幕会不会重演时,曼奇尼说,“有这种可能性。” “我当然不希望这样的事情发生,但是谁也不能保证。”'"); echo "<h1>Article Updated!</h1>"; ?> On the sunny argues page i currently have, where it only selects ID 1: <?php mysql_connect("localhost", "web148", "123") or die(mysql_error()); mysql_select_db("web148") or die(mysql_error()); mysql_query("SET names 'utf8'"); $result = mysql_query("SELECT body FROM sunnyargues WHERE ID='1'"); $row = mysql_fetch_array( $result ); echo nl2br($row['body']); ?> Is there a way i can update this query with the new ID of the 2nd article once its been inserted into the database. I hope that makes sense Hi there. I'm totally new (about a week!) with php and mysql and am encountering a problem that perhaps someone can help me with?
I've looked through to see if a similar problem has appeared or been solved, but without success, so apologies if I am repeating something.
In php I am trying to update 7 fields from a form from which a user has edited/modified any of the fields in a chosen record (except id).
Here is the code:
$id=$_GET['id']; I have a form that allows my client to update some products. Now the products are simple just basic info and 1 picture. I have set this up so they can edit the products and change the information, having done this many times in the past, but now hit a puzzling block that I am baffled. The client when editing is presented with the form with the information pulled from the database and the form fields loaded with that data ready to edit. The image can either be left alone or they can choose to upload a new image. They are shown the image they currently have stored in the database. The problem I have is EVEN if they decide not to upload an image and change other information, when the submit the form it must be sending a blank value for the image somewhere as it is updating the database and removing the image reference as if it has been removed. I have an if/else statement based on the form to perform 2 different queries for the update in mysql. Here is the code for the form update, as you can see the image should not update?? Please help?? if ($_SERVER['REQUEST_METHOD'] =='POST') { //This stops SQL Injection in POST vars foreach ($_POST as $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } // **************************** THIS IS FOR NO NEW IMAGE ******************************** if ($_SERVER['REQUEST_METHOD'] =='POST' && empty($_FILES['product_image']['name'])) { # setup SQL statement for no new image $SQL = " UPDATE products SET product_title = '{$_POST['product_title']}', product_description = '{$_POST['product_description']}', standard_price = '{$_POST['standard_price']}', deluxe_price = '{$_POST['deluxe_price']}' WHERE product_id = '{$_REQUEST['product_id']}' "; } // **************************** THIS IS FOR A NEW IMAGE ******************************** else { // Check the image type is a jpeg or gif for the image. if (($_FILES['product_image']['type'] != "image/gif") && ($_FILES['product_image']['type'] != "image/jpeg") && ($_FILES['product_image']['type'] != "image/pjpeg")) { echo "<FONT FACE=\"Verdana\"><SPAN CLASS=\"content\">You have chosen not to upload a <b>Product Image</b>.<BR></SPAN>" ; } elseif ($_FILES['product_image']['size'] > 100000) { echo "<FONT FACE=\"Verdana\"><SPAN CLASS=\"content\">The file size is bigger than 300kb.<BR></SPAN>" ; } else { move_uploaded_file($_FILES['product_image']['tmp_name'], "/httpdocs/product_images/".$_FILES['product_image']['name']) ; echo "<FONT FACE=\"Verdana\"><SPAN CLASS=\"content\"><B>Your front image has successfully uploaded.</B><BR></SPAN>" ; } } # setup SQL statement for update $SQL = " UPDATE products SET product_title = '{$_POST['product_title']}', product_description = '{$_POST['product_description']}', standard_price = '{$_POST['standard_price']}', deluxe_price = '{$_POST['deluxe_price']}', product_image = '{$_FILES['product_image']['name']}' WHERE product_id = '{$_REQUEST['product_id']}' "; } #execute SQL statement $result = mysql_db_query( *****,"$SQL",$connection ); # check for error if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } I have the following PHP script to update two time/date fields in the database. When i run this the fields are not updated. Can anyone see where i m going wrong. <?php $con = mysql_connect("localhost","dbname","dbpassword"); if (!$con) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db("my_db", $con); mysql_query("UPDATE msm_content SET created = '2011-01-02 00:00:00', modified = '2011-01-01 00:00:00'"); echo 'Query Updated successfully'; mysql_close($con); ?> Your guidance is much appreciated. Hello all, I'm relatively new to all of this, but making progress.... I figure this has come up before, but couldn't fin anything by search or browsing. I have an sql table that is cron updated every two minutes from externally generated data in table X columns a,b,c,... . As part of more complicated site, I have one body element page (selected by a tab in the header) that does various sql queries on the data in table X and displays the data. I need this to rerun the queries and update the displayed results every 2 minutes or so as well. However, the standard solutions do not seem to be working: <META HTTP-EQUIV="refresh" CONTENT="15"> A refresh button refreshes the entire site, and not just this element. <FORM> <INPUT TYPE="button" onClick="history.go(0)" VALUE="Force Flight Data Refresh"> </FORM> I hope it is clear. Any ideas of how I could get this to work? Thanks, Kalle Here is a snippet of the code on that page for what it's worth... </head> <body> <div id="header"> <center><h2><font color="red">TRAFFIC INFORMATION</font></h2> </div> <div id="navigation"> </div> <div id="content"> <!-- refresh button --> <FORM> <INPUT TYPE="button" onClick="history.go(0)" VALUE="Force Flight Data Refresh"> </FORM> </center> <?php $IDS->db_build($db); $IDS->db_query($db,$res,"SELECT * FROM `Pilots` WHERE `dest`='KORD'"); echo "<h5>Arrivals to O'Ha </h5>"; while ($arr_row = mysql_fetch_assoc($res)) { echo "<font color=yellow>".$arr_row['callsign']."</font> using route: ". $arr_row['route']."<br>"; } //end queries //close connect to sql database mysql_close($con) </div> <div id="footer"> </div> </body> </html> This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=326455.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351353.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=311010.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=329559.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=344191.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=347365.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321853.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353189.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319016.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=348956.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=353002.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=358137.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=306850.0 |