Jump to content

Fearpig

Members
  • Posts

    195
  • Joined

  • Last visited

Everything posted by Fearpig

  1. Hi Guys, Can anyone help me? I've been struggling through various tutorials and I'm stuck on editing MySQL data with PHP. Can someone take a looka t the code below and suggest where I'm going wrong?  :) <? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","root","password"); mysql_select_db("Telephonelist"); //If cmd has not been initialized if(!isset($cmd)) {   //display all the people   $result = mysql_query("SELECT * FROM tbl_telephonenumbers ORDER BY ID");     //run the while loop that grabs all the news scripts   while($r=mysql_fetch_array($result))   {       //grab the title and the ID of the news       $First=$r["First_Name"];//take out the title   $Last=$r["Last_Name"];//take out the title       $ID=$r["ID"];//take out the id     //make the title a link       echo "<a href='Edit_SpecificPerson.php?cmd=edit&ID=$ID'>$First $Last</a>";       echo "<br>";     } } //If cmd has been initialized if(isset($cmd)) { if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") {   if (!isset($_POST["submit"]))   {       $id = $_GET["ID"];       $sql = "SELECT * FROM tbl_telephonenumbers WHERE ID=$ID";       $result = mysql_query($sql);              $myrow = mysql_fetch_array($result);       ?>         <form action="Edit_SpecificPerson.php" method="post">       <input type=hidden name="id" value="<?php echo $myrow["ID"] ?>">         First Name:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["First_Name"] ?>" SIZE=30><br>       Last Name:<INPUT TYPE="TEXT" NAME="message" VALUE="<?php echo $myrow["Last_Name"] ?>" SIZE=30><br>       Role:<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["Role"] ?>" SIZE=30><br>           <input type="hidden" name="cmd" value="edit">         <input type="submit" name="submit" value="submit">             </form>   <? } } if(isset($submit)) {   if ($_POST["$submit"])   {       $First = $_POST["First_Name"];   $Last = $_POST["Last_Name"];   $Role = $_POST["Role"];     $sql = "UPDATE tbl_telephonenumbers SET First_Name='$First',Last_Name='$Last',Role='$Role' WHERE ID=$ID";       //replace news with your table name above       $result = mysql_query($sql);       echo "Thank you! Information updated."; } } } ?> The first two pass throughs it works OK. - On the first pass it list all the names as a link. - On the second pass it populate text boxes with the details you selected (by which name you clicked on) - On the third pass it fails. This is when you click submit and the database should be updated with any changes made into the text boxes. This is the error page that comes up: Notice: Undefined index: cmd in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 31 Notice: Undefined index: First_Name in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 61 Notice: Undefined index: Last_Name in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 62 Notice: Undefined index: Role in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 63 Notice: Undefined variable: ID in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 65 Thank you! Information updated. - the information is not updated and any help will be REALLY appreciated as I've been hacking at this for days now and it all seems a bit of a blur! Cheers Tom
  2. Nope it didn't like that one....... Notice: Undefined index: id in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 4 Notice: Undefined index: first_name in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 5 Notice: Undefined index: last_name in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 6 Notice: Undefined index: role in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 7 Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 9 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 9 Unable to update the users information Do you know where I can find a tutorial that I can follow as oppose to bugging you every few minutes! It looks as though I need to go through all of the basics again? Thanks again for your help. Tom
  3. Aaaaaarrrrrgggggghhhhh............ I'm sooo close to cracking this now! The problem seems to be now that when you click on submit the php file refers to itself but fails when it gets to the $id variable as that is defined on the page before. (I now get the error message: Notice: Undefined index: id in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 23 which is this line: $result = mysql_query("SELECT * FROM tbl_telephonenumbers WHERE ID='$id'",$db); ) Any ideas on this one....?
  4. Cheers for that tomfmason, It looks as though that what I'm after. I'm now getting a new error though. Notice: Undefined index: PHPSELF in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 28 Do you know what this is? I'm sure I've had it before but can't remember how to resolve it! Cheers again though. Tom
  5. Hello again Guys, I'm stuck yet again!! I've now created the following code to populate three textboxes with data from a row in MySQL (linked through the $id from the page before). I now want to edit these fields, click submit and have it update the row in the database. <html> <head> </head> <body> <?php $db = mysql_connect("localhost", "root", "password"); $id = $_GET['id']; mysql_select_db("Telephonelist",$db); $result = mysql_query("SELECT * FROM tbl_telephonenumbers WHERE ID='$id'",$db); $myrow = mysql_fetch_array($result) ?> <form action="Edit_SpecificPerson.php" method="post"> <INPUT TYPE="HIDDEN" NAME="ID" VALUE="<?php echo $myrow["ID"] ?>"><br>  <INPUT TYPE="TEXT" NAME="First_Name" VALUE="<?php echo $myrow["First_Name"] ?>" SIZE=30><br> <INPUT TYPE="TEXT" NAME="Last_Name" VALUE="<?php echo $myrow["Last_Name"] ?>" SIZE=30><br> <INPUT TYPE="TEXT" NAME="Role" VALUE="<?php echo $myrow["Role"] ?>" SIZE=30><br> <input type="Submit" value="Update"> </form>   </body> </html> I know I need another SQL query like: $query="UPDATE contacts SET First_Name='$ud_first', Last_Name='$ud_last', Role='$ud_role' WHERE id='$ud_id'"; But how do I include it into this page and tie it to the submit button? If anyone could suggest some code or a tutorial I would be very grateful. Cheers. Tom.
  6. Doh! Thank you guys I think the process of writing it out again unblocked something and I managed to work it out. It was that I was just missing the line: $myrow = mysql_fetch_array($result) Which should be at the start where I declare my variables. Cheers for your help.
  7. I'm sorry... I don't understand.... ??? Could you repost the code and show me how you got no errors.
  8. Hi Guys, Can anyone help me with the following? I'm trying to set up a PHP page where you can edit data stored in an SQL table. Here's my code... <?php $db = mysql_connect("localhost", "root", "password"); $id = $_GET['id']; mysql_select_db("Telephonelist",$db); $result = mysql_query("SELECT * FROM tbl_telephonenumbers WHERE ID='$id'",$db); ?> <form action="Submit_SpecificPerson.php" method="post"> <INPUT TYPE="HIDDEN" NAME="ID" VALUE="<?php echo $myrow["ID"] ?>"><br>  <INPUT TYPE="TEXT" NAME="First_Name" VALUE="<?php echo $myrow["First_Name"] ?>" SIZE=30><br> <INPUT TYPE="TEXT" NAME="Last_Name" VALUE="<?php echo $myrow["Last_Name"] ?>" SIZE=30><br> <INPUT TYPE="TEXT" NAME="Role" VALUE="<?php echo $myrow["Role"] ?>" SIZE=30><br> <input type="Submit" value="Update"> </form> The page before passes through the 'id' variable and this page should populate three text boxes with the values stored in the database. The problem is that when I get to this page the textboxes only have the following error message: <br /><b>Notice</b>:  Undefined variable: myrow in <b>D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php</b> on line <b>17</b><br /> With a different line in each textbox (lines 15, 16 and 17). If anyone can spot where I'm going wrong I'd be very grateful. Cheers Tom
  9. Hello guys, Can someone take a look at my code and point me in the right direction? I'm reading through various tutorials on the web and trying to make my own pages to edit data in a MySQL database. The page before this one brings up a list of names and when the user clicks on one it opens the page below with a variable called "id" specifying which record to show. [b]<?php $db = mysql_connect("localhost", "root", "password"); $id = $_GET['id']; mysql_select_db("Telephonelist",$db); $result = mysql_query("SELECT * FROM tbl_telephonenumbers WHERE ID=$id",$db); <form action="Submit_SpecificPerson.php" method="post"> <INPUT TYPE="HIDDEN" NAME="ID" VALUE="<?php echo $myrow["ID"] ?>">  <INPUT TYPE="TEXT" NAME="First_Name" VALUE="<?php echo $myrow["First_Name"] ?>" SIZE=30><br> <INPUT TYPE="TEXT" NAME="Last_Name" VALUE="<?php echo $myrow["Last_Name"] ?>" SIZE=30><br> <INPUT TYPE="TEXT" NAME="Role" VALUE="<?php echo $myrow["Role"] ?>" SIZE=30><br> <input type="Submit" value="Update"> </form> ?>[/b] When I run this page I get the following error: Parse error: parse error, unexpected '<' in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 16 [b]line 16 is the line beginnning "<form action=......."[/b] Any help with this would be greatly appreciated as I'm just stuck at the moment! Cheers.
  10. Thank you Wildteen.... only just started with PHP and I was scratching my head. Do you know of any good up-to-date tutorials?
  11. Hello, I'm currently working through the PHP SQL tutorial at the address below: http://webmonkey.wired.com/webmonkey/99/21/index2a.html but I'm getting stuck on one of the earlier lessons. I've posted my code below (slightly changed from the tutorial). Would someone take a look at it please and see if they spot the problem? When I run the file I get the two following error messages: [color=red]Notice: Undefined variable: id in D:\Intranet v3\php_telephone_list\Lesson4b.php on line 13 Notice: Undefined variable: PHP_SELF in D:\Intranet v3\php_telephone_list\Lesson4b.php on line 37[/color] <html> <head> </head> <body> <?php $db = mysql_connect("localhost", "root", "password"); mysql_select_db("Telephonelist",$db); // display individual record if ($id) {   $result = mysql_query("SELECT * FROM tbl_telephonenumbers WHERE ID=$id",$db);   $myrow = mysql_fetch_array($result);   printf("First name: %s\n<br>", $myrow["First_Name"]);   printf("Last name: %s\n<br>", $myrow["Last_Name"]);   printf("Address: %s\n<br>", $myrow["Address_1"]);   printf("Position: %s\n<br>", $myrow["Role"]); } else {     // show employee list   $result = mysql_query("SELECT * FROM tbl_telephonenumbers",$db);     if ($myrow = mysql_fetch_array($result)) {       // display list if there are records to display       do {         printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $myrow["ID"], $myrow["First_Name"], $myrow["Last_Name"]);       } while ($myrow = mysql_fetch_array($result));     } else {     // no records to display       echo "Sorry, no records were found!";     } } ?> </body> </html>
  12. I'm running all the latest versions: MySQL 5.0.21 IIS 6.0 PHP 5.1.4 Could it be the PHP extension for MySQL thats not running properly?
  13. Hello again Redarrow..... Here's the SQL part of the php.ini file (I took out the comments so you can see more easily). [MySQL] mysql.allow_persistent = On mysql.max_persistent = -1 mysql.max_links = -1 mysql.default_port = mysql.default_socket = mysql.default_host = mysql.default_user = mysql.default_password = mysql.connect_timeout = 60 mysql.trace_mode = Off So it has got the 60 second time-out that you mentioned. It shouldn't be a problem for the database to process as there is only one table in there with 20 records. There will be more records when I know its running. Any other ideas...?
  14. Right then....  :-\ I've tried following the tutorials which all seem to be for slightly different version of the software compared to mine. I've also reinstalled IIS, PHP and MySQL and I still get the same error. I've gone back to the PHP.ini file and made the following extensions active: extension=php_mssql.dll extension=php_msql.dll extension=php_mysql.dll However when I search my system I cannot find php_mysql.dll...? I can connect and get data from an Access file via ODBC which shows that php and iis should be working together correctly. I'm running "EMS SQL Manager 2005 for MySQL" which allows me to upload and change the database in MySQL.  Can anyone tell me where I'm going wrong....... Please help as I'm on the verge of giving up on PHP and using ASP as I want to get on with site designing.
  15. Sorry Redarrow! There is a load of stuff on the website you linked!! Just getting frustrated and skipping through stuff....! Thanks again for your help on this. Tom.
  16. Hello again, The site looks good with good descriptions but it doesn't help me as I'm running IIS and there's nothing on configuring that.  :-[ Can anyone tell me a website with a tutorial detailing how to get MySQL5, PHP5 and IIS6 working together.
  17. Nope..... Did you mean the libmySQL.dll file from the MySQL Server bin? Do you know of any good tutorials on the setup of PHP / MySQL? Thanks for your help Redarrow.
  18. Hello, I'm hoping that someone can help me with this  :) I've installed MySQL and PHP5 using the standard windows install executables and I'm now trying to configure PHP so that MySQL is enabled. So far I've edited the PHP.ini file as shown below: ;extension=php_mbstring.dll ;extension=php_bz2.dll ;extension=php_curl.dll ;extension=php_dba.dll ;extension=php_dbase.dll ;extension=php_exif.dll ;extension=php_fdf.dll ;extension=php_filepro.dll ;extension=php_gd2.dll ;extension=php_gettext.dll ;extension=php_ifx.dll ;extension=php_imap.dll ;extension=php_interbase.dll ;extension=php_ldap.dll ;extension=php_mcrypt.dll ;extension=php_mhash.dll ;extension=php_mime_magic.dll ;extension=php_ming.dll extension=php_mssql.dll extension=php_msql.dll extension=php_mysql.dll ;extension=php_oci8.dll ;extension=php_openssl.dll ;extension=php_oracle.dll ;extension=php_pgsql.dll ;extension=php_shmop.dll ;extension=php_snmp.dll ;extension=php_sockets.dll ;extension=php_sqlite.dll ;extension=php_sybase_ct.dll ;extension=php_tidy.dll ;extension=php_xmlrpc.dll ;extension=php_xsl.dll I've enabled three of the extensions.... are they all necessary or have I missed one? I then rebooted the server but I'm still getting the error message shown below: Fatal error: Call to undefined function mysql_connect() in D:\Intranet v3\php_telephone_list\index.php on line 8 PHP Warning: PHP Startup: Unable to load dynamic library './php_mssql.dll' - The specified module could not be found. in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library './php_msql.dll' - The specified module could not be found. in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library './php_mysql.dll' - The specified module could not be found. in Unknown on line 0 The only instructions I can find to help is a line in a PHP3 tutorial saying I have to right-click on php_iis_reg.inf and select install but I can't find the file on my system. Any help will be appreciated as I'm fed up with looking through out-of-date websites!  ;D
  19. Aaaahhhhh!  :D I didn't really just raced through the install! Cheers Thorpe I'll go away and check my PHP install.
  20. Hi guys any help with this would be appreciated.... I'm just starting out in PHP and I have a webserver with IIS 6, PHP and MySQL. I've set up a database with 1 table and I'm trying to pull some very basic data out but I'm having problems establishing a connection. Here are the details and the error message. Can anyone see the problem or suggest a way to start checking things? Database: TelephoneList Table: TelephoneNumbers Username: root Password: password Here's my PHP page: <html> <head> </head> <body> <?php $db = mysql_connect("localhost", "root", "password"); mysql_select_db("Telephonelist",$db); $result = mysql_query("SELECT * FROM telephonenumbers",$db); printf("First Name: %s<br>\n", mysql_result($result,0,"first_name")); ?> </body> </html> ...and here's the error it gives: Fatal error: Call to undefined function mysql_connect() in D:\Intranet v3\php_telephone_list\index.php on line 7 Cheers guys!
×
×
  • 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.