Jump to content

lawler_09

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

lawler_09's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. <?php function doQuery($query) { $result = ""; $conn = @mysql_connect('xxx', 'xxx', 'xxx'); if($conn==false) { $result = false; } else { $db = mysql_select_db("xxx"); if($db==false) { $result = false; } else { $rows = mysql_query($query); if($rows==false) { $result = false; } else { $result = $rows; } } } return $result; } ?> works fine on every other page when connectiong to db
  2. it just seems odd cause i use the include functions.php to connect to the database, which works perfectly on all the other pages
  3. thanks again for your help. few things. in the text box on the form i'm wanting it to be blank and the user only puts a value in if they want to change the stock level. if no value is put in the text box then it is ignored. as far as i understand your code your wanting me to echo in the stock value, which is already displayed in the previous column. but i tried what you put anyway, and it just cycled through the query, but didnt work. i put in echo mysql_error(); after the query and it returned 'database not selected', and cant figure out why
  4. thanks for your help as well. in my form i have echo "<td style=\"text-align: center;\"><input type=\"text\" name=\"item_new_stock_total\" style=\"width:20px\"></td>"; echo "<td style=\"text-align: center;\"><input type=\"hidden\" name=\"item_id[" . $row['item_id'] . "]\" style=\"width:20px\"></td>"; then in the page it posts to i have: extract($_POST); include("functions.php"); $items = $_POST['item_new_stock_total'];foreach($items as $key => $val){ mysql_query("UPDATE items SET item_stock = '$val' WHERE item_id = '$key'");} echo mysql_error(); i dont know how to do the escaping you mentioned in step 2. apologises as im really new to php.
  5. thanks for all your help so far. ive just tried that now and it just ignores it. should i be changing $val + $key to something else?
  6. I understand that i'll need mutliple queries and your train of thought. The issue i'm having is that the id and new stock value will be different every single time. I'll attempt to show you what i have so far (excuse the amateur coding, like i said im new aha) <?php $query = "SELECT * FROM items"; $result = doQuery($query); if($result==false) { echo mysql_error(); } else { $rowcount = 1; while($row=mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td style=\"text-align: center;\">".$row['item_id']."</td>"; echo "<td style=\"text-align: center;\">".$row['item_model']."</td>"; echo "<td style=\"text-align: center;\">".$row['item_code']."</td>"; echo "<td style=\"text-align: center;\">".$row['item_colour']."</td>"; if ($row['item_stock']=="2") echo "<td style=\"text-align: center;\"><font color =\"#d50031\">"."<b>".$row['item_stock']."</b>"."</font></td>"; elseif ($row['item_stock']=="1") echo "<td style=\"text-align: center;\"><font color =\"#d50031\">"."<b>".$row['item_stock']."</b>"."</font></td>"; elseif ($row['item_stock']=="0") echo "<td style=\"text-align: center;\"><font color =\"#d50031\">"."<b>"."Out Of Stock"."</b>"."</font></td>"; else echo "<td style=\"text-align: center;\"><font color =\"#009933\">"."<b>".$row['item_stock']."</b>"."</font></td>"; ?><form class="cmxform" id="signupForm" method="post" action="../../php/query.php"> <?php echo "<td style=\"text-align: center;\"><input type=\"text\" name=\"item_new_stock_total\" style=\"width:20px\"></td>"; echo "</tr>"; $rowcount++; } } ?> </table> <p align="right" style="padding-right: 49px;"> <input class="submit" type="submit" value="Submit" id="button_style" /> </p> </form> so i'd pass the value in the text box for item_new_stock_total and the id to another php page to do the query. so for example the page might look: (ID) (Model) (current stock level) (new stock level) 1 AAA 3 [ ] 2 BBB 1 [4] 3 CCC 4 [ ] 4 DDD 4 [2] 5 EEE 5 [ ] [sUBMIT BUTTON] so when i click the submit button it updates the rows with id 2 and 4 with replace the current stock levels with the value in the new stock level. but the week after the same page might look like this: (ID) (Model) (current stock level) (new stock level) 4 DDD 3 [1] 6 FFF 1 [ ] 7 GGG 4 [ ] 8 HHH 4 [ ] 9 III 5 [2] 11 GHF 4 [ ] 13 DFE 4 [3] [sUBMIT BUTTON] so when i click the submit button this time it updates the rows with id 4, 9 and 13 with the values, each time ignoring the rows with dont have anything entered in the new stock level column Hope this was easy enough to understand!!
  7. it could be different every time. for example, tomorrow there might be 10 records displayed and you want to change to stock level of row 1,3,5,8 and 9 with the number in the new stock level, and ignore rows 2,4,6,7 and 10 as they don't have anything in the new stock level text box. but next week there may be 20 records/rows returned and you want to change rows 1 and 2 and ignore the rest of the rows. thanks for your help so far as well!
  8. how do you mean same data? the numbers going in to the 'new stock level' would be different every time as well as which row is being update. so the first 3 rows might be updated and every other row ignored. also the id numbers are slightly different to just 1,2,3, and rows would change all the time as models come and go.
  9. Hi guys, Doing a small project and i'm pretty new to php/mysql so hoping someone can help. Also i wasn't sure if this should be in php section or mysql, so apologises if it's in the wrong section. Basically... I have a form with a table in it with the fields (id, model, current stock level, new stock level) The table is populated using a mysql query to get the data from 1 table in a database. In the new stock column there's a simple text box to put a number in. Sooo like (ID) (Model) (current stock level) (new stock level) 1 AAA 3 [ ] 2 BBB 1 [ ] 3 CCC 4 [ ] A user will then put a new number in the 'new stock level' text box and when it gets submitted the new number replaces the number in 'current stock level' Basically i know how to do it if it was just the one record, but how do i get it to update all the ones with numbers in the new stock level column at the same time, and ignore it if it doesn't have anything entered in the text box? appreciate any help! thanks!
  10. really? its for a college project, and basically theres 4 different types of accounts, with different fields in each. when they log in, it picks up what kind of account they have, and takes them to a seperate account page for that particular type of account.
  11. when someone enters an email address and password, i want the script to check each of the 4 tables for what was entered, and then forward them somewhere depending on which table it was found in, or if it wasnt found in any then to another page <?php session_start(); $_SESSION['loggedin'] = false; include("functions.php"); extract($_POST); $query = "SELECT * From table1 WHERE email='$email' and password='$password';"; $result = doQuery($query); if($result==false) { $query = "SELECT * From table2 WHERE email='$email' and password='$password';"; $result = doQuery($query); if($result==false) { $query = "SELECT * From table3 WHERE email='$email' and password='$password';"; $result = doQuery($query); if($result==false) { $query = "SELECT * From table4 WHERE email='$email' and password='$password';"; $result = doQuery($query); if($result==false) { } else { if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['loggedin'] = true; $_SESSION['id'] = $_POST['id']; header("Location:1"); } else { header("Location:wrong.php"); } } } else { if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['loggedin'] = true; $_SESSION['id'] = $_POST['id']; header("Location:2"); } else { header("Location:wrong.php"); } } } else { if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['loggedin'] = true; $_SESSION['id'] = $_POST['id']; header("Location:3"); } else { header("Location:wrong.php"); } } } else { if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['loggedin'] = true; $_SESSION['id'] = $_POST['id']; header("Location:4"); } else { header("Location:wrong.php"); } } ?>
  12. sorry is there anyway i can edit my post? and no they have different coloumns
  13. hi guys, any help will be much appreciated!! basically i have a login script, that i want to check mutliple tables and i am stuggling to get it to work! what i have is basically: <?php session_start(); $_SESSION['loggedin'] = false; include("functions.php"); extract($_POST); $query = "SELECT * From table1 WHERE email='$email' and password='$password';"; $result = doQuery($query); if($result==false) { $query = "SELECT * From table2 WHERE email='$email' and password='$password';"; $result = doQuery($query); if($result==false) { $query = "SELECT * From table3 WHERE email='$email' and password='$password';"; $result = doQuery($query); if($result==false) { $query = "SELECT * From table4 WHERE email='$email' and password='$password';"; $result = doQuery($query); if($result==false) { } else { if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['loggedin'] = true; $_SESSION['id'] = $_POST['id']; header("Location:1"); } else { header("Location:wrong.php"); } } } else { if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['loggedin'] = true; $_SESSION['id'] = $_POST['id']; header("Location:2"); } else { header("Location:wrong.php"); } } } else { if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['loggedin'] = true; $_SESSION['id'] = $_POST['id']; header("Location:3"); } else { header("Location:wrong.php"); } } } else { if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); $_SESSION['loggedin'] = true; $_SESSION['id'] = $_POST['id']; header("Location:4"); } else { header("Location:wrong.php"); } } ?>
×
×
  • 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.