Jump to content

gesseg

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Everything posted by gesseg

  1. Hi Im getting a weird error for this simple bit of code. Error is:"Resource id #6" code is here: http://pastebin.com/T4P44d6h
  2. Thats great! Its working now thanks. I just wish I had a better grasp of why it is now working Dont suppose you want to point me in the right direction to getting the drop down in alphebetical order?
  3. Fixed it sort of. Someone else on another forum had exactly the same problem so copied there revised code. Its still not working properly. It will only return the first word in the "name" field. As above but: while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[name]>name: $nt[name]}</option>"; Now print_r ( $_POST ); gives: Array ( [name] => Coheed [skill] => 10 [counter] => 1 ) I want it to read: ( [name] => Coheed and Cambria [skill] => 10 [counter] => 1 )
  4. Heres vote.php. The code is taken from a tutorial on the web, <form action="insert.php" method="post"> name: <?php $con = mysql_connect("xxx","xxx","xxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a3362005_bands", $con); $query="SELECT name FROM band_data2"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo 'Name:<select name="name">'; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=\"{$nt['id']}\">{$nt['name']}</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> <br /> skill : <select name="skill"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option></select> <input type="hidden" name="counter" value="1"> <input type="submit" /> </form></center> Heres the insert.php <?php $con = mysql_connect("xxx","xxx","xxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a3362005_bands", $con); //Add to the table value with form data. mysql_query("UPDATE band_data2 SET skill = (skill + {$_POST['skill']}) WHERE name='{$_POST['name']}'"); mysql_query("UPDATE band_data2 SET skill_ave = (skill / counter) WHERE name='{$_POST['name']}'"); echo 'vote counted'; mysql_close($con); print_r ( $_POST ); ?> And here is the output from "print_r ( $_POST );" "Array ( [name] => [skill] => 10 [counter] => 1 )" i was told to put this in so i could see what was going on. As you can see the "name" from the dropdown isnt making it to the insert.php.
  5. Thanks but even with your revisions its still not doing what I want. To be honest Ive only been learning for a week. I can follow most of what the script is doing but havent got a clue how to edit to do what I want. What I want is a drop down list populated with my "name" field from my database, once the name is selected I want to pass the "name" data on to insert.php as $_POST data. I did have a text box that was working but in order to update the table you have to, obviously, type the name exactly.
  6. Doesnt it need to be"name" because thats where its getting its data from? i.e. field "name" in database "band_data2". I tried it anyway but it didnt help.
  7. heres my code not sure why it doesnt work... <form action="insert.php" method="post"> name: <?php $con = mysql_connect("xxx","xxx","xxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxx", $con); $query="SELECT name FROM band_data2"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name='name'> Name</option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[id]>$nt[name]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> <br /> skill : <select name="skill"> <option value="">Do they hold their instuments up the right way?</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option></select> <input type="hidden" name="counter" value="1"> <input type="submit" /> </form>
  8. sorry, it does return xml. Ive had a play round with parsing the xml. and ive got the script working but I dont understand enought to make it do what i want I want it to only output the </name> tags. Anyway heres the code i have: <?php $file = "http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=sandi-g&12month&api_key=b25b959554ed76058ac220b7b2e0a026"; function contents($parser, $data){ echo $data; } function startTag($parser, $data){ echo "<b>"; } function endTag($parser, $data){ echo "</b><br />"; } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startTag", "endTag"); xml_set_character_data_handler($xml_parser, "contents"); $fp = fopen($file, "r"); $data = fread($fp, 3368500); if(!(xml_parse($xml_parser, $data, feof($fp)))){ die("Error on line " . xml_get_current_line_number($xml_parser)); } xml_parser_free($xml_parser); fclose($fp); ?>
  9. I doesnt return xml. it would be easier if it did.
  10. Hi I need to pull the top 20 from my last.fm account. Last.fm provide an API key (?) Heres the link to mine http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=sandi-g&api_key=b25b959554ed76058ac220b7b2e0a026 I need to search this string (as html code not what a browser outputs) for "<name>" and then return all character untill the next "<" the search on again for the next "<name>" all the way up to 20. Ive not got very far on this one to be honest. I dont even know how to search it as plain txt. I dont necessarily want some one to do it for me but bare in mind Ive only been coding for a few days.
  11. Thanks very much I knew there would be an easy way to do it.
  12. Hi, Im trying (and failing) to add results from a form to existing results in the table. So if the row "skill" was 10 then the form submitted had a skill value of 5 the table would update to 15. Im sure there is an easy way of doing this but Ive searched the web and canfind one. Heres my code: <?php $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $result = mysql_query("SELECT skill FROM database WHERE name = '$_POST[name]'"); mysql_query("UPDATE database SET skill = '$_POST[skill] + $result' WHERE name = '$_POST[name]'"); mysql_close($con); ?>
  13. error is Error: 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 '(counter, name, *a few other fields*' at line 1 Can you walk me through the bold bits of that PFMaBiSmAd? Thanks.
  14. Hi, Im getting a very odd result here. My code works fine and does what its supposed to when I use INSERT INTO (for my mysql table) but if i change that to UPDATE it breaks. Heres the code: <?php $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $sql="update table (counter, name) VALUES ('$_POST[counter]','$_POST[name]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo 'You entered the following votes:' . '<br />'; echo 'name ' . $_POST[name] . '<br />'; mysql_close($con) ?> Its really stumped me.
  15. Your registration form is broken for one thing.
  16. Hi Im new to php and any sort of programing actually. Ive bee working through tutorials on the net and mostly getting the correct results . I need to know if php and mysql will do everything I need. I need to create a game lobby witch waits for 5 players to click "start game" then once there is 5 a non graphical, unique game is started. Once a player wins a +1 stat is added to his user profile.
×
×
  • 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.