Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2004-06-29, 07:08 PM
Squintz
Guest
 
Posts: n/a
Default

Im having problems with mysql when i run the following script and others i can SELECT data from the database and view it in the browser but i can not INSERT or DELETE data from the web page. How ever i can Insert it and Delete the data from the windows command prompt.

I can figure out why. I am logging in as root and i have tried Grant All to root but that does not do the trick. This script is right from a tutorial and my other script i wrote myself. Neither work! Im running MySQL on my local machine.

Code:
<html>

<body>



<?php



$db = mysql_connect("localhost", "root","862000");

mysql_select_db("mydb",$db);



if ($submit) {

 // here if no ID then adding else we're editing

 if ($id) {

  $sql = "UPDATE employees SET first='$first',last='$last',address='$address',pos ition='$position' WHERE id=$id";

 } else {

  $sql = "INSERT INTO employees (first,last,address,position) VALUES ('$first','$last','$address','$position')";

 }

 // run SQL against the DB

 $result = mysql_query($sql);

 echo "Record updated/edited!<p>";

} elseif ($delete) {

	// delete a record

  $sql = "DELETE FROM employees WHERE id=$id";	

  $result = mysql_query($sql);

  echo "$sql Record deleted!<p>";

} else {

 // this part happens if we don't press submit

 if (!$id) {

  // print the list if there is not editing

  $result = mysql_query("SELECT * FROM employees",$db);

  while ($myrow = mysql_fetch_array($result)) {

   printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["id"], $myrow["first"], $myrow["last"]);

  printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);

  }

 }



 ?>

 <P>

 <a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>

 <P>

 <form method="post" action="<?php echo $PHP_SELF?>">

 <?php



 if ($id) {

  // editing so select a record

  $sql = "SELECT * FROM employees WHERE id=$id";

  $result = mysql_query($sql);

  $myrow = mysql_fetch_array($result);

  $id = $myrow["id"];

  $first = $myrow["first"];

  $last = $myrow["last"];

  $address = $myrow["address"];

  $position = $myrow["position"];

  // print the id for editing



  ?>

  <input type=hidden name="id" value="<?php echo $id ?>">

  <?php

 }



 ?>

 First name:<input type="Text" name="first" value="<?php echo $first ?>"><br>

 Last name:<input type="Text" name="last" value="<?php echo $last ?>"><br>

 Address:<input type="Text" name="address" value="<?php echo $address ?>"><br>

 Position:<input type="Text" name="position" value="<?php echo $position ?>"><br>

 <input type="Submit" name="submit" value="Enter information">

 </form>



<?php



}



?>



</body>

</html>
Reply With Quote
  #2 (permalink)  
Old 2004-06-30, 05:03 PM
Moderator
 
Join Date: May 2004
Location: Portugal
Posts: 143
gesf is an unknown quantity at this point
Send a message via ICQ to gesf Send a message via MSN to gesf Send a message via Skype™ to gesf
Default

Any errors !?

BTW: I suggest you to use php´s $_GET/$_POST superglobal!
__________________
Best Regards,
Gonçalo "GesF" Fontoura

Website : gesf.org
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:36 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.