Jump to content

stevens

Members
  • Posts

    20
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

stevens's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Works perfectly now!! There was an error as it couldnt find "name" field, so i changed it to "word" and it worked! my fault for changing the name field to word half way through coding!! Thanks a million for your help.
  2. Still doesnt work ??? yet there is no error message either. Im lost now, I have no idea why it is not working. Thanks for your help though.
  3. [quote author=king arthur link=topic=103338.msg411447#msg411447 date=1154994071] [code] $names_array = explode(",", $names); $result = mysql_query("select id from mytable order by id"); $i = 0; while($row = mysql_fetch_assoc($result)) { $r = mysql_query("update mytable set name=" . $names_array[$i] . " where id=" . $row["id"]); } [/code] See if that works. Obviously change "mytable" to the name of your table.[/quote] Hi, no errors show, but it does not update the database, any ideas? Thanks. This is my code: [quote]$words = $_POST['words']; $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db, $connection); if ($words) { $word_array = explode(",", $words); $result = mysql_query("SELECT id FROM details ORDER BY id"); $i = 0; while($row = mysql_fetch_assoc($result)) { $r = mysql_query("UPDATE details SET word=" . $word_array[$i] . " WHERE id=" . $row["id"]); } }[/quote] Do i need to do $i + 1 in the mysql_fetch_assoc? so its adds 1 each row?
  4. [quote author=ToonMariner link=topic=103338.msg411424#msg411424 date=1154991425] so if you generate you query string in a doo loop you could do it all pretty quickly. [/quote] How would i do this in a do loop?
  5. [quote author=king arthur link=topic=103338.msg411436#msg411436 date=1154991765] Ok, well are all the id fields in contiguous order? Then you could do it as ToonMariner says, with a loop incrementing the id for each query. If not, then pull all the id's out first and then update the rows with names for each id you pulled out. [/quote] Ok I have managed to get all my current names into a text field seperated by a comma (,) Now i need to insert these into the table (yes the id fields are in contiguous order). How can insert these into the db? at the moment they are all stored together in the variable $names seperated by a comma. If i do an explode to seperate each of the names i am going to have to do it 400 times, there must be an easier way?
  6. [quote author=ToonMariner link=topic=103338.msg411424#msg411424 date=1154991425] no you would need to change each name individually BUt you can do it in one query. $qry = "UPDATE table SET name = 'tom' WHERE id='1'"; $qry = mysql_query($qry); That is your query to update an individual record. Now you could have: $qry = "UPDATE table SET name = 'tom' WHERE id='1';"; $qry .= "UPDATE table SET name = 'dick' WHERE id='2';"; $qry .= "UPDATE table SET name = 'harry' WHERE id='3';"; $qry = mysql_query($qry); so if you generate you query string in a doo loop you could do it all pretty quickly. [/quote] So i could create a text area and input 400 names seperated by a comma. Then do an explode function on the commas and i would get 400 variables i could insert into the 400 query's. Is that correct?
  7. [quote author=king arthur link=topic=103338.msg411422#msg411422 date=1154991347] How are the list of names defined? [/quote] ??? currently i do not have a list of names to input. I was thinking of creating a text field where i could enter the names seperated by a comma and then input this into the query. Is that what you mean?
  8. Hi I hope you can help me. I need to update 1 field in every record of my database, how can i do this? I have the following fields in my table: id name address email I want to update the 'name' field in every record in the table (around 400) each with a different name. Could i use something like this: [quote]$query = "UPDATE table SET name = 'tom', name = 'bob', name = 'john', etc...";[/quote] Somehow i dont think the above query will work  :-[, lol. So how can i do this? thanks.
  9. Hi everyone and thanks for your help, Unfortunatly none of your answers worked. My database is being called in the config.php for you who were not sure. @wildteen I changed my code to what you posted but still got the same error - Isnt the code you posted the same as what i already had? thanks anyway. [size=18pt][color=red][b]EDIT: I HAVE SORTED IT NOW, I FOUND THE ERROR. THE ERROR WAS THE SECOND QUERY & RESULT NAME. I CHANGED IT TO QUERY2 & RESULT2 AND NO ERRORS  ;D THANKS AGAIN FOR YOUR HELP GUYS[/b][/color][/size]
  10. Hi I am running the script below and it works perfectly (updates the database ok) yet displays the following error, please help me undertsand why. Thankyou. (The code is to be run by a cron job to check whether an account has expired) Error Message: [quote]PHP Warning:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /2.php on line 9[/quote] Code: [quote]<?php include("config.php"); $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); $query = "SELECT * FROM details WHERE order_no != 0"; $result = mysql_db_query($db, $query, $connection) or die ("Could not execute query: $query. " . mysql_error()); while ($newArray = mysql_fetch_assoc($result)) {      $order_no = $newArray['order_no']; $word = $newArray['word'];      $email = $newArray['cust_email'];     $start_date = $newArray['start_date']; $end_date = $newArray['end_date']; $date = date("Y-m-d"); if ($end_date == $date) { $query = "DO QUERY"; $result = mysql_db_query($db, $query, $connection) or die ("Could not execute query: $query. " . mysql_error());     $subject = "YOUR ACCOUNT HAS NOW EXPIRED"; $msg = "THE ACCOUNT YOU HAVE PURCHASED ON ".$domain." HAS NOW EXPIRED\n\n";     mail($email, $subject, $msg, "From: ".$orderemail); } else { $days_left = (strtotime($end_date) - strtotime(date("Y-m-d"))) / (60 * 60 * 24); if ($days_left == '30') {     $subject = "YOUR ACCOUNT IS EXPIRING IN 30 DAYS"; $msg = "THE ACCOUNT YOU HAVE PURCHASED ON ".$domain." IS EXPIRING IN 30 DAYS\n\n";     $msg.= "PLEASE LOGIN TO YOUR MEMBERS ACCOUNT NOW\n\n";     mail($email, $subject, $msg, "From: ".$orderemail); } } echo "$days_left"; } ?> [/quote]
  11. How can i make this return cost_check if they dont match? This doesnt work: [code]if (!$cost_check == $status) {     echo "$cost_check"; } else { echo "ok";      } }[/code]
  12. Houdini thankyou for your reply, i understand that now.
  13. The status = "test" works fine, but i will change it to == anyway. The problem seems to be with the brackets and || maybe?
  14. Hi there is something wrong with my if statement, please let me know what it is!! It doesnt echo denied! Im trying to only get accepted; if status doesnt = "test" and it is authorised. [code] $status = $_POST['status']; if ((!strstr($response, "AUTHORISED"))||($status = "test")) {     echo "denied"; } else {     echo "accepted"; } [/code]
×
×
  • 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.