Jump to content

[SOLVED] I need a second pair of eyes to check out my code for an error


gathos

Recommended Posts

hey guys, I'm looking for the error in my code. I can't seem to find it. anyways the situation is, i have a gallery database, i have my form setup to give each image a name and description. hit submit and then the it supposed to update the database with the description.

 

heres my code for my form page editrec.php:

<form id="form1" name="form1" method="post" action="processeditrec.php">
  
    <?php
	$id = $_GET["id"]; 
	$name = $_GET["name"];
	$page = $_GET['page'];
	mysql_connect("localhost", "username*****", "password****") or die(mysql_error());
	mysql_select_db("database*****") or die(mysql_error());
	$result = mysql_query("SELECT * FROM samples WHERE id='$id'") or die(mysql_error());
		$row = mysql_fetch_array( $result );

			$oldname = $row['name'];
			$oldfilename = $row['filename'];
			$oldsdesc = $row['sdesc'];
			$oldldesc = $row['ldesc'];

?>
  
    <input name="passid" type="hidden" id="passid" value="<? echo $id; ?>" />
    <?
	 function strip_ext($name)
	 {
		 $ext = strrchr($name, '.');
		 if($ext !== false)
		 {
			 $name = substr($name, 0, -strlen($ext));
		 }
		 return $name;
	 };

	 $remove_exts = strip_ext($oldfilename);


?>
    <input name="page" type="hidden" id="page" value="<? echo $page ?>" />
  <br />
  <table width="100%" border="0">
    <tr>
      <td width="20%" rowspan="2"><img src="images/<? echo $oldfilename; ?>" alt="" height="100" /></td>
      <td width="26%">name: 
      <input name="name" type="text" id="name" value="<? echo $remove_exts ?>" class="textfield" /></td>
      <td>Short Description: 
      <input type="text" name="sdesc" id="sdesc" value="<? echo $oldsdesc; ?>"/></td>
    </tr>
    <tr>
      <td colspan="2" align="left" valign="top"><p>Description:<br />
          <textarea name="ldesc" id="ldesc" cols="45" rows="5"><? echo $oldldesc; ?></textarea>
          <br />
      </p></td>	
    </tr>
  </table>

  
  <br />
  <table width="100%" border="0">
    <tr>
      <td> </td>
      <td>
</td>
    </tr>
  </table>
  <br />
  <table width="100%" border="0">
    <tr>
      <td width="25%" align="left" valign="top"> </td>
      <td width="25%" align="left" valign="top"> </td>
      <td width="25%" align="left" valign="top"> </td>
      <td width="25%" align="left" valign="top"> </td>
    </tr>
  </table>

<label>
    <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
  </p>
</form>

 

 

heres my code for my processing page processeditrec.php:

 

<?
$name = $_POST['name'];
$sdesc = $_POST['sdesc'];
$ldesc = $_POST['ldesc'];
$id = $_POST['passid'];
$obscurity = $_POST['obscurity'];
$page = $_POST['page'];


mysql_connect("localhost", "username*****", "password*****") or die(mysql_error());
mysql_select_db("database*****") or die(mysql_error());


$sql = "
UPDATE sample 
SET 
name= '$name', 
sdesc= '$sdesc',
ldesc= '$ldesc',
obscurity= '$obscurity'
WHERE id = '$id'";


$result = mysql_query($sql);

if ($result){
echo "Your record was updated!<br/>";
} else {
echo "An error occured during update!<br/>";
}



?>

<html>
<head>

</head>
<br>
<a href="displayrec.php">Click here to go to the gallery.</a>
</html>

 

i can't figure out what is going on.  it's probably something simple but, well i can't find it.

 

It won't update the databse with the new info, and on the process page i get " an error occured during the update" but i have no idea how to get it to give me more information.

 

thanks for your help,

gathos.

 

ey guys, I'm looking for the error in my code. I can't seem to find it.

 

What makes you think there's an error?  What happens, or doesn't happen?

 

 

EDIT: A little debugging...

 

You shouldn't use short hand php tags, use <?php.

 

Change this line to:

 

   $result = mysql_query($sql) or die(mysql_error());

 

Dont Know if this is it but i usually use also you should add a limit 1 to your query if your only going to be updating 1 row and after that you have to start the loop

 

<?php $result = mysql_query("SELECT * FROM samples WHERE id='$id' LIMIT 1") or die(mysql_error());
	while ($row = mysql_fetch_array($result)) {
//Rows are being looped even though you only 
//call one row with limit 1

			$oldname = $row['name'];
			$oldfilename = $row['filename'];
			$oldsdesc = $row['sdesc'];
			$oldldesc = $row['ldesc'];
}// end row loop 
?>

Archived

This topic is now archived and is closed to further replies.

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