PHP - Error Occurs While Updating Data In Mysql Using Csv File
I need help here. I am creating a system where the user will be able to update the product stock by uploading the stock of the products according to the id that has been assigned to the product.
I tried the code below but all i could not update my data into my database. And there's not error shown on my code. I do not know what is wrong with my codes. Please help me. <?php include 'conn.php'; if(isset($_POST["add_stock"])) { if($_FILES['product_file']['tmp_name']) { $filename = explode(".", $_FILES['product_file']['tmp_name']); if(end($filename) == "csv") { $handle = fopen($_FILES['product_file']['tmp_name'], "r"); while($data = fgetcsv($handle)) { $product_id = mysqli_real_escape_string($conn, $data[0]); $product_stock = mysqli_real_escape_string($conn, $data[1]); $product_status = 1 ; $query = "UPDATE products SET `product_stock` = '$product_stock', `product_status` = '$product_status' WHERE id = '$product_id'"; mysqli_query($conn, $query); } fclose($handle); header("location: upload-product.php?updation=1"); } else { echo '<script>alert("An error occur while uploading product. Please try again.") window.location.href = "upload-product.php"</script>'; } } else { echo '<script>alert("No file selected! ") window.location.href = "upload-product.php"</script>'; } } if(isset($_GET["updation"])) { echo '<script>alert("Product Stock Updated successfully!")</script>'; } ?> <div class="col-12"> <div class="card card-user"> <div class="card-header"> <h5 class="card-title">Update Product Stock</h5> <div class="card-body"> <div class="form-group"> <label for="file">Update Products stock File (.csv file)</label> <a href="assets/templates/product-template.xlsx" title="Download Sample File (Fill In Information and Export As CSV File)" class="mx-2"> <span class="iconify" data-icon="fa-solid:download" data-inline="false"> </a> </div> <form class = "form" action="" method="post" name="uploadCsv" enctype="multipart/form-data"> <div> <input type="file" name="product_file" accept=".csv"> <div class="row"> <div class="update ml-auto mr-auto"> <button type="submit" class="btn btn-primary btn-round" name="add_stock"> Import .cvs file</button> </div> </div> </div> </div> </form> </div> </div>
This is the template that i require user to key in and saved it in CSV format before uploading it. Similar TutorialsI have a form to search through apartments but if one field (rent) is not filled the php script cannot process the search. Is there a way that I can have the script just search the minimum rent or maximum rent if those fields are not filled in? In other words could I make it say if blank put in 0 for minimum rent? The HTML Form: Code: [Select] <form method="post" action="searchapts.php"> <table width="372" border="0" class="apttable"> <tr> <td width="66" style="color: #000">Borough:</td> <td colspan="2"><select name="county" id="county"> <option selected="selected">Bronx</option> <option>Brooklyn</option> <option>Manhattan</option> <option>Queens</option> <option>Staten Island</option> <option>---------------</option> <option>Nassau</option> <option>Suffolk</option> </select></td> </tr> <tr> <td style="color: #000">Beds:</td> <td colspan="2"><select name="type" id="type"> <option>0 Bed</option> <option>1 Bed</option> <option>2 Bed</option> <option>3 Bed</option> <option>4 Bed</option> <option>5 Bed</option> </select></td> </tr> <tr> <td style="color: #000">Rent:</td> <td width="151" style="color: #000"><span id="AptRentMin"> <span id="sprytextfield3"> <input name="min_price" type="text" id="min_price" value="" size="7" maxlength="7" /> <span class="textfieldRequiredMsg">Required.</span></span>(Min)</td> <td width="141" style="color: #000"><span id="AptRentMax"> <span id="sprytextfield4"> <input name="max_price" type="text" id="max_price" value="" size="7" maxlength="7" /> <span class="textfieldRequiredMsg">Required.</span></span>(Max)</td> </tr> <tr> <td style="color: #000"><input name="Search" id="Search" value="Search" type="submit" /></td> <td> </td> <td> </td> </tr> </table> </form> The PHP Script: Code: [Select] <?php if ($_POST){ $county = $_POST['county']; $rooms = $_POST['type']; $rentmin = $_POST['rent_min']; $rentmax = $_POST['rent_max']; } $dbase = mysql_connect ( 'localhost', '', '' ); mysql_select_db ( '', $dbase ); if($county){ $sql = "SELECT * FROM `apartments`, `county` = '".mysql_real_escape_string($county)."', `rooms` = '".mysql_real_escape_string($rooms)."', `MIN(rent)` '".mysql_real_escape_string($rentmin)."', `MAX(rent)` '".mysql_real_escape_string($rentmax)."' order by `date_created` DESC"; }else{ $sql = "SELECT * FROM `apartments`"; } $res = mysql_query($sql, $dbase); if ( mysql_num_rows($res) > 0 ) { echo "<strong>Click Headers to Sort</strong>"; echo "<table border='0' align='center' bgcolor='#999969' cellpadding='3' bordercolor='#000000' table class='sortable' table id='results'> <tr> <th> Title </th> <th> Borough </th> <th> Town </th> <th> Phone </th> <th> Rooms </th> <th> Bath </th> <th> Fees </th> <th> Rent </th> </tr>"; while($row = mysql_fetch_assoc($res)) { echo "<tr> <td bgcolor='#FFFFFF' style='color: #000' align='center'> <a href='classified/searchapts/index.php?id=".$row['id']."'>" . $row['title'] . "</a></td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['county'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['town'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['phone'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['rooms'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['bath'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['feeornofee'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['rent'] . "</td> </tr>"; } echo "</table>"; print_r($apts); } else { echo "<p> </p><p> </p> No Results <br /><p> </p><FORM><INPUT TYPE='button' VALUE='Go Back' onClick='history.go(-1);return true;'></FORM> and Refine Your Search <p> </p><p> </p>"; } ?> Hello folks, I can not seem to find out why this code is not being executed properly. Basically, I'd like to edit Records, so I am using forms to retrieve data, make modifications then save them. Code: [Select] <?php //connection to db $results = mysql_query("SELECT * FROM crud WHERE id=".$_GET[id]."") or die (mysql_error()); $row = mysql_fetch_assoc($results); echo "<form action=\"\" method=\"POST\">"; echo "Year: <input type=\"text\" value=".$row['car_year']." name=\"car_year\" /> <br />"; echo "Make: <input type=\"text\" value=".$row['car_make']." name=\"car_make\" /> <br />"; echo "Model: <input type=\"text\" value=".$row['car_model']." name=\"car_model\" /><br /><br />"; echo "Description:<br /><textarea rows=\"15\" cols=\"60\" name=\"description\" />". $row['description']. "</textarea>"; echo "<br /><input type=\"submit\" value=\"save\">"; echo "</form>"; if ($_POST['save']) { $car_year = $_POST['car_year']; $car_make = $_POST['car_make']; $car_model = $_POST['car_model']; $description = $_POST['description']; // Update data $update = mysql_query("UPDATE crud SET car_year='$car_year', car_make='$car_make' car_model='$car_model', description='$description' WHERE id=".$_GET['id']."") or die (mysql_error()); echo 'Update successfull'; } ?> Please HELP!!!! I used to be good at this but I changed servers and everything is different... Heres my code so far: Code: [Select] <?php $rated=$_REQUEST['rated']; echo $rated; $rating=$_REQUEST['rating']; echo $rating; // Make a MySQL Connection mysql_connect("localhost", "********", "********") or die(mysql_error()); mysql_select_db("*********") or die(mysql_error()); $result = mysql_query("SELECT * FROM main WHERE username = '$rated'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $votes = $db_field['$rating']; $newvotes = $votes + 1; echo $newvotes; mysql_query("UPDATE main SET $rating = '$newvotes' WHERE username = '$rated'"); ?> Whats going on here is the colomb that I want to update comes as a variable $rated (That works) and then the database selects the row to update with $username (That works) and gets the variable $newvotes by taking the original value of the data its about to update and add 1 to it (That works) Then it updates the field to $newvotes.... I don't know why the update won't go through... there are no errors.... Hi all I have 3 tables Table_1, Table_2 and Table_3 Table_1 is a list of countries, with name and country_id Table_2 is a table that has 3 fields, id, name and description Table 3 is a table that has name, Table_2_id So what I need to do: Display the name and description field of Table_2 in a form Loop through the countries table and display each as an input box and display on the same form When I fill out the form details, the name/description must be inserted into Table_2, creating an id The input boxes data then also needs inserting into Table_3, with the foreign key of Table_2_id So a small example would be: Name: testing Description: this is a test Country of Australia: Hello Country of Zimbabwe: Welcome This means that in Table_2, I will have the following: ============================= | id | name | description | 1 | testing | this is a test ============================= Table_3 ============================= | Table_2_id | name | country_id | 1 | Hello | 20 | 1 | Welcome | 17 ============================= 20 is the country_id of Australia 17 is the country_id of Zimbabwe Code: Generating the input fields dynamically: $site_id = $this->settings['site_id']; $options = ''; $country_code = ''; $query = $DB->query("SELECT country_code, country_id, IF(country_code = '".$country_code."', '', '') AS sel FROM Table_1 WHERE site_id='".$this->settings['site_id']."' ORDER BY country_name ASC"); foreach ($query->result as $row) { $options .= '<label>' . 'Test for ' . $this->settings['countries'][$row['country_code']] . '</label>' . '<br />'; //$row['country_id'] is the country_id from Table_1 $options .= '<input style="width: 100%; height: 5%;" id="country_data" type="text" name="' . $row['country_id'] . '" value="GET_VALUE_FROM_DB" />' . '<br /><br />'; } echo $options; This outputs: Code: [Select] Textareas go here...... <label>Test for Australia</label> <input type="text" value="" name="20" id="country_data" style="width: 100%; height: 5%;"> <label>Test for Zimbabwe</label> <input type="text" value="" name="17" id="country_data" style="width: 100%; height: 5%;"> Now, I need to insert the value of the input field and it's country_id (20 or 17) into Table_3 and also Table_2_id. This then means I could get the value from Table_3 to populate 'GET_VALUE_FROM_DB' But I'm at a loss on how I'd do this. Could someone help me with this? Thanks hello, I need xml file as playlist.xml and i want to retrive data from my mysql table. I have the following code as i am trying to use php code inside playlist.xml file. Code: [Select] <?xml version="1.0" encoding="utf-8"?> <xml> <?php $dbhost='localhost'; $dbuser='pavel'; $dbpass='pavel123'; mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db("amarmusic"); $sql=("select *from bband where artist='Meghdol' and album='Drohe Montre Valobasha';"); $res = mysql_query($sql); while ($result = mysql_fetch_array($res)){ ?> <track> <path> <? $result['link']?></path> <title><? $result['title']?></title> </track> <? } ?> </xml> but unfortunately its not working. any1 have any idea how to fix it? please help me. Hey guys, first post and I've just returned to PHP after about 4 years of no coding, so be gentle! In a nutshell I'm creating a photo album and I've pretty much got the majority of it complete, apart from a few tweaks and the obvious ongoing development. I'm at the stage now where I need to moderate images being uploaded, so I've made an admin only script which displays the uploaded images with links that say approve and delete. Uploaded images are stored in uploads/ which are left there until i move them to img/, plus the filename is stored in mysql so I can "<img src='../uploads/".$row['filename']."' width='200'>". Now, I would like to make the Approve button move the image from uploads/ to img/ and I'd like the delete button to remove both the entry from MySQL and the file from the uploads folder and I'm not too sure on how to make it work. Here's what I have so far in the mod.php file (mod for moderation) Code: [Select] $image = mysql_query("SELECT * FROM images WHERE id"); while($row = mysql_fetch_assoc($image)) { echo " <table> <td> <tr> <img src='../uploads/".$row['filename']."' width='200'><br /> </tr> </td> <td> <tr> <a href=''>Approve</a> <a href=''>Delete</a> </tr> </td> </table> "; } You'll have to ignore the table tags, I'm still getting used to positioning items on the screen lol. Any clues would be greatly appreciated Live long and prosper. Hi, Im getting this error with my script that im using to try and echo content for my website: Parse error: syntax error, unexpected T_ECHO in /home/a9855336/public_html/test.php on line 16 my php code is <?php $host="mysql12.000webhost.com"; // Host name $username="a9855336_root"; // Mysql username $password="n4th4n%"; // Mysql password $db_name="a9855336_mail"; // Database name // Connect to server and select databse. mysql_connect($host, $username, $password); mysql_select_db($db_name); $query = "SELECT title, content, FROM members where ID = 1"; $result = mysql_query($query); $row = mysql_fetch_array($result) echo $row['title']; ?> html stuff <?php echo $row['content']; ?> If anyone can help me fix this problem or sugguest a dfiferent way to go about this it would be greatly appriciated. Thanks, Blink359 Hi Guys, I have stuck with my problem and i am nothing to php, i already posted this to another php script forum, but haven't solve, so i wondering if anyone here help me and many thanks. this is all about game scores from .xml file inside the xml file itself as: Code: [Select] <gesmes:Envelope> <gesmes:subject>Reference Scores</gesmes:subject> - <gesmes:Sender> <gesmes:name>Game Information Scores</gesmes:name> </gesmes:Sender> - <Cube> - <Cube time="2010-10-13"> <Cube scores="GameA1" value="1.5803"/> <Cube scores="GameA2" value="21.35"/> ............etc <Cube scores="GameA15" value="135"/> </Cube> </Cube> </gesmes:Envelope> then i got php script that can save all data of .xml above to mysql, look like <?php class Scores_Converter { var $xml_file = "http://192.168.1.112/gamescores/scores-daily.xml"; var $mysql_host, $mysql_user, $mysql_pass, $mysql_db, $mysql_table; var $scores_values = array(); //Load convertion scores function Scores_Converter($host,$user,$pass,$db,$tb) { $this->mysql_host = $host; $this->mysql_user = $user; $this->mysql_pass = $pass; $this->mysql_db = $db; $this->mysql_table = $tb; $this->checkLastUpdated(); $conn = mysql_connect($this->mysql_host,$this->mysql_user,$this->mysql_pass); $rs = mysql_select_db($this->mysql_db,$conn); $sql = "SELECT * FROM ".$this->mysql_table; $rs = mysql_query($sql,$conn); while($row = mysql_fetch_array($rs)) { $this->scores_values[$row['scores']] = $row['value']; } } /* Perform the actual conversion, defaults to 1.00 GameA1 to GameA3 */ function convert($amount=1,$from="GameA1",$to="GameA3",$decimals=2) { return(number_format(($amount/$this->scores_values[$from])*$this->scores_values[$to],$decimals)); } /* Check to see how long since the data was last updated */ function checkLastUpdated() { $conn = mysql_connect($this->mysql_host,$this->mysql_user,$this->mysql_pass); $rs = mysql_select_db($this->mysql_db,$conn); $sql = "SHOW TABLE STATUS FROM ".$this->mysql_db." LIKE '".$this->mysql_table."'"; $rs = mysql_query($sql,$conn); if(mysql_num_rows($rs) == 0 ) { $this->createTable(); } else { $row = mysql_fetch_array($rs); if(time() > (strtotime($row["Update_time"])+(12*60*60)) ) { $this->downloadValueScores(); } } } /* Download xml file, extract exchange values and store values in database */ function downloadValueScores() { $scores_domain = substr($this->xml_file,0,strpos($this->xml_file,"/")); $scores_file = substr($this->xml_file,strpos($this->xml_file,"/")); $fp = @fsockopen($scores_domain, 80, $errno, $errstr, 10); if($fp) { $out = "GET ".$scores_file." HTTP/1.1\r\n"; $out .= "Host: ".$scores_domain."\r\n"; $out .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { $buffer .= fgets($fp, 128); } fclose($fp); $pattern = "{<Cube\s*scores='(\w*)'\s*value='([\d\.]*)'/>}is"; preg_match_all($pattern,$buffer,$xml_values); array_shift($xml_values); for($i=0;$i<count($xml_values[0]);$i++) { $exchange_value[$xml_values[0][$i]] = $xml_values[1][$i]; } $conn = mysql_connect($this->mysql_host,$this->mysql_user,$this->mysql_pass); $rs = mysql_select_db($this->mysql_db,$conn); foreach($exchange_value as $scores=>$value) { if((is_numeric($value)) && ($value != 0)) { $sql = "SELECT * FROM ".$this->mysql_table." WHERE scores='".$scores."'"; $rs = mysql_query($sql,$conn) or die(mysql_error()); if(mysql_num_rows($rs) > 0) { $sql = "UPDATE ".$this->mysql_table." SET value=".$value." WHERE scores='".$scores."'"; } else { $sql = "INSERT INTO ".$this->mysql_table." VALUES('".$scores."',".$value.")"; } $rs = mysql_query($sql,$conn) or die(mysql_error()); } } } } /* Create the scores table */ function createTable() { $conn = mysql_connect($this->mysql_host,$this->mysql_user,$this->mysql_pass); $rs = mysql_select_db($this->mysql_db,$conn); $sql = "CREATE TABLE ".$this->mysql_table." ( scores char(3) NOT NULL default '', value float NOT NULL default '0', PRIMARY KEY(scores) ) ENGINE=MyISAM"; $rs = mysql_query($sql,$conn) or die(mysql_error()); $sql = "INSERT INTO ".$this->mysql_table." VALUES('GameA0',1)"; $rs = mysql_query($sql,$conn) or die(mysql_error()); $this->downloadValueScores(); } } ?> but that php script above just create table of mysql below CREATE TABLE IF NOT EXISTS `scrore_table` ( `scores` char(3) NOT NULL default '', `value` float NOT NULL default '0', PRIMARY KEY (`scores`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `scrore_table` (`scores`, `value`) VALUES ('GameA0', 1), ('GameA1', 1.5651), ......etc ('GameA15', 95.572); while of my existing database table look like: CREATE TABLE IF NOT EXISTS `scrore_table` ( `scrore_id` int(11) NOT NULL auto_increment, `scrore_title` varchar(32) collate utf8_bin NOT NULL default '', `scores` varchar(3) collate utf8_bin NOT NULL default '', `decimal_place` char(1) collate utf8_bin NOT NULL, `value` float(15,8) NOT NULL, `date_updated` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`currency_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ; INSERT INTO `scrore_table` (`scrore_id`, `scrore_title`, `scores`, `decimal_place`, `value`, `date_updated`) VALUES (1, 'Game Class A0', 'GameA0', '2', 1.00000000, '2010-04-06 22:00:54'), (2, 'Game Class A1', 'GameA1', '2', 1.52600002, '2010-04-06 22:00:54'), ..............................etc (14, 'Game Class A15', 'GameA15', '2', 1.13999999, '2010-04-06 22:00:54'); as i said i newbie to php then i dont know how to modify the php code above able to automatically create the table and insert/update new fields e.g. scrore_id, scrore_title,decimal_place, date_updated also all values to my existing database i looking for some helps and thanks in advance.. I think this is the right section to post this is in..... Anyway.....I'm building a web site that requires i have functionality to upload a tab delimited file (or some file format that is easiest) via php and insert the data into MYSQL. I've searched for many third party scripts but none seem to work. So I've decided to move to the community to see if someone can give me insight on how i might accomplish this script. I have some third party scripts but I'm not sure if they'd be of any use. Thank you kindly 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? Ok this is puzzleing. I am geting "Could not delete data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1". but its is deleting the entry that needs to be removed. The "1" is the entry. Just not sure what is causing the error. I do have another delete php but I have put that on the back burning for the time being.
<?php $con = mysqli_connect("localhost","user","password","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20 "); $amp20ptid = $_POST['amp20ptid']; // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); mysqli_query($con, "DELETE FROM amp20 WHERE amp20ptid = '$amp20ptid'"); if (!mysqli_query($con, $amp20ptid)); { die('Could not delete data: ' . mysqli_error($con)); } echo "Part has been deleted to the database!!!\n"; mysqli_close($con); } ?> Ok, so I'm not quite sure how to explain this, but here it goes: I have table A that contains stats for all players in the NHL, and then I have table B with just a few players. These few players in table B are also in table A, but table B has more information on them. I want to take the stats for these players out of table A and put into table B, and I want table B to update along with table A every time those numbers change. How would I do this? I am working on a php project in which players can equipt items from there inventory and it shows them there current stats. When players have decided to equipt an item they hit the submit button and the new stats should show. The issue I have is that the data is delaying in update such as: we have 10 strength we equipt a sword with +2 to strength and click submit it displays we have 10 strength we equipt a axe with +3 to strength and click submit it displays 12 strength we equipt a sword with +2 to strength and click submit it displays 13 strength we equipt a sword with +2 to strength and click submit it displays 12 strength .... my code is represented below <?php updateEquiptment(); require("playerInfo.php"); ?> <p title="This stat increases how hard you hit with weapons!">Strength:<?php echo $baseStrength + getModStrength() ?> </p> the functions updateEquiptment and getModStrength are in the playerInfo.php file and are shown like this: $user = $_SESSION['username']; $result = mysql_fetch_row(mysql_query("SELECT equiptment FROM warUsers WHERE name = '$user'")); $equiptment = explode(",",$result[0]); function updateEquiptment() { global $user; $result = mysql_fetch_row(mysql_query("SELECT equiptment FROM warUsers WHERE name = '$user'")) or die(mysql_error()); global $equiptment; $equiptment = explode(",",$result[0]); } //get there modified stats function getModStrength() { $total = 0; global $equiptment; foreach ($equiptment as $value) //loop through every item in the equiptment { if($value == 0 || $value == null) //if nothing is equipt go to the next loop continue; $result = mysql_query("SELECT * FROM items WHERE id = '$value'"); $item = mysql_fetch_row($result); $total += $item[4]; //get the items strength and add it to the total } return $total; } any help on the matter would be greatly appreciated Hi, I want to loop out data from DB in <input> and change and update several posts at the same time. Can you give me a short example, how <input> and maybe foreach could look like? Thanks I keep having trouble with exploded arrays, every function i go to use within the exploded quotes requires a string not an array. Below im trying to count the spaces and if there are four or more change the data string to the halt string. The problem is most of the functions require a string, is there another way to only count the space characters within quotes without exploding the quotes? Code: [Select] $data = 'Hello World This is a test string!'; $halt = 'String had more than 4 spaces.'; $arr = explode('"', $data); if (substr_count($arr, ' ') >= 4) { $data = implode('"', $arr); $data = $halt; 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 Hey guys, I got another one that i could use some help on. I have a input form that utilizes a javascript that adds additional rows to my table. here is a look at what i got. Code: [Select] <script type="text/javascript"> function insertRow() { var x = document.getElementById('results_table').insertRow(-1); var a = x.insertCell(0); var b = x.insertCell(1); var c = x.insertCell(2); var d = x.insertCell(3); var e = x.insertCell(4); a.innerHTML="<input type=\"text\" name=\"id\">"; b.innerHTML="<input type=\"text\" name=\"place\">"; c.innerHTML="<input type=\"text\" name=\"username\">"; d.innerHTML="<input type=\"text\" name=\"earnings\">"; e.innerHTML="<input type=\"button\" value=\"delete\" onClick=\"deleteRow(this)\">"; } function deleteRow(r) { var i=r.parentNode.parentNode.rowIndex; document.getElementById('results_table').deleteRow(i); } </script> this is my code stored in the header of my page. basically just a button to add a new row and a button in each row to delete rows if needed. here is a look at my html table, pretty basic... Code: [Select] <table id="results_table"> <th>Event ID</th><th>Place</th><th>Username</th><th>Earnings</th> <tr> <td><input type="text" name="id"></td><td><input type="text" name="place"></td><td><input type="text" name="username"></td><td><input type="text" name="earnings"></td><td><input type="button" value="delete" onClick="deleteRow(this)"</td> </tr> </table> Now what I am hoping to acheive is once i submit all of these rows to the database i will insert each of these rows into their own row in the database. is this doable? the structure of my database is: ResultID (Primary Key) Place Earnings UserID (Foreign Key) EventID (Foreign Key) now i think the biggest problem i'm having with submitting data to the database is that in the original HTML form I am typing in the actual username and not the userID. so when it comes to processing I need to do a switch of these two things before I run my query. Should something like this work? Code: [Select] $username = $_POST['username']; $userID = "SELECT userID FROM users WHERE username="$username"; $query = mysql_query($userID); also i've never tried to submit multiple entries at a time. maybe i have to create an array somehow in order to capture each rows data. any thoughts? as always thanks for the help. Hello all, I have form that has several fields. Each field will be saved to a table (which is a relations table we will call markups). The form is built from another table which is an array of categories. The output will build a form with each category and allow the end-user to input data for each category. The information the user will be entering is markup values. Cat1 | Markup Input Cat2 | Markup Input Cat3 | Markup Input I'll be saving the data in their own columns and not as an serialized array to the database. I'm currently looping through the arrayed fields and saving the data to the markup relations table. I've read other forums and serializing the data will be to difficult to retrieve for relationship purposes?? Anyway, here's my question: Let's say the user is entering the markups for the first time. They go down the list of categories and add their markups for each and click save. Cool, no problem just do an INSERT INTO. Then, they go into the category setup screen and add a category then go back to the markup screen and now have to update the category markup that was just added. So now I have to do an UPDATE to the current listed markups table (no problem). But now I have to add another row in the same table from that array. Is there a logical way of handling this. I guess I'm looking for some ideas on how to accomplish this task. I hope you guy understand what I'm after here. Thanks for any suggestions on this. well here my page i tryed and tryed to get it working but it shows the data but it dont update it Code: [Select] [php]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><?php include "../config.php"; $id = $_GET['id']; $con = database_connect(); $sql = "SELECT * FROM anime1 WHERE animeid ='$id'"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $title = $row['title']; $type = $row['type']; $episode = $row['episode']; $year = $row['year']; $genre = $row['genre']; $status = $row['status']; $summary = $row['summary']; $pictures = $row['pictures']; }mysql_query($sql) or exit(mysql_error()); mysql_close($con); ?> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".flip").click(function(){ $(".panel").slideToggle("slow"); }); }); </script> <style type="text/css"> </style> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Transdmin Light</title> <!-- CSS --> <link href="style/css/transdmin.css" rel="stylesheet" type="text/css" media="screen" /> <!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie6.css" /><![endif]--> <!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie7.css" /><![endif]--> <!-- JavaScripts--> <script type="text/javascript" src="style/js/jquery.js"></script> <script type="text/javascript" src="style/js/jNice.js"></script> </head> <body> <div id="wrapper"> <!-- h1 tag stays for the logo, you can use the a tag for linking the index page --> <h1><a href="#"><span>Transdmin Light</span></a></h1> <!-- You can name the links with lowercase, they will be transformed to uppercase by CSS, we prefered to name them with uppercase to have the same effect with disabled stylesheet --> <ul id="mainNav"> <li><a href="#">DASHBOARD</a></li> <!-- Use the "active" class for the active menu item --> <li><a href="./anime.php" class="active">Anime</a></li> <li><a href="#">DESIGN</a></li> <li><a href="#">OPTION</a></li> <li class="logout"><a href="#">LOGOUT</a></li> </ul> <!-- // #end mainNav --> <div id="containerHolder"> <div id="container"> <div id="sidebar"> <ul class="sideNav"> <li><?php echo $lbox1 ?></li> <li><?php echo $lbox2 ?></li> <li><?php echo $lbox3 ?></li> <li><?php echo $lbox4 ?></li> <li> <?php echo $lbox5 ?></li> <li><?php echo $lbox6 ?></li> </ul> <!-- // .sideNav --> </div> <!-- // #sidebar --> <!-- h2 stays for breadcrumbs --> <h2><a href="#">Anime</a> » edit » <?php echo "$title"; ?></h2> <div id="main"> <form action="<?php echo $_SERVER['PHP_SELF']."?id=$id" ; ?>" method="post" class="jNice"> <h3>Editing <?php echo "$title"; ?>, when finished click submit</h3> <fieldset> <p> <label>Series Title -- (Put the Title of the Series you are adding into here)</label> <input name="title" type="text" class="text-long" id="title" value="<?php echo $title ?>" /> </p> <p> <label>Type -- (Put what type of anime is it?)</label> <select name="type" id="type"> <option selected="selected">Select one</option> <option>TV Series</option> <option>OVA</option> <option>TV Special</option> <option>Movie</option> <option>Web</option> <option>DVD Special</option> <option>Other</option> </select> </p> <p> <label>Episodes -- (How many Episode are there?)</label> <input name="episode" type="text" class="text-long" id="episode" value="<?php echo $episode ?>" /> </p> <p> <label>Year -- (What year was the anime release in?)</label> <input name="year" type="text" class="text-long" id="year" value="<?php echo $year ?>" /> </p> <p> <label>genre <a href="./genre">(click this for the list and FAQ for adding in genre)</a></label> <input name="genre" type="text" class="text-long" id="genre" value="<?php echo $genre ?>" /> </p> <p> <label>status -- (What Is the status of the anime, Completed, Ongoing or Stalled)</label> <select name="status" id="status"> <option selected="selected">Select one</option> <option>Complete</option> <option>Ongoing</option> <option>Stalled</option> </select> </p> <p> <label>Summary -- (Put in the Summary for the anime)</label> <textarea name="summary" cols="1" rows="1" id="summary"><?php echo $summary ?></textarea> </p> <p> <label>Pictures -- (link to the Anime Pictures you upladed)</label> <input name="pictures" type="text" class="text-long" id="pictures" value="<?php echo $pictures ?>" /> </p> <?php $con = database_connect(); $sql="UPDATE anime1 SET title='$title', type='$type', episode='$episode', year='$year', genre='$genre', status='$status', summary='$summary', pictures='$pictures' WHERE animeid = '$id'"; $con = database_connect(); $title = $_POST['title']; $type = $_POST['type']; $episode = $_POST['episode']; $year = $_POST['year']; $genre = $_POST['genre']; $status = $_POST['status']; $summary = $_POST['summary']; $pictures = $_POST['pictures']; $title = mysql_real_escape_string($title); $type = mysql_real_escape_string($type); $episode = mysql_real_escape_string($episode); $year = mysql_real_escape_string($year); $genre = mysql_real_escape_string($genre); $status = mysql_real_escape_string($status); $summary = mysql_real_escape_string($summary); $pictures = mysql_real_escape_string($pictures); error_reporting(-1); if (!mysql_query($sql,$con)) { die('Error adding anime database: ' . mysql_error()); } ?> <h3> </h3> <?php $con = database_connect(); $sql1 = "SELECT * FROM episodea WHERE animeid = '$id' UNION ALL SELECT * FROM episodeb WHERE animeid = '$id'"; $result1 = mysql_query($sql1); while ($row = mysql_fetch_assoc($result1)) { $ep = $row['ep']; $epname = $row['epname']; $animeid = $row['animeid']; $video = $row['video']; $video2 = $row['video2']; $video3 = $row['video3']; mysql_query($sql) or exit(mysql_error()); echo " <div class=\"panel\">\n"; echo "<p>\n"; echo " <label>Episodes -- (When this box says Anime episode finished, you have added in all the episodes)</label>\n"; echo " <input name=\"ep\" type=\"text\" class=\"text-long\" id=\"ep\" value=\" $ep\" readonly=\"readonly\" />\n"; echo " </p>\n"; echo " <p>\n"; echo " <label>Episodes Name-- (What is the name of the episode you are adding? --- If the episodes has no name enter episode number)</label>\n"; echo " <input name=\"epname\" type=\"text\" class=\"text-long\" id=\"epname\" value=\" $epname\" />\n"; echo " </p>\n"; echo " <p>\n"; echo " <label>Viewable -- (Is the episode your are adding in SUBBED or DUBBED or RAW?)</label>\n"; echo " <select name=\"viewable\" id=\"viewable\">\n"; echo " <option selected=\"selected\">Select one</option>\n"; echo " <option>SUBBED</option>\n"; echo " <option>DUBBED</option>\n"; echo " <option>RAW</option>\n"; echo " </select>\n"; echo " </p>\n"; echo " <p>\n"; echo " <label>Video 1 -- (enter the embed code for the episode you are adding in)</label>\n"; echo " <textarea name=\"video\" cols=\"1\" rows=\"1\" id=\"video\"> $video</textarea></p>\n"; echo " <p>\n"; echo " <label>Video 2 -- ( If you have a 2ed embed code </label>\n"; echo " <textarea name=\"video1\" cols=\"1\" rows=\"1\" id=\"video1\"> $video2</textarea>\n"; echo " </p>\n"; echo " <p>\n"; echo " <label>Video 3 --( If you have a 3ed embed code </label>\n"; echo " <textarea name=\"video4\" cols=\"1\" rows=\"1\" id=\"video4\"> $video3</textarea>\n"; echo "<h3>\n"; echo "<a href=\"#submit\">IF you finished editing ep, click me to go to submit button</a></h3>\n"; echo " </p>\n"; echo "</div>\n"; echo " \n"; echo " <br />"; echo "<br />"; echo "<p class=\"flip\">Click here to edit all Episodes For $title </p>\n"; echo " <br />"; echo "<br />"; } ?> <h3> remember to click submit before changing the page</h3> <h3> </h3> <h3> <a name="submit" id="submit"></a> <input type="submit" value="Submit Query" /> </h3> </fieldset> </form> </div> <!-- // #main --> <div class="clear"></div> </div> <!-- // #container --> </div> <!-- // #containerHolder --> <p id="footer">Feel free to use and customize it. <a href="http://www.perspectived.com">Credit is appreciated.</a></p> </div> <!-- // #wrapper --> </body> </html> [/php] Hi, Apologies to keep going on about this but I have hit a brick wall over updating my database with XML. I have spent around 100 hours on this and so far I can only copy the file, I am unable so far to update my database with the information from the XML file. I would be very grateful for any help you can offer to fix this. Code: [Select] ----Code so far----> $xmlReader = new XMLReader(); $filename = "datafeed_98057.xml"; $url = "http://www.domain.co.uk/datafeed.xml"; file_put_contents($filename, file_get_contents($url)); $xmlReader->open($filename); while ($xmlReader->read()) { switch ($xmlReader->name) { case'prod': $dom = new DOMDocument(); $domNode = $xmlReader->expand(); $element = $dom->appendChild($domNode); $domString = utf8_encode($dom->saveXML($element)); $prod = new SimpleXMLElement($domString); $id = $prod->prod['id']; $description = $prod->name; $image = $prod->awImage; $fulldescription = $prod->desc; //insert query if(strlen($prod) > 0) { $query = mysql_query("REPLACE INTO productfeed (id, description, fulldescription, image) VALUES ('$id','$description','$image','$fulldescription') "); echo $id . "has been inserted </br>"; } else{echo ("This does not work </br>");} } This is an outline of the XML feed I am using, it only includes one item which I am using as a test: Code: [Select] - <merchant id="1829" name="Pinesolutions.co.uk"> - <prod id="39920873" pre_order="no" web_offer="no" in_stock="yes" hotPick="no" adult="no"> - <text lang="EN"> <name>Oakleigh Wall Mirror 60x90</name> <desc>Mirrors are useful anywhere in the house. Not only are they functional allowing you to see your reflection in order to look your best, they also add elegance to any room theyre placed in. We offer a variety of mirrors to fit your decorating tastes as well as wall space. The Oakleigh Wall Mirror radiates an elegant simplistic style, while offering a generous size glass. The Oakleigh Wall Mirror s frame is crafted from solid hardwood and is lacquered with a protective finish to guard against dust and unexpected stains. The Oakleigh Wall Mirror is versatile and can be hung portrait style at the top of a staircase or landscape. The Oakleigh Wall Mirrors light colour means it also complements all of the furniture in our Camden Painted Range because the range has ash tops. The Oakleigh Wall Mirror has fewer knots than traditional oak wood, but is built just as sturdy so you can be certain it will last you through the generations to come.</desc> </text> - <uri lang="EN"> <awTrack>http://www.awin1.com/pclick.php?p=39920873&a=98057&m=1829</awTrack> <awImage>http://images.productserve.com/preview/1829/39920873.jpg</awImage> <mLink>http://www.pinesolutions.co.uk/bedroom-furniture/mirrors/wall-mirrors/oakleigh-wall-mirror-60x90/</mLink> <mImage>http://media.pinesolutions.co.uk/images/products/903.333.3.4.jpg</mImage> </uri> - <price curr="GBP"> <buynow>40.00</buynow> </price> - <cat> <awCatId>424</awCatId> </cat> <brand /> </prod> </merchant> |