Jump to content

RON_ron

Members
  • Posts

    370
  • Joined

  • Last visited

Everything posted by RON_ron

  1. Thanks. but now the $codeNumber is red as jack\'s154879? Not outputting the desired results whenever there is an apostrophe (') in the $codeNumber variable.?
  2. my code $query = "SELECT SUM(furnitureA) AS furnitureA FROM items WHERE quantity = '$codeNumber'"; $result = mysql_query($query); $rBf = mysql_fetch_array($result); // ERROR: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in.... This usually happens whenever there's an apostrophe (') in $codeNumber (E.g. if $codeNumber = jack's154879). How do i overcome this?
  3. I need to read a column name (in my db) using a variable. How can I do it. Below is my code. Eg. Name of the column which I need to update is "AppleFruitProducts" variable sent to the php containing the word "AppleFruit" is in: $category = mysql_real_escape_string($_POST['categories']); My code: $outlet = mysql_real_escape_string($_POST['outlets']); $category = mysql_real_escape_string($_POST['categories']); $catName = "Products"; $newColumnName = $category.$catName; $availability = "3"; $query = sprintf("UPDATE db5 SET $newColumnName=".'$availability'.", WHERE Outlet ='%s'", mysql_real_escape_string($outlet));
  4. This is the error message when I did a echo mysql_error(); command denied to user 'abcb_showrooms'@'localhost' for table 'data'
  5. I'm trying to delete a complete row from 3 databases. But it's not functioning. I can't see an error. Could someone help? $sperson = mysql_real_escape_string($_POST['sperson']); $sqlA="DELETE FROM showrooms WHERE salesperson = '".$sperson."'"; $result1=mysql_query($sqlA); $sqlB="DELETE FROM supplier WHERE salesperson = '".$sperson."'"; $result2=mysql_query($sqlB); $sqlC="DELETE FROM data WHERE salesperson = '".$sperson."'"; $result3=mysql_query($sqlC); if($result1 && $result2 && $result3){ $login = "Success"; echo($login); } else { $login = "failed"; echo($login); };
  6. this is my code so far. something is still wong here. Can someone help? <?php require_once("doc.php"); foreach ($_POST as $key => $value) { $$key = $value; } $query = "UPDATE db1 SET "; for($i=0;$i<30;$i++){ if(isset(${"codeID_".$i})){ $query .= "item= '".${'item_'.$i}."' WHERE Code ='".${'codeID_'.$i}."'"; if (${'item_'.$i}.==2) { $query = "UPDATE db2 SET availability='Stage 1' WHERE Code ='".${'codeID_'.$i}."'"; } else if (${'item_'.$i}.==3) { $query = "UPDATE db2 SET availability='Stage 3' WHERE Code ='".${'codeID_'.$i}."'"; } } } $query = substr($query, 0, -2); $result= mysql_query($query); ?>
  7. Hello All For some reason the below code does not update the db? What am I doing wrong? I trying to update 30 records in 2 databases uring loop. The data is sent as item_0, item_1,..... and codeID_0, codeID_1, etc.... foreach ($_POST as $key => $value) { $$key = $value; } $query = "UPDATE db1 SET "; for($i=0;$i<30;$i++){ if(isset(${"codeID_".$i})){ $query .= "item='" .${'item_'.$i}."' WHERE Code ='".${'codeID_'.$i}.'","; if ('" .${'item_'.$i}."'==2) { $query = "UPDATE db2 SET availability='Stage 1' WHERE Code ='".${'codeID_'.$i}.'","; } else if ('" .${'item_'.$i}."'==3) { $query = "UPDATE db2 SET availability='Stage 3' WHERE Code ='".${'codeID_'.$i}.'","; } } } $query = substr($query, 0, -2); $result= mysql_query($query);
  8. yes i did. all which comes to $ar1 are dataA and $ar2 are dataB
  9. the output shows that those are arrays. array(0) { } array(0) { } Any idea why isn't the code working?
  10. OUTPUT string(3) "ar1" string(3) "ar2" What does this mean? if (isset($_POST['DataA']) && is_array($_POST['DataA'])) { foreach ($_POST['DataA'] as $key => $value) { if (is_string($value) && $value != "") { $ar1[$key] = $value; } } } echo var_dump(ar1)."<br>"; $ar2 = array(); if (isset($_POST['DataB']) && is_array($_POST['DataB'])) { foreach ($_POST['DataB'] as $keys => $values) { if (is_string($values) && $values != "") { $ar2[$keys] = $values; } } } echo var_dump(ar2)."<br>";
  11. the POST values doesn't seem to be going in to the arrays? Any idea why? $ar1 = array(); if (isset($_POST['DataA']) && is_array($_POST['DataA'])) { foreach ($_POST['DataA'] as $key => $value) { if (is_string($value) && $value != "") { $ar1[$key] = $value; } } } $ar2 = array(); if (isset($_POST['DataB']) && is_array($_POST['DataB'])) { foreach ($_POST['DataB'] as $keys => $values) { if (is_string($values) && $values != "") { $ar2[$keys] = $values; } } } $n=0; foreach ($ar1 as $thing) { $bigar[$n][1] = $thing; $n++; } $n=0; foreach ($ar2 as $thing) { $bigar[$n][2] = $thing; $n++; } foreach ($bigar as $part) { $query = sprintf("UPDATE db1 SET code='%s' WHERE name ='%s'", mysql_real_escape_string($part[2]), mysql_real_escape_string($part[1])); $result = mysql_query($query); }
  12. Thank you requinix. I'm getting an error and I dodn't know how to fix it? (Warning: Invalid argument supplied for foreach()) Here's what I'm trying to achieve; 1. DataA This is the students ID and DataB is the student name. 2. In my form there are 25 rows to enter the student IDs and student names. When the submit button is clicked, it brings all the data to this php (below). 3. I want this PHP to be able to search the student name and update the ID accordingly for all the 25 students. //all input data is DataA and DataB. $ar1 = array(); if (isset($_POST['DataA']) && is_array($_POST['DataA'])) { foreach ($_POST['DataA'] as $key => $value) { if (is_string($value) && $value != "") { $ar1[$key] = $value; } } } $ar2 = array(); if (isset($_POST['DataB']) && is_array($_POST['DataB'])) { foreach ($_POST['DataB'] as $keys => $values) { if (is_string($values) && $values != "") { $ar2[$keys] = $values; } } } $n=0; //Warning: Invalid argument supplied for foreach() foreach ($ar1 as $thing) { $bigar[$n][1] = $thing; $n++; } $n=0; //Warning: Invalid argument supplied for foreach() foreach ($ar2 as $thing) { $bigar[$n][2] = $thing; $n++; } foreach ($bigar as $part) { //Warning: Invalid argument supplied for foreach() $query = sprintf("UPDATE db1 SET code='%s' WHERE name ='%s'", mysql_real_escape_string($part[2]), mysql_real_escape_string($part[1])); $result = mysql_query($query); }
  13. in my submit form I have manditory fields and some optional fields. I want to create an array of only all the non empty inputs. Doesn't work. $a1 = array(); for (i=0; i<25; i++) { if ($_POST['dataA']+$i != "") { $a1[] = ['dataA']+$i; $a1[$key] = ['dataA']+$i; } }
  14. could someone help me out? I'm getting an error for these 3 lines foreach ($ar1 as $thing) { foreach ($ar2 as $thing) { foreach ($bigar as $part) { Warning: Invalid argument supplied for foreach()
  15. is this a good way of doing it? $ar1 = array(1,2,3,4,5); $ar2 = array(9,8,7,6,5); $n=0; foreach ($ar1 as $thing) { $bigar[$n][1] = $thing; $n++; } $n=0; foreach ($ar2 as $thing) { $bigar[$n][2] = $thing; $n++; } foreach ($bigar as $part) { //echo $part[1].$part[2]; $query = sprintf("UPDATE studentbackup13 SET code='%s' WHERE name ='%s'", mysql_real_escape_string($part[1]), mysql_real_escape_string($part[2])); $result = mysql_query($query); }
  16. I want to send 25 students records in to the mySQL in one go. I used a for loop to do this. This is what I've tried so far and no success. Could someone help? require_once("accessLocal.php"); for (i=0; i<25; i++) { $student+$i = mysql_real_escape_string($_POST['student'+$i]); $subjectID+$i = mysql_real_escape_string($_POST['subjectID'+$i]); $query = sprintf("UPDATE studentbackup13 SET code='%s' WHERE name ='%s'", mysql_real_escape_string($subjectID+$i), mysql_real_escape_string($student+$i)); $result = mysql_query($query); }
  17. I'll getting data from two different databses. Code A is the current code (works well). After doing some modifications (Code B), now the code outputs nothing . Could someone help to correct the error in Code B? Code A $query = "SELECT * FROM furniture LEFT OUTER JOIN furnitureBrands ON furniture.itemCode = furnitureBrands.theName ORDER BY furniture.key DESC; $results = mysql_query($query); Code B $query = "SELECT * FROM furniture LEFT OUTER JOIN furnitureBrands ON furniture.itemCode = furnitureBrands.theName WHERE furniture.checked = '0', furniture.availability = 'yes' ORDER BY furniture.key DESC; $results = mysql_query($query); Thanks.
  18. it's strange.... echo works.... is there anything wrong in that piece of code?
  19. Could someone tell what's wrong with the below code? it's not updating the database? $result = sprintf("UPDATE student_db1 SET completed='Yes', name='".$sname."' WHERE id ='%s'", mysql_real_escape_string($sid)); $results = mysql_query($result);
  20. RON_ron

    JOIN WHERE

    oops.... I get an error. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ...... line: while($line = mysql_fetch_array($results)) {
  21. RON_ron

    JOIN WHERE

    Can someone help to fix this piece of code... Does not work? $checkStudent = "Malakai"; $query = "SELECT * FROM gifts_db LEFT OUTER JOIN grade_db ON gifts_db.student = grade_db.Student WHERE gifts_db.student = ".$checkStudent; $results = mysql_query($query); while($line = mysql_fetch_array($results)) { //// }
  22. ORDER BY is not giving me the expected results. Have I done it correctly? $query = "SELECT * FROM gift_db2 LEFT OUTER JOIN student_db ON gift_db2.category = student_db.name ORDER BY gift_db2.category DESC, gift_db2.grade DESC";
  23. you mean $link = mysqli_connect("localhost", "my_user", "my_password", "world");
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.