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
https://forums.phpfreaks.com/topic/142563-query-troubles/
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
https://forums.phpfreaks.com/topic/142563-query-troubles/#findComment-747110
Share on other sites

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.