Jump to content

Query Troubles


slaterino

Recommended Posts

I am having troubles with what I thought was a simple query. I am hoping to have a form where I can edit data from my MySQL database. However, the page keeps showing as blank. I have an index page with dynamic links such as 'class_edit.php?cl_ID=2'. They then go to this page but it's currently showing completely blank. This is the code on the page. If anyone can see anything on this page that might be causing problems could they please let me know. Thanks!

 

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');

include '../library/config.php';
include '../library/opendb.php';

   $cl_ID = $_GET['cl_ID'];

   if(isset($_POST['submit']))
  {

      $cl_course = addslashes($_POST['cl_course']);
      $cl_day = addslashes($_POST['cl_day']);

         $result = mysql_query("UPDATE classes SET cl_course='$cl_course', cl_day='$cl_day' WHERE cl_ID='$cl_ID' ",$conn);

}
elseif($cl_ID)
{

        $result = mysql_query("SELECT * FROM classes WHERE cl_ID='$cl_ID' ",$conn);
        while($myrow = mysql_fetch_assoc($result))
             {
                $cl_course = $myrow["cl_course"];
                $cl_day = $myrow["cl_day"];
?>

<form method="post" action="<?php echo $PHP_SELF ?>">
<table>
<input type="hidden" name="cl_ID" value="<? echo $myrow['cl_ID']?>">
<tr>
<td>Course:</td><td><input name="cl_course" size="40" maxlength="255" value="<? echo $cl_course; ?>" /></td></tr>
<tr>
<td>Day: </td><td><input name="cl_day"  size="40" maxlength="255" value="<? echo $cl_day; ?>" /></td></tr>
</table><br />
<div align="center"><input type="submit" name="submit" value="Update Class" /></div>
</form>
<?
              }

  }
?>

Link to comment
Share on other sites

If cl_id is a number than you don't need quotes around it in your query. that's probably the problem...sql trying to compare a string to an integer

 

Try that and then if that doesn't work start profiling it by throwing some echo statements in there???

 

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');

include '../library/config.php';
include '../library/opendb.php';

   $cl_ID = $_GET['cl_ID'];

   if(isset($_POST['submit']))
  {

      $cl_course = addslashes($_POST['cl_course']);
      $cl_day = addslashes($_POST['cl_day']);

         $result = mysql_query("UPDATE classes SET cl_course='$cl_course', cl_day='$cl_day' WHERE cl_ID='$cl_ID' ",$conn);

}
elseif($cl_ID)
{

        $result = mysql_query("SELECT * FROM classes WHERE cl_ID='$cl_ID' ",$conn);
        while($myrow = mysql_fetch_assoc($result))
             {

                $cl_course = $myrow["cl_course"];
echo $cl_course;
                $cl_day = $myrow["cl_day"];
echo $cl_day;
?>

<form method="post" action="<?php echo $PHP_SELF ?>">
<table>
<input type="hidden" name="cl_ID" value="<? echo $myrow['cl_ID']?>">
<tr>
<td>Course:</td><td><input name="cl_course" size="40" maxlength="255" value="<? echo $cl_course; ?>" /></td></tr>
<tr>
<td>Day: </td><td><input name="cl_day"  size="40" maxlength="255" value="<? echo $cl_day; ?>" /></td></tr>
</table><br />
<div align="center"><input type="submit" name="submit" value="Update Class" /></div>
</form>
<?
              }

  }
?>

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.