Jump to content

MYSQL database don't update please help.


jaylearning

Recommended Posts

Can any please tell me why this don't update?, im learning so i can't figure out anything, i been trying for last 5 months but can't get it to work.

 

 

Thank you for looking.

 

 

<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #FFFFFF;
}
-->
</style><? 
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root",""); 

//select which database you want to edit
mysql_select_db("book"); 

//If cmd has not been initialized
if(!isset($cmd)) 
{
   //display all the 
   $result = mysql_query("select * from school_book order by id"); 
   
   //run the while loop that grabs all the school_book scripts
   while($r=mysql_fetch_array($result)) 
   { 
      //grab the title and the ID of the school_book
      $title=$r["title"];//take out the title
      $id=$r["id"];//take out the id
     
 //make the title a link
      //echo "<a href='editad.php?cmd=edit&id=$id'>$title - Edit</a>";
     // echo "<br>";
    }
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $id = $_GET["id"];
      $sql = "SELECT * FROM school_book WHERE id=$id";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);
      ?>
  
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">

  <tr>
    <td width="413" align="center" valign="middle"><!-- leftpane -->
        <table width="413" border="0" align="center" cellpadding="0" cellspacing="0">
          
          <tr>          </tr>
          

          <tr>
            <td width="6" bgcolor="#DCE6FF"></td>
            <td width="440" bgcolor="#DCE6FF">
		 <form action="book_adit.php" method="post">
      <input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
		  <table width="100%" border="0" cellspacing="1" cellpadding="3">
          
                <tr>
                  <td align="right">Name</td>
                  <td>:</td>
                  <td><input name="title" type="text" id="title" value="<?php echo $myrow["title"] ?>" size="50" /></td>
                </tr>
                <tr>
                  <td width="103" align="right"> Categoy                  </td>
                  <td width="4">                  :</td>
                  <td width="311"><input name="category" type="text" id="category" value="<?php echo $myrow["category"] ?>" size="50" /></td>
                </tr>
                <tr>
                  <td align="right">Type</td>
                  <td>:</td>
                  <td><input name="type" type="text" id="type" value="<?php echo $myrow["type"] ?>" size="50" /></td>
                </tr>
                <tr>
                  <td align="right">                  Approved</td>
                  <td>                  :<br /></td>
                  <td><input name="processed" type="text" id="processed" value="<?php echo $myrow["processed"] ?>" size="5" /> 
                    0 = no / 1 = yes </td>
                </tr>
                <tr>
                  <td align="right">Image</td>
                  <td>:</td>
                  <td><input name="image" type="text" id="image" value="<?php echo $myrow["image"] ?>" size="50" /></td>
                </tr>
                <tr>
                  <td align="right"> Book Url</td>
                  <td>:</td>
                  <td><input name="url" type="text" id="url" value="<?php echo $myrow["url"] ?>" size="50" /></td>
                </tr>
                <tr>
                  <td align="right">Description</td>
                  <td>:</td>
                  <td><textarea name="description" cols="38" id="description"><?php echo $myrow["description"] ?></textarea></td>
                </tr>
                <tr>
                  <td align="right"> User / Id </td>
                  <td>:</td>
                  <td><input name="username" type="text" id="username" value="<?php echo $myrow["username"] ?>" size="10"/>
                  <input name="user" type="text" value="<?php echo $myrow["user"] ?>" size="5" user="user"/>
                  <input type="hidden" name="cmd" value="edit" /></td>
                </tr>
                <tr>
                  <td align="right"> </td>
                  <td> </td>
                  <td align="right">book Edit               
                    <input type="submit" name="submit" value="submit">              </td>
                </tr>
              </table>
		</form>					</td>
            <td width="4" bgcolor="#DCE6FF"> </td>
          </tr>

          <tr>
            <td height="2" colspan="3" bgcolor="#DCE6FF"><img src="/theme/default/images/frame/spacer.gif" alt="Spacer" height="2" /></td>
          </tr>
          <tr>
            <td colspan="3" background="/theme/default/images/frame/block_border_bottom.gif" bgcolor="#AEC5FD"><img src="/theme/default/images/frame/spacer.gif" alt="Spacer" height="14" /></td>
          </tr>
        </table>
      <!-- /leftpane --></td>
  </tr>
