Jump to content

Updating a DB with a form.


Lee-Bartlett

Recommended Posts

I followed this TUT online and i cant see what i got wrong,

 

  <?php require_once("includes/db_connection.php") ?>
  
  <?php 
//If cmd has not been initialized

if(!isset($cmd)) 
{
   //display all the business

   $result = mysql_query("select * from tblbasicform by email"); 

   

   //run the while loop that grabs all the business scripts

   while($r=mysql_fetch_array($result));

   { 

      //grab the business_name and the username of the business

      $email=$r["email"];//take out the business_name

      $name=$r["name"];//take out the username

     

     //make the business_name a link

    echo "<a href='edit.php?cmd=edit&username=$username'>$business_name - Edit</a>";

     // echo "<br>";

    }

}

?>





<?

if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")

{

   if (!isset($_POST["submit"]))

   {

      $name= $_GET["name"];

      $sql = "SELECT * FROM tblbasicform WHERE name='$name'";

      $result = mysql_query($sql);        

      $myrow = mysql_fetch_array($result);

      ?>

      

      <form action="edit.php" method="post">

      <input type=hidden name="username" value="<?php echo $myrow["name"] ?>">

   

      business_name:<INPUT TYPE="TEXT" NAME="email" VALUE="<?php echo $myrow["email"] ?>" SIZE=30><br>

      info:<TEXTAREA NAME="locaiton" ROWS=10 COLS=30><? echo $myrow["location"] ?></TEXTAREA><br>

      industry:<INPUT TYPE="TEXT" NAME="buissnes_name" VALUE="<?php echo $myrow["buissnes_name"] ?>" SIZE=30><br>

   

      <input type="hidden" name="cmd" value="edit">

   

      <input type="submit" name="submit" value="submit">

   

      </form>

   

   <? } ?>

  
   

  <?

   if ($_POST["$submit"])

   {

      $email = $_POST["email"];

      $location = $_POST["location"];

      $buissnes_name = $_POST["buissnes_name"];



      $sql = "UPDATE tblbasicform SET email='$email',location='$location', buissnes_name='$buissnes_name' WHERE name='$name'";



      $result = mysql_query($sql);

      echo "Thank you! Information updated.";

   }

}

?>

 

i get this error

 

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Website\attempt.php on line 16

 

Link to comment
Share on other sites

<?php 
$db_host = "localhost"; // Your database host server, eg. db.server.com
$db_user = "takenout"; // User who has access to the database
$db_pass = "takenout"; // User password to access database
$db_name = "roberts_work"; // Existing database name

// -- Connecting to the database (not persistent connection)

$connect = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name,$connect) or die(mysql_error());


?>

Link to comment
Share on other sites

Ah, the problem seems to be in your query:

<?php $result = mysql_query("select * from tblbasicform by email");

I think you want 'ORDER BY email'.

<?php $result = mysql_query("select * from tblbasicform ORDER BY email") or die(mysql_error());

also adding the die after will show you if there is a problem in your query...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.