PHP - Having Trouble With Simple Update To Database
First time poster, and very amateur php coder. I am trying to delete items that in a list using ajax. I can't figure out what I am doing wrong. Any help would be greatly appreciated!
Here is a snippet of my javascript... $('.delete-item').click(function() { var itemID = $(this).data('itemID'); var clear = 1; $.ajax({ url: 'includes/delete-item.php', method: 'POST', data: { itemid:itemID, clear:1 }, success: function(data) { $('.content').load('includes/lists.php') } }) })
and here is the relevant php... $item = $_POST['itemid']; $clear = $_POST['clear']; $clearSQL = "DELETE FROM `List_Items` WHERE `item_ID` = $item"; $cleared = mysqli_query($connect, $clearSQL); Similar TutorialsHi i have this simple update form and scrip but somehow it doesnt seem to be update the field on the database can someone help out please. The html form is the second form bellow where the action send to status_update.php HTML FORM Code: [Select] <?php include("../header.html"); ?> <?php include("header_news.html"); extract($_REQUEST,EXTR_SKIP); ?><?php /* print("sfilm_refnum = $sfilm_refnum<BR>"); print("sfilm_addr01 = $sfilm_addr01<BR>"); print("sfilm_postcode = $sfilm_postcode<BR>"); print("Film Client = $fclient<BR>"); */ ?> <form id="search" action="list.php" method="post" name="search"> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#eeeeee"> <tr> <td align="right" width="140"></td> <td width="320"><span class="hofblack10"> </span> </td> <td align="center" width="100"><input type="hidden" name="lstart" value="<?php print("$lstart"); ?>" /><input type="hidden" name="lend" value="<?php print("$lend"); ?>" /><input type="hidden" name="lamount" value="<?php print("$lamount"); ?>" /></td> <td align="center" width="100"></td> <td align="right"></td> </tr> </table> </form> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#4050c4"> <tr> <td width="60" class="hofwhite10">action</td> <td width="140"><span class="hofwhite14">DATE</span></td> <td width="80"><span class="hofwhite14">ID</span></td> <td><span class="hofwhite14">News Titile</span></td> <td width="100"><span class="hofwhite14">Status</span></td> </tr> <tr height="0"> <td bgcolor="white" width="60"></td> <td bgcolor="white" width="140" height="0"></td> <td bgcolor="white" width="80" height="0"></td> <td bgcolor="white" height="0"></td> <td bgcolor="white" width="100" height="0"></td> </tr> </table><table width="780" border="0" cellspacing="0" cellpadding="4"><tr> <td width="60"></td> <td width="80"></td> <td><a class="blueullrg" href="add.php">Add News</a></td> <td align="right" width="120"></td> </tr> <tr height="0"> <td width="60" height="0"></td> <td width="80" height="0"></td> <td height="0"></td> <td align="right" width="120" height="0"></td> </tr> </table> <?php //get the DB connection variables include("../../../includes/config.php"); //connect to DB $connection = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select DATABASE."); $query2="SELECT * FROM news WHERE !(news_status='deleted')"; $result2 = mysql_query($query2) or die("Couldn't execute QUERY - Select NEWS Qty"); $fqty = mysql_num_rows($result2); //SELECT or FIND the same USERNAME $query3="SELECT * FROM news WHERE !(news_status='deleted') ORDER BY news_id DESC"; $result3 = mysql_query($query3) or die("Couldn't execute QUERY - Select NEWS"); while ($row = mysql_fetch_array($result3)) { $news_id = $row['news_id']; $news_title = $row['news_title']; $news_story = $row['news_story']; $news_image = $row['news_image']; $news_image_caption = $row['news_image_caption']; $news_image_link = $row['news_image_link']; $news_date_day = $row['news_date_day']; $news_date_month = $row['news_date_month']; $news_date_year = $row['news_date_year']; $news_status = $row['news_status']; $news_website = $row['news_website']; $news_date_created = $row['news_date_created']; $news_date_modified = $row['news_date_modified']; ?> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#eeeeee"> <tr> <td width="60"><span class="hofblack10"> <?php if($news_status=="deleted"){ print("<a class='hifblack10'>deleted</span>"); }ELSE{ print("<a class='blueul' href='edit.php?id=$news_id'>edit</a>"); } ?> </span></td> <td width="140"><span class="titlegrey12"> <?php if(!$news_date_day) { echo "00"; } else{ echo $news_date_day; } echo "/"; if(!$news_date_month) { echo "00"; }else{ echo $news_date_month; } echo "/"; if(!$news_date_year) { echo "0000"; }else{ echo $news_date_year; } ?> </span></td> <td width="80"><span class="titlegrey12"><?php print("$news_id"); ?></span> </td> <td><?php if($news_status=="deleted") { print("<class='hofblack10'>$news_title</span>"); }ELSE{ print("<a class='blueul' href='edit.php?id=$news_id'>$news_title</a>"); } ?></td> <td width="100"> <form id="list_update" action="status_update.php" method="post" name="list_update"> <select name="newnstatus" size="1"> <option <?php if($row['news_status'] == "") { print("selected"); } ?> selected="selected" value="">Status...</option> <option <?php if($row['news_status'] == "on") { print("selected"); } ?> value="on">On</option> <option <?php if($row['news_status'] == "off") { print("selected"); } ?> value="off">Off</option> <option <?php if($row['news_status'] == "deleted") { print("selected"); } ?> value="deleted">Delete</option> </select> <input type="hidden" name="nstatus" value="<?php echo $row[news_status]; ?>" /> <input type="hidden" name="id" value="<?php echo $row[news_id]; ?>" /> <input type="submit" name="update" value="update" /> </form> </td> </tr> <tr height="0"> <td bgcolor="white" width="60"></td> <td bgcolor="white" width="140" height="0"></td> <td bgcolor="white" width="80" height="0"></td> <td bgcolor="white" height="0"></td> <td bgcolor="white" width="100" height="0"></td> </tr> </table> <?php } mysql_close($connection);//}?> <table width="780" border="0" cellspacing="0" cellpadding="4"> <tr> <td width="60"></td> <td width="80"></td> <td><a class="blueullrg" href="add.php">Add News</a></td> <td align="right" width="120"></td> </tr> </table><?php // include("list_navigation.html"); ?> <?php include("../footer.html"); ?> </div></body></html> The action script php Code: [Select] <?php /* echo "fstatus: ".$fstatus."<BR>"; echo "id: ".$id."<BR>"; echo "fclient: ".$fclient."<BR>"; echo "newfstatus: ".$newfstatus."<BR>";*/ //set the date of agreement $timestamp = date('l jS \of F Y h:i:s A'); //get the DB connection variables include("../../../includes/config.php"); //connect to DB $connection = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select FILMS DATABASE."); // All appears well, so enter into database $query= "UPDATE news SET news_status = '$newnstatus' WHERE news_id='$id'"; $result = mysql_query($query) or die("could not execute query - Update FILMS Record to DB"); //setup an email to the Admin @ hof, w/o attachment $emailto="xx@xxx.co.uk"; $emailfrom="no-reply@xxxx.co.uk"; $emailsubject="xx Record Updated"; $emailmessage="Hello Registrar\n\n"; $emailmessage.="News ID: ".$id."\n"; $emailmessage.="Updated on: ".$timestamp."\n\n"; $emailmessage.="Status was: ".$nstatus."\n"; $emailmessage.="Status now: ".$newfnstatus."\n"; $emailmessage.="Thank you,\n\n"; $emailmessage.="Web Site ROBOT\n"; $emailmessage.="(Administrator)\n"; $emailmessage.="xxx.co.uk | xxx.biz\n"; $emailmessage.="----------------------------------------------\n"; $emailmessage.="e. http://www.xxx.co.uk/contact.php\n"; $emailmessage.="w. http://www.xxx.co.uk\n"; $emailheader="From: xxx.co.uk<$emailfrom>"; $emailheader .= 'Cc: xxx@xxx.co.uk'."\r\n"; $emailheader .= 'Bcc: xxx@xxxxx.co.uk'."\r\n"; $ok=mail($emailto,$emailsubject,$emailmessage,$emailheader); mysql_close($connection); if ($ok) { header("Location: list.php"); /* Redirect browser */ exit; } else { $errmsg="There was a problem, please try later or telephone us direct."; $errsta="1"; include("edit_error.html"); //echo "<p>Mail could not be sent. Sorry!</p>"; exit; } ?> Thanks in advance I am trying to do something that a hell of a lot of people must need to do every day, yet despite this I can not find a single example online, or in books, which makes absolutely no sense! Anyway, hopefully it will be blindingly obvious to someone what I'm doing wrong, I really hope so as I can't figure it out... I have a mysl table as follows: tblvenue venue_id PRIMARY KEY (int) venue_name (varchar 50) station_id (int) I have a php/html page as follows: <html> <head> <title>Update & Delete Venues</title> </head> <body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0" style="margin:0;padding:0" bgcolor="#B0E0E6"> <h1></h1> <form action="venue4.php" method="post"> <table border="1" style="border:solid black" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="center" width="33%">Action</td> <td align="center" width="33%">Venue Name</td> <td align="center" width="33%">Station Name</td> </tr> <?php $station_name=$_POST['station_name']; @ $db = new mysqli('XXX', 'XXX', 'XXX', 'XXX'); $query = "call sp_venue()"; $result = $db->query($query); $num_results = $result->num_rows; function db_result_to_array($result){ //--------------------------------------------------------------------- $res_array = array(); for ($count=0; $row = $result->fetch_assoc(); $count++) { $res_array[$count]=$row; } return $res_array; } //--------------------------------------------------------------------- function get_dataset($server, $user, $password, $database, $query7) { //--------------------------------------------------------------------- $db1 = new mysqli($server, $user, $password, $database); $query1 = $query7; $result1 = $db1->query($query1); $num_results = $result1->num_rows; $result8 = db_result_to_array($result1); return $result8;} //--------------------------------------------------------------------- echo "<tr>"; echo "<td>"; echo "<table width='100%'><td width='33%' align='center'><input type='submit' id='btnupdate' name='btnupdate' value='Update & Delete' ></td>"; echo "<td width='33%' align='center'><input type='submit' name='btncancel'id='btncancel' value='Cancel Updates' ></td>"; echo "<td width='33%' align='center'><input type='submit' value='Add New Venue' name='btnadd'></td></table>"; echo "</td>"; echo "<td><input type='text' name='tbvenue_name'/></td>"; echo "<td>"; ?> <select name="stat_id"> <?php $stat_array=get_dataset('XXX', 'XXX', 'XXX', 'XXX',"call sp_station"); foreach ($stat_array as $thisstat){ echo "<option value=\"".$thisstat['station_id']."\""; echo ">".$thisstat['station_name']."</option>"; } ?> </select> <?php echo "</td>"; echo "</tr>"; echo "<tr>"; while($row = $result->fetch_assoc()) { echo "<td width='33%'>Delete:<input type='Checkbox' id='cbdelete[]' name='cbdelete[]' value='".$row['venue_id']; echo "'>Update:<input type='Checkbox' id='value' name='cbupdate[]' value='".$row['venue_id']."'><input type='hidden' name='venue_id[]' value='".$row['venue_id']."'></td>"; echo "<td width='33%'><input type='Textbox' width='100%' name='venue_names' value='" .$row['venue_name']. "'></td>"; echo "<td width='33%'>" ; echo "<select name='station_id[]' width='100%'>"; $stat_array=get_dataset('localhost', 'root', 'snooker1', 'pool',"call sp_station"); foreach ($stat_array as $thiscat) { echo '<option value="' . $thiscat['station_id'] . '"'; if ($row['station_id'] == $thiscat['station_id']) {echo ' selected';} echo '>' . $thiscat['station_name'] . '</option>'; } echo "</td>"; echo "</tr>"; } echo "</table>"; ?> </form> </body> </html> This displays correctly and when checking the appropriate checkbox and clicking the script venue4.php is run: <?php //Connects to the database $db = new mysqli('XXX', 'XXX', 'XXX', 'XXX'); //Checks to see if the update button has been clicked if (isset($_POST['btnupdate'])) { //Assigns checkbox array to variable $aDel = $_POST['cbdelete']; $aVal = $_POST['cbupdate']; //Loops through rows to delete selected records foreach($_POST['cbdelete'] as $delete11) { //Deletes record $query = "delete from tblvenue where venue_id =".$delete11; $result = $db->query($query); $num_results = $result->num_rows; } //Loops through rows to delete selected records foreach($_POST['cbupdate'] as $update11) { //Gets variable //$Venue = $_POST['venue_names']; //Updates record $query = "update tblvenue set venue_name=".$venue." where venue_id =".$update11; $result = $db->query($query); $num_results = $result->num_rows; } //Checks to see if Add button was clicked } elseif (isset($_POST['btnadd'])) { //Looks for Venue Name & Station Name $tbvenue_name=$_POST['tbvenue_name']; $tbstat_id=$_POST['stat_id']; //Formats variables if(!get_magic_quotes_gpc()) { $tbvenue_name = addslashes($tbvenue_name); $tbstat_id = addslashes($tbstat_id); } //Inserts new record $query = "call sp_insert_venue('".$tbvenue_name."',".$tbstat_id.")"; $result = $db->query($query); } elseif (isset($_POST['btnedit'])) { switch($page) { default: include("venue2.php"); break; } } else { //If cancel button is clicked, goes straight to switch code below } //Closes database connection $db->close(); //Goes back to Venue page switch($page) { default: include("venue.php"); break; } echo var_dump($aval); print_r($aVal); //$test = $_POST['cbupdate']; ?> Deleting records works fine. Inserting records works fine. If I hard code the data (ie. set venue_name = 'blah blah blah') for updates, I can get the relevant row id from cbupdate and update the row in question. However I can not get the data from venue2.php (typed into a textbox on the row in question) and submit this to the database to be updated. This scenario must come up for zillions of developers, but so far no-one has been able to help. Please can anyone assist... I cant figure out why im having this problem. i stuck this at the top of my page on its own and it wont update the row to read Code: [Select] <?php mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> I echo $_GET['pm_id']; and that turn out correct and the number matches the pm_id on the row. everything is lowercase I typed read manually into the column and echo that and it showed read also I have this same exact line of code on another script that works fine. does someone see something im over looking? this is driving me crazy http://localhost/stargate/users/view.php?pm_id=1376672&inbox=2 Code: [Select] <?php require("menu.php"); ?> <html> <body> <?php mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> </body> </html> Hi guys, Sorry - this might more belong in the SQL section but I think it is PHP related. I am trying to update a table with: $sql="UPDATE $tbl_name SET (gender, description) VALUES ('$gender', '$description') WHERE image = ('$photoname')"; $result=mysql_query($sql); Needless to say, its not working. Only odd thing is that the $photoname variable is sent with a hidden field on the previous form. I can echo all 3 varaibles though and get the right results. I just dont know why it isnt updating - seems pretty standard to me. Can anyone help? Thanks! Hi, I am having trouble coding for mysqli update. Please, somebody tell me the correct way. I'm trying to update the "lastused" (current date) field in "emailtbl". Somebody please tell the best way to code this. Below is the message and following, the current code: Fatal error: Call to undefined function curdate() in C:\xampp\htdocs\home\lastused.php on line 14 $db = new mysqli('localhost', 'root', 'pass', 'mydb'); if($db->connect_errno > 0) {die('Unable to connect to database [' . $db->connect_error . ']');} $sql = <<<SQL SELECT * FROM `emailtbl` WHERE `id` = '$id' SQL; if(!$result = $db->query($sql)) {die('There was an error running the query [' . $db->error . ']');} $lastused = $_POST['lastused']; $lastused = curdate(); echo "last date accessed is ".$data['lastused']; $result->free(); $db->escape_string('This is an unescape "string"'); $db->close(); ?> $update= mysqli_query($dbconnect, "UPDATE emailtbl SET lastused = curdate() WHERE id ='$id'"); if($update == false) { die("UPDATE FAILED: ".mysqli_error($dbconnect)); } echo "$lastused is the last date this account was accessed"; Having update statement trouble... The error I'm getting is... "Could not query the database - : " Not sure what I'm missing, I had this working before also, but now it's not. Here is my code for the update page... Code: [Select] <html> <head> <title>Update User</title> </head> <body> <form method="post" action="update_user2.php"> <?php $dbc = mysqli_connect('localhost', 'se266_user', 'pwd', 'se266') or die(mysql_error()); //delete users echo '<b>Delete or Update User</b>.<br />'; if (isset($_POST['remove'])) { foreach($_POST['delete'] as $delete_id) { $query = "DELETE FROM users WHERE course_id = $delete_id"; mysqli_query($dbc, $query) or die ('can\'t delete user'); } echo 'user has been deleted.<br />'; } if (isset($_POST['update'])) { $course_id = $_POST['course_id']; $course_name = $_POST['course_name']; $student_id = $_POST['student_id']; $query = "UPDATE users SET course_name ='". $course_name ."' WHERE course_id = $course_id"; $updres = mysqli_query($query); if(!$updres) { die(" Could not query the database - : <br/>". mysqli_error() ); } else { echo 'course has been updated.<br />'; } } //display users info with checkbox to delete $query = "SELECT * FROM users"; $result = mysqli_query($dbc, $query); while($row = mysqli_fetch_array($result)) { echo '<input type="checkbox" value="' .$row['course_id'] . '" name="delete[]" />'; echo ' ' .$row['course_name'] .' '. $row['student_id']; echo '<br />'; } mysqli_close($dbc); ?> <form method="POST" action="update_user2.php"> <label for="course_id">Course ID:</label> <input type="text" id="course_id" name="course_id" /> <br /> <label for="course_name">Course Name:</label> <input type="text" id="course_name" name="course_name" /> <br /> <label for="course_name">Student ID:</label> <input type="text" id="student_id" name="student_id" /> <br /> <input type="submit" name="remove" value="Remove" /> <input type="submit" name="update" value="Update" /> <br><br> </form> </body> </html> Hello: I am trying to figure out how to do an UPDATE SET for a photo gallery based on the "photo_id" ... not working to well ... Currently, it just uploads a photo but updates everything. This is the code: Photo_Edit.php Code: [Select] <?php $photo_id = $_REQUEST['photo_id']; ?> ... <?php $query=mysql_query("SELECT * FROM gallery_photos WHERE photo_id = $photo_id") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $photo_id=$result['photo_id']; $photo_filename=$result['photo_filename']; $photo_caption=$result['photo_caption']; } ?> <form enctype="multipart/form-data" action="a_Photo_Upload2.php" method="post" name="upload_form"> <input type='hidden' name='photo_id' value='<?php echo $photo_id; ?>' /> <table width='600' border='0' id='tablepadding' align='center'> <tr> <td width='50'> Photo: <td width='550'> <input name='photo_filename[]' id='my_photo' type='file' /> <div style='clear: both;'></div> Current photo: <div style='clear: both;'></div> <img src="../gallery/tb_<?php echo $photo_filename; ?>" width="100px" class='imgCenter' /> <div style='clear: both;'></div> <a href="javascript:void(0);" onmouseover="tooltip.show('<img src=../gallery/tb_<?php echo $photo_filename; ?> width=500 />');" onmouseout="tooltip.hide();">Larger view</a> </td> </tr> <tr> <td> Description: </td> <td> <textarea name='photo_caption[]' cols='100' rows='10'><?php echo $photo_caption; ?></textarea> </td> </tr> <tr> <td> <input type='submit' name='submit' value='Edit Product' /> </td> </tr> </table> </form> Goes to this page, where I am having the problems: a_Photo_Upload2.php Code: [Select] <?php echo $photo_id; ?> <?php // initialization $result_final = ""; $counter = 0; // List of our known photo types $known_photo_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/bmp' => 'bmp', 'image/x-png' => 'png' ); // GD Function List $gd_function_suffix = array( 'image/pjpeg' => 'JPEG', 'image/jpeg' => 'JPEG', 'image/gif' => 'GIF', 'image/bmp' => 'WBMP', 'image/x-png' => 'PNG' ); // Fetch the photo array sent by preupload.php $photos_uploaded = $_FILES['photo_filename']; // Fetch the photo caption array $photo_caption = $_POST['photo_caption']; while( $counter <= count($photos_uploaded) ) { if($photos_uploaded['size'][$counter] > 0) { if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types)) { $result_final .= "File ".($counter+1)." is not a photo<br />"; } else { $new_id = mysql_insert_id(); $filetype = $photos_uploaded['type'][$counter]; $extention = $known_photo_types[$filetype]; $filename = $new_id.".".$extention; mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" ); // Store the orignal file copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename); // Let's get the Thumbnail size $size = GetImageSize( $images_dir."/".$filename ); if($size[0] > $size[1]) //{ //$thumbnail_width = 100; //$thumbnail_height = (int)(100 * $size[1] / $size[0]); //} //else //{ //$thumbnail_width = (int)(100 * $size[0] / $size[1]); //$thumbnail_height = 100; //} { //$thumbnail_width = 690; //$thumbnail_height = (int)(500 * $size[1] / $size[0]); $old_width = $size[0]; $old_height = $size[1]; $thumbnail_width = 690; $thumbnail_height = ($old_height * $thumbnail_width / $old_width); } else { $thumbnail_width = (int)(690 * $size[0] / $size[1]); $thumbnail_height = 500; } // Build Thumbnail with GD 1.x.x, you can use the other described methods too $function_suffix = $gd_function_suffix[$filetype]; $function_to_read = "ImageCreateFrom".$function_suffix; $function_to_write = "Image".$function_suffix; // Read the source file $source_handle = $function_to_read ( $images_dir."/".$filename ); if($source_handle) { // Let's create an blank image for the thumbnail //$destination_handle = ImageCreate ( $thumbnail_width, $thumbnail_height ); $destination_handle = imagecreatetruecolor( $thumbnail_width, $thumbnail_height ); // Now we resize it ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] ); } // Let's save the thumbnail $function_to_write( $destination_handle, $images_dir."/tb_".$filename ); ImageDestroy($destination_handle ); // $result_final .= "<img src='".$images_dir. "/tb_".$filename."' style='margin-right: 20px; width: 100px;' />"; } } $counter++; } // Print Result echo <<<__HTML_END $result_final __HTML_END; ?> Can anyone show me how to make this work, OR show me a way to do this ... Thank you. Hey guys I am trying to read my xml file and itterate through the list. I am having trouble.
<?xml version="1.0" encoding="UTF-8"?> <stock> <itemPlace id="1"> <name>null</name> <image>null</image> <wholeSale>44</wholeSale> <retailPrice>null</retailPrice> <quantity>null</quantity> <location>null</location> <color>null</color> <size>null</size> <weight>null</weight> <description>null</description> <itemType>null</itemType> <date>null</date> </itemPlace> <itemPlace id="2"> <name>null</name> <image>null</image> <wholeSale>55</wholeSale> <retailPrice>null</retailPrice> <quantity>null</quantity> <location>null</location> <color>null</color> <size>null</size> <weight>null</weight> <description>null</description> <itemType>null</itemType> <date>null</date> </itemPlace> </stock> <?php $xml = simplexml_load_file('stock.xml'); foreach ($xml->xpath('itemPlace') as $eq) { echo "<p><a class='inline' href=\"#inline_content\"> {$eq->name}</a></p>"; echo '<br>'; echo " <div style='display:none'>"; echo " <div id='inline_content' style='padding:10px; background:#fff;'>"; echo " <p>"; echo " <strong>{$eq->wholeSale}</strong>"; echo "</div></div>";Is there a way I can look up the object through the itemPlace id="#" and call out the parameters of the item? Like the name price, etc? I know how to mySQL query but not XML, and this is a project that needs to use xml... FML..I have been looking for a few hours so any help would be appreciated! Hello everyone, I have a question with the use of the functon in_array... I have a list of categories in my table and I want to know if a specific category exists so I am doing this: $categoriasexistentes= mysql_query("SELECT * FROM LugaresTuristicos WHERE DestinoPeg='$LinkDestino' GROUP BY Clasificacion ") or die(mysql_error()); $array = mysql_fetch_array($categoriasexistentes); print_r($array); WHAT IS DISPLAYED BY print_r (there should be much more categories) IS THIS: Array ( => Bar [Clasificacion] => Bar ) If I ad this all categories are displayed: while($categoria = mysql_fetch_array($categoriasexistentes)) { $todas=$categoria['Clasificacion']; ?> <?php echo"{$todas} - "; ?> <?php }; ?> I'm just trying to incorporate some of what I've learned into practice and I can't believe I'm having problems with this but I really want to figure it out. I'm trying to create a simple program where a user enters the name of a song, and gives it a rating (out of 5), and it displays the output first by song rating then (if the ratings are the same) displays it by the name of the song alphabetically. The idea in practice would work like this...user enters: Quote Song Name: My Song Rating: 3 Song Name: His Song Rating: 5 Song Name: Her Song Rating: 5 Your list so far is: Her Song - 5 stars His Song - 5 stars My Song - 3 stars I just keep undoing things and clearly I'm not getting it. I had many ideas making it so I'll show you what I wrote (which isn't much): http://pastebin.com/2AGqgxQd It looks terrible I know, I was just trying to find out how to put things from the form INTO an array and trying to output the array as I described above. If I could figure out how to use these session arrays to hold the entries from the post, then I'd be able to sort them properly, I'm just lost right now because everything I've read online and tried wasn't fixing the problem. Thank you so much for the help! Never worked with GoDaddy before... Can't get my config script to connect to the database. Here's my code (I'm sure all the login info is correct, except maybe the host name but I copied that from GoDaddy too...) <?php ob_start(); // MySQL connection settings $db_host = "anakdesigns.db.2089823.hostedresource.com"; $db_user = "********"; $db_pass = "********"; $db_name = "********"; // Connect to the database $con = mysql_connect($db_host, $db_user, $db_pass) or die("Cannot connect to DB"); mysql_select_db($db_name) or die("Error accessing DB"); ?> http://www.anakdesigns.com/dev Hi guys, i am currently working on a project that queries an inventory database through the use of radio buttons, for example; If the first button FOR THE Item(HAMMERS)is clicked, the output should be the name of the item, the number sold and the total profit(calculations) into a table. the way i have it now, when io click on the radio button my output comes back as the results for all the items in the table, i want it to display only the information about hammers, then only about each individual item when the corresponding radio button is clicked. any help would be greatly appreciated!!! I'm trying to modify my existing comment form to only allow users to post comments. Right now anyone can visit the site and comment. Here is my code if($_POST['submit']){ if($_POST['$_SESSION['username']))==''){ $err = "You must login first"; }elseif($_POST['thecomment']==''){ $err = "You have to enter a comment."; }else{ $username = strip_tags($_POST['username']); $themessage = strip_tags($_POST['thecomment']); $ezdb->get_results("INSERT INTO user_comments (id,date_added, posted_by, message, image_id) VALUE ('','".time()."','".$name."','".$themessage."','".$imageid."')"); $err = "Thank you for your comment."; } } When a user is logged in, I still get the "you must log in error" Help please. Hi guys, I have had to make some changes to a database that I updated hockey players stats with. Since doing this I can no longer edit player stats in my admin section of the website. I was wondering if someone could possibly have a look at it for me. It is driving me nuts not being able to fix it. What should happen is: I choose the player from a list of teams to update. Their stats show up on next page in a table for the different competitions they play in (league, cup, play-offs). I could then update the stats and then once pressing the edit button at the bottom, this then updates my SQL database. Can anyone help? <?php if ($stat==1) { // normal players $table = "players"; } else { // snl_players $table ="snl_players"; } if ($act==edit) { $query11 = "SELECT * FROM `$table` WHERE `PlayerID` = '$PlayerID'"; $result11 = mysql_query($query11) or die ('Error: Sh2'); $rows = mysql_fetch_array($result11); $PlayerID = $rows['PlayerID']; $TeamID = $rows['TeamID']; $Team = $rows['Team']; $Player = $rows['Player']; $Games = $rows['Games']; $Goals = $rows['Goals']; $PPGoals = $rows['PPGoals']; $SHGoals = $rows['SHGoals']; $Assists = $rows['Assists']; $PIM = $rows['PIM']; $Points = $rows['Points']; $GamesCup = $rows['GamesCup']; $GoalsCup = $rows['GoalsCup']; $PPGoalsCup = $rows['PPGoalsCup']; $SHGoalsCup = $rows['SHGoalsCup']; $AssistsCup = $rows['AssistsCup']; $PIMCup = $rows['PIMCup']; $PointsCup = $rows['PointsCup']; /* $GamesNPL = $rows['GamesNPL']; $GoalsNPL = $rows['GoalsNPL']; $PPGoalsNPL = $rows['PPGoalsNPL']; $SHGoalsNPL = $rows['SHGoalsNPL']; $AssistsNPL = $rows['AssistsNPL']; $PIMNPL = $rows['PIMNPL']; $PointsNPL = $rows['PointsNPL']; */ $GamesPO = $rows['GamesPO']; $GoalsPO = $rows['GoalsPO']; $PPGoalsPO = $rows['PPGoalsPO']; $SHGoalsPO = $rows['SHGoalsPO']; $AssistsPO = $rows['AssistsPO']; $PIMPO = $rows['PIMPO']; $PointsPO = $rows['PointsPO']; $Nationality = $rows['Nationality']; $query11 = "SELECT * FROM `teams` WHERE `TeamID` = '$TeamID'"; $result11 = mysql_query($query11) or die ('Error: Sh2'); $rows = mysql_fetch_array($result11); $TeamName = $rows['TeamName']; echo ("<form name=\"form1\" method=\"post\" action=\"playerstats.php?act=editdo&PlayerID=$PlayerID&stat=$stat\"> <table width=\"80%\" border=\"0\"> <tr> <td width=\"30%\" class=\"data\">Player Name </td> <td width=\"70%\"><input name=\"Player\" type=\"text\" id=\"Player\" value=\"$Player\"></td> </tr> <tr> <td class=\"data\">Associated Team ID </td> <td class=\"data\"> <select name=\"TeamID\">"); $query11 = "SELECT * FROM `teams`"; $result11 = mysql_query($query11) or die ('Error: Sh2'); while ( $rows = mysql_fetch_array($result11) ) { $TeamName = $rows['TeamName']; $TeamID2 = $rows['TeamID']; if ($TeamID==$TeamID2) { echo(" <option value=\"$TeamID2\" selected>$TeamName</option>"); } else { echo(" <option value=\"$TeamID2\">$TeamName</option>"); } } echo("</select></td> </tr> <tr> <td class=\"data\">Games</td> <td><input name=\"Games\" type=\"text\" id=\"Games\" size=\"6\" value=\"$Games\"></td> </tr> <tr> <td class=\"data\">Goals</td> <td><input name=\"Goals\" type=\"text\" id=\"Goals\" size=\"6\" value=\"$Goals\"></td> </tr> <tr> <td class=\"data\">PPGoals</td> <td><input name=\"PPGoals\" type=\"text\" id=\"Goals\" size=\"6\" value=\"$PPGoals\"></td> </tr> <tr> <td class=\"data\">SHGoals</td> <td><input name=\"SHGoals\" type=\"text\" id=\"Goals\" size=\"6\" value=\"$SHGoals\"></td> </tr> <tr> <td class=\"data\">Assists</td> <td><input name=\"Assists\" type=\"text\" id=\"Assists\" size=\"6\" value=\"$Assists\"></td> </tr> <tr> <td class=\"data\">PIM</td> <td><input name=\"PIM\" type=\"text\" id=\"PIM\" size=\"6\" value=\"$PIM\"></td> </tr> <tr> <td class=\"data\">Points</td> <td><input name=\"Points\" type=\"text\" id=\"Points\" size=\"6\" value=\"$Points\"></td> </tr> <tr> <td class=\"data\">GamesCup</td> <td><input name=\"GamesCup\" type=\"text\" id=\"GamesCup\" size=\"6\" value=\"$GamesCup\"></td> </tr> <tr> <td class=\"data\">GoalsCup</td> <td><input name=\"GoalsCup\" type=\"text\" id=\"GoalsCup\" size=\"6\" value=\"$GoalsCup\"></td> </tr> <tr> <td class=\"data\">PPGoalsCup</td> <td><input name=\"PPGoalsCup\" type=\"text\" id=\"GoalsCup\" size=\"6\" value=\"$PPGoalsCup\"></td> </tr><tr> <td class=\"data\">SHGoalsCup</td> <td><input name=\"SHGoalsCup\" type=\"text\" id=\"GoalsCup\" size=\"6\" value=\"$SHGoalsCup\"></td> </tr> <tr> <td class=\"data\">AssistsCup</td> <td><input name=\"AssistsCup\" type=\"text\" id=\"AssistsCup\" size=\"6\" value=\"$AssistsCup\"></td> </tr> <tr> <td class=\"data\">PIMCup</td> <td><input name=\"PIMCup\" type=\"text\" id=\"PIMCup\" size=\"6\" value=\"$PIMCup\"></td> </tr> <tr> <td class=\"data\">PointsCup</td> <td><input name=\"PointsCup\" type=\"text\" id=\"PointsCup\" size=\"6\" value=\"$PointsCup\"></td> </tr> "); if ($stat==1) { } else { echo(" <tr><td class=\"data\">GamesPO</td> <td><input name=\"GamesPO\" type=\"text\" id=\"GamesPO\" size=\"6\" value=\"$GamesPO\"></td> </tr> <tr> <td class=\"data\">GoalsPO</td> <td><input name=\"GoalsPO\" type=\"text\" id=\"GoalsPO\" size=\"6\" value=\"$GoalsPO\"></td> </tr> <tr> <td class=\"data\">PPGoalsPO</td> <td><input name=\"PPGoalsPO\" type=\"text\" id=\"GoalsPO\" size=\"6\" value=\"$PPGoalsPO\"></td> </tr> <tr> <td class=\"data\">SHGoalsPO</td> <td><input name=\"SHGoalsPO\" type=\"text\" id=\"GoalsPO\" size=\"6\" value=\"$SHGoalsPO\"></td> </tr><tr> <td class=\"data\">AssistsPO</td> <td><input name=\"AssistsPO\" type=\"text\" id=\"AssistsPO\" size=\"6\" value=\"$AssistsPO\"></td> </tr><tr> <td class=\"data\">PIMPO</td> <td><input name=\"PIMPO\" type=\"text\" id=\"PIMPO\" size=\"6\" value=\"$PIMPO\"></td> </tr><tr> <td class=\"data\">PointsPO</td> <td><input name=\"PointsPO\" type=\"text\" id=\"PointsPO\" size=\"6\" value=\"$PointsPO\"></td> </tr><tr> <td class=\"data\">Nationality</td> <td><input name=\"Nationality\" type=\"text\" id=\"Nationality\" value=\"$Nationality\"></td> </tr> <td class=\"data\"> </td> <td> </td> </tr> <tr> <td class=\"data\"> </td> <td><input type=\"submit\" name=\"Submit\" value=\"Edit\"></td> </tr> </table> </form>"); } if ($stat!=0) { $query = "UPDATE `players` SET `Nationality` = '$Nationality', `GamesPO` = '$GamesPO' , `AssistsPO` = '$AssistsPO' , `GoalsPO` = '$GoalsPO' , `PPGoalsPO` = '$PPGoalsPO' , `SHGoalsPO` = '$SHGoalsPO' , `PointsPO` = '$PointsPO' , `PIMPO` = '$PIMPO' , `PIM` = '$PIM' , `PointsCup` = '$PointsCup' , `PIMCup` = '$PIMCup' , `AssistsCup` = '$AssistsCup' , `GoalsCup` = '$GoalsCup' , `PPGoalsCup` = '$PPGoalsCup' , `SHGoalsCup` = '$SHGoalsCup' , `GamesCup` = '$GamesCup' , `Points` = '$Points', `Assists` = '$Assists' , `Goals` = '$Goals' , `PPGoals` = '$PPGoals' , `SHGoals` = '$SHGoals' , `TeamID` = '$TeamID' , `Player` = '$Player' , `Games` = '$Games' WHERE `PlayerID` = '$PlayerID'"; $result = mysql_query($query) or die ("Can't Update"); echo ("The player has been updated.<br><br><a href=\"playerstats.php\"> Go back to the player List</a>"); } else { $query = "UPDATE `snl_players` SET `PIM` = '$PIM' , `GamesPO` = '$GamesPO' , `AssistsPO` = '$AssistsPO' , `GoalsPO` = '$GoalsPO' , `PPGoalsPO` = '$PPGoalsPO' , `SHGoalsPO` = '$SHGoalsPO' , `PointsPO` = '$PointsPO' , `PIMPO` = '$PIMPO' , `PointsCup` = '$PointsCup' , `PIMCup` = '$PIMCup' , `AssistsCup` = '$AssistsCup' , `GoalsCup` = '$GoalsCup' , `PPGoalsCup` = '$PPGoalsCup' , `SHGoalsCup` = '$SHGoalsCup' , `GamesCup` = '$GamesCup' , `Points` = '$Points', `Assists` = '$Assists' , `Goals` = '$Goals' , `PPGoals` = '$PPGoals' , `SHGoals` = '$SHGoals' , `TeamID` = '$TeamID' , `Player` = '$Player' , `Games` = '$Games' WHERE `PlayerID` = '$PlayerID'"; $result = mysql_query($query) or die ("Can't Update"); echo ("The player has been updated.<br><br><a href=\"playerstats.php\"> Go back to the player List</a>"); } } elseif ($act==teamlist) { $query112 = "SELECT * FROM `teams` WHERE `TeamID` = '$TeamID'"; $result112 = mysql_query($query112) or die ('Error: Sh2'); $rows2 = mysql_fetch_array($result112); $TeamName = $rows2['TeamName']; $Logo = $rows2['Logo']; if ($Logo!="") { echo("<img src=\"../Images/$Logo\" /><br><br>"); } else { } echo ("<strong>Edit $TeamName Players</strong><br><br>Click Player Names to edit details<br><br>"); $query11 = "SELECT * FROM `players` WHERE `TeamID` = '$TeamID'"; $result11 = mysql_query($query11) or die ('Error: Sh2'); while ( $rows = mysql_fetch_array($result11) ) { $Player = $rows['Player']; $PlayerID = $rows['PlayerID']; $TeamID = $rows['TeamID']; echo ("<span class=\"style1\"><a href=\"playerstats.php?act=edit&PlayerID=$PlayerID&stat=1\">$Player</a><br>"); } } else { echo ("Click Team Names to view players<br><br>"); $query11 = "SELECT distinct TeamID FROM `players` ORDER BY `TeamID`"; $result11 = mysql_query($query11) or die ('Error: Sh2'); while ( $rows = mysql_fetch_array($result11) ) { $TeamID = $rows['TeamID']; $query112 = "SELECT * FROM `teams` WHERE `TeamID` = '$TeamID'"; $result112 = mysql_query($query112) or die ('Error: Sh2'); $rows2 = mysql_fetch_array($result112); $TeamName = $rows2['TeamName']; echo ("<span class=\"style1\"><a href=\"playerstats.php?act=teamlist&TeamID=$TeamID&stat=1\">$TeamName</a><br>"); } echo ("<a name=\"snl\"></a><br><strong><a href=\"snlplayerstats.php\">SNL Teams</a></strong><br><br>"); } ?> Hello I am updating a SQL database - basically adding to an account field as follows... $sql1 = "select * from member where username = \"$owner\" limit 1 "; $result1 = mysql_query($sql1, $conn) or die(mysql_error()); $row1 = mysql_fetch_assoc($result1); $total_commissions = $row1['total_commissions']; $total_commissions = $total_commissions + $_SESSION['cost_per_token']; //add to data $balance = $row1['balance']; $balance = $balance + $_SESSION['cost_per_token']; //add to data #-------------------------------------------------------------------------- #Update db $sql1 = " UPDATE member SET total_commissions = \"$total_commissions\", balance = \"$balance\" WHERE username=\"$owner\" "; $result1 = mysql_query($sql1, $conn) or die(mysql_error()); is there a way to add to the data from the UPDATE query? e.g; $sql1 = " UPDATE member SET total_commissions = \"$total_commissions\ + $_SESSION['cost_per_token'] ", balance = \"$balance\ + $_SESSION['cost_per_token']" WHERE username=\"$owner\" "; I'm not shore what to do this update code isn't updating my database this is just the update code for my login Code: [Select] mysql_query("UPDATE users SET session_id='$session' WHERE email='$email' AND password='$pas'") or die(mysql_error()); //Add session ID to DB mysql_query("UPDATE users SET login_ip='$ip' WHERE email='$email' AND password='$pas'") or die(mysql_error()); //Add login IP to DBand this is all of it Code: [Select] <title>Log In</title><?php require('database.php'); //Include DB connection information if (isset($_POST['login'])) { //Execute the following if form is submitted $ip = mysql_real_escape_string($_SERVER["REMOTE_ADDR"]); //Geet user's IP Address $email = mysql_real_escape_string($_POST['email']); //Post email from form $password = mysql_real_escape_string(sha1(md5($_POST['pass']))); //Post password from form and encrypt if (empty($email) || empty($password)) { //Check for empty fields die("<b>Error:</b> All fields are required to be filled in."); } $check = mysql_query("SELECT * FROM users WHERE email = '$email'") or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) { //Check if account exists die("<b>Error:</b> Email and password do not match the database."); } $row = mysql_fetch_array($check); $db_password = $row['password']+$row['key']; if ($password != $db_password) { //Check if password is correct die("<b>Error:</b> Email and password do not match the database."); } $allowed = $row['u']; if ($allowed != 1) { //Check if they have permission die("<b>Error:</b> You do not have permission to view this section."); } function randomstring($length = 10) { $validCharacters = "abcdefghijklmnopqrstuxyvwz1234567890"; $validCharNumber = strlen($validCharacters); $result = ""; for ($i = 0; $i < $length; $i++) { $index = mt_rand(0, $validCharNumber - 1); $result .= $validCharacters[$index]; } return $result; } $session = randomstring(); $key = $row['key']; $pas = $password . $key; mysql_query("UPDATE users SET session_id='$session' WHERE email='$email' AND password='$pas'") or die(mysql_error()); //Add session ID to DB mysql_query("UPDATE users SET login_ip='$ip' WHERE email='$email' AND password='$pas'") or die(mysql_error()); //Add login IP to DB $level = $row['accounttype']; $u = $row['u']; $fs = $row['fs']; $bc = $row['bc']; $fam = $row['fam']; $future = time() + 1209600; setcookie("uemail", $email, $future); //Set cookie containing username setcookie("sessionid", $session, $future); //Set cookie containging session ID setcookie("acounttype", $level, $future); setcookie("u", $u, $future); setcookie("fs", $fs, $future); setcookie("bc", $bc, $future); setcookie("fam", $fam, $future); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// //header("Location: undefined.php"); //Redirect to members page } else { //If form is not submitted display the form echo<<<login <center> <h1>Log In To The Undefiend Section</h1> <h2>Or GO <a href="../main.php">Home</a></h2> <form method="post" action=""> Email: <input type="text" name="email"><br> Password: <input type="password" name="pass"><br> <input type="submit" name="login" value="Login"><br><br> </form></center> login; } ?> Hello, I am trying to update my database using a form. While submitting this function is called, but nothing is changed. If I replace the variables with values, the function works fine, but not with variables. Code: [Select] function updateCandidate($id, $F_Name, $L_Name, $Gender, $Bday, $PhoneNo, $Address, $City, $Country, $Nationality, $experience, $Stat) { $q = "UPDATE candidates SET F_Name = '$F_Name', L_Name='$L_Name', Gender='$Gender', Bday='$Bday', PhoneNo='$PhoneNo', Address = '$Address', City='$City', Country = '$Country', Nationality = '$Nationality', Experience_idExperience='$experience', Status= $Stat WHERE Users_UsersID = $id"; return mysql_query($q, $this->connection); I am trying to make a rating system and this script is not working. Code: [Select] $ratingget = $_REQUEST['star2']; mysql_select_db($database_news, $news); $query_ratingsys = "UPDATE news SET votes = votes +1 AND rating = rating +'$ratingget' WHERE id = '$id'"; $ratingsys = mysql_query($query_ratingsys, $news) or die(mysql_error()); I'm trying to update my database so that if someone enters an e-mail address that doesn't exist, the program updates the database with the new address. I've tested everything and $result returns the correct data every time (0 or 1) but if the address doesn't exist, nothing gets updated. I know I'm missing something, just not sure what it is... Code: [Select] { $result = mysql_query(" SELECT * FROM PlayerInfo WHERE Player_Email = '$playeremail'"); IF($result) { IF (mysql_num_rows($result) = 0) { //Insert into database: new e-mail address... } } I've also tested the insert into statement and it works, so that's not the issure. Any help appreciated. Thanks. Hello, I have a form where individuals can update there personal information that is already stored in a database, i.e name, address, phone number etc. There are several fields they can update. Right now it sends an email to the owner that an individual has updated their records, and sends all the fields that are in the table. Is it possible to let the owner be notified by email which individual field was updated? Example their phone number has changed they make the update and the owner gets an e-mail with just that field update. I hope I explained myself properly. Thank you in advance. |