</table>
   
<? } ?>
<?
if ($_POST["submit"])
   {
      $title = $_POST["title"];
	$category = $_POST["category"];		
      $type = $_POST["type"];
	$processed = $_POST["processed"];
      $image = $_POST["image"];
	$url = $_POST["url"];							
      $description = $_POST["description"];
	$username = $_POST["username"];
	$user = $_POST["user"];	

			  
  $sql = "UPDATE school_book SET title='$title', category='$category', type='$type', processed='$processed', image='$image', url='$url', description='$description', username='$username', user='$user' WHERE id=$id";
      //replace school_book with your table name above
$result = mysql_query($sql) or die(mysql_error());
      echo '
  
  
   <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="middle"><table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="6"> </td>
        <td colspan="2"><h1>Edit book</h1>
            <p>Please use the form below to edit your book</p></td>
      </tr>
      <tr> </tr>
      <tr>
        <td height="8" colspan="3"><img src="/theme/default/images/frame/spacer.gif" alt="Spacer" height="8" /></td>
      </tr>
      <tr>
        <td colspan="3" background="/theme/default/images/frame/block_border_top.gif" bgcolor="#AEC5FD"><img src="/theme/default/images/frame/spacer.gif" alt="Spacer" height="14" /></td>
      </tr>
      <tr>
        <td width="6" b


gcolor="#DCE6FF"></td>
        <td width="440" align="center" bgcolor="#DCE6FF"><h1>book Has  Updated</h1></td>
        <td width="4" bgcolor="#DCE6FF"> </td>
      </tr>
      <tr>
        <td height="2" colspan="3" bgcolor="#DCE6FF"><img src="/theme/default/images/frame/spacer.gif" alt="Spacer" height="2" /></td>
      </tr>
      <tr>
        <td colspan="3" background="/theme/default/images/frame/block_border_bottom.gif" bgcolor="#AEC5FD"><img src="/theme/default/images/frame/spacer.gif" alt="Spacer" height="14" /></td>
      </tr>
      <tr>
        <td height="20" colspan="3"><img src="/theme/default/images/frame/spacer.gif" alt="Spacer" height="20" /></td>
      </tr>
    </table></td>
  </tr>
</table>
  
  
  ';
}
}
?>

Link to comment
Share on other sites

Change this line:

 

$sql = "UPDATE school_book SET title='$title', category='$category', type='$type', processed='$processed', image='$image', url='$url', description='$description', username='$username', user='$user' WHERE id=$id";
//replace school_book with your table name above
$result = mysql_query($sql) or die(mysql_error());

 

To this:

 

$sql = "UPDATE school_book SET title='$title', category='$category', type='$type', processed='$processed', image='$image', url='$url', description='$description', username='$username', user='$user' WHERE id=$id";
//replace school_book with your table name above
die($sql);
$result = mysql_query($sql) or die(mysql_error());

 

and post the result contained in $sql;

Link to comment
Share on other sites

chnage this line

 

$sql = "UPDATE school_book SET title='$title', category='$category', type='$type', processed='$processed', image='$image', url='$url', description='$description', username='$username', user='$user' WHERE id=$id";

 

to

 

$sql = "UPDATE school_book SET title='$title', category='$category', type='$type', processed='$processed', image='$image', url='$url', description='$description', username='$username', user='$user' WHERE id='$id'";

 

the single ticks around the $id variable were missing so the condition would never equal true uless you happen to have an id called $id !!!

Link to comment
Share on other sites

thanks but still dont help..

 

chnage this line

 

$sql = "UPDATE school_book SET title='$title', category='$category', type='$type', processed='$processed', image='$image', url='$url', description='$description', username='$username', user='$user' WHERE id=$id";

 

to

 

$sql = "UPDATE school_book SET title='$title', category='$category', type='$type', processed='$processed', image='$image', url='$url', description='$description', username='$username', user='$user' WHERE id='$id'";

 

the single ticks around the $id variable were missing so the condition would never equal true uless you happen to have an id called $id !!!

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.