Click here to Skip to main content
15,887,135 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
Questiondynamic page creation using php Pin
susmita0107198613-Aug-11 20:40
susmita0107198613-Aug-11 20:40 
AnswerRe: dynamic page creation using php Pin
cjoki16-Aug-11 11:02
cjoki16-Aug-11 11:02 
SuggestionRe: dynamic page creation using php Pin
enhzflep16-Aug-11 17:15
enhzflep16-Aug-11 17:15 
QuestionVoice recording in php website?? Pin
doitnow114713-Aug-11 4:39
doitnow114713-Aug-11 4:39 
AnswerRe: Voice recording in php website?? Pin
cjoki16-Aug-11 11:04
cjoki16-Aug-11 11:04 
GeneralRe: Voice recording in php website?? Pin
doitnow114716-Aug-11 23:18
doitnow114716-Aug-11 23:18 
GeneralRe: Voice recording in php website?? Pin
cjoki17-Aug-11 9:39
cjoki17-Aug-11 9:39 
Questioninsert multiple database table row from dynamic checkboxes from db Pin
sir_amin12-Aug-11 1:57
sir_amin12-Aug-11 1:57 
hello there

i have a form for submiting data into mysql table with the name of TERM_LESSON table in this form i have a sets of checkboxes that came from a table with the name GRADE these are my two tables:
TERM_LESSON
SQL
CREATE TABLE IF NOT EXISTS `term_lesson` (
  `lid` int(5) NOT NULL,
  `gradeid` int(1) NOT NULL,
  
  PRIMARY KEY (`lid`,`gradeid`)
) ENGINE=MyISAM ;

GRADE
SQL
CREATE TABLE IF NOT EXISTS `grade` (
  `gradeid` int(11) NOT NULL AUTO_INCREMENT,
  `gname` varchar(40)  NOT NULL,
  PRIMARY KEY (`gradeid`)
) ENGINE=MyISAM  AUTO_INCREMENT=0 ;


and this is my form:

HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" id="form1">
                            <table align="center">
                              <tr valign="baseline">
                                 <td align="right">LID</td>
                                <td">
                                
                                <input name="lid[]" type="text" id="lid[]" value="<?php echo $row_rslesson['lid']; ?>" size="32" readonly="readonly" />
                                </td>
                               
                                
                              </tr>
                                <td >GRADE</td>
                                <td >
                                  <?php do { ?>
                                  <input name="gradeid[]" type="checkbox" id="gradeid[]" value="<?php echo $row_rstotalgrade['gradeid']; ?>" />
                                  <label for="gradeid[]"></label>
                                  <?php echo $row_rstotalgrade['gname']; ?><br />
                                <?php } while ($row_rstotalgrade = mysql_fetch_assoc($rstotalgrade)); ?></td>
                              <tr valign="baseline">
                                <td style="text-align: center"></td>
                                <td align="right"><input type="submit" value="submit" /></td>
                               
                              </tr>
                            </table>
                            <input type="hidden" name="MM_insert" value="form1" />
                          </form>
</body>
</html>


i want to make a TABLE ROW in TERM_LESSON for every checkboxes that is selected by user with same LID in form like: (for 2 chekbox seledted)

lid gradeid
11 , 1
11 , 2

and this is my php code for doing that:

PHP
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
	
  foreach ($_POST['gradeid'] as $i) {

  $insertSQL = sprintf("INSERT INTO term_lesson (lid, gradeid) VALUES (%s, %s)",
                       GetSQLValueString($_POST['lid'], "int"),
                       GetSQLValueString($i, "int"));

  mysql_select_db($database_register, $register);
  $Result1 = mysql_query($insertSQL, $register) or die(mysql_error());
  }
  $insertGoTo = "lesson_term_added.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_register, $register);
$query_rstotalgrade = "SELECT * FROM grade";
$rstotalgrade = mysql_query($query_rstotalgrade, $register) or die(mysql_error());
$row_rstotalgrade = mysql_fetch_assoc($rstotalgrade);
$totalRows_rstotalgrade = mysql_num_rows($rstotalgrade);
?>



but when i submit the form i face to this error :

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11
Column 'lid' cannot be null


i appreciate any idea.

with prior thanks
Generalhelp me (PHP beginner) Pin
Ahmad Alweshahi11-Aug-11 6:11
Ahmad Alweshahi11-Aug-11 6:11 
GeneralRe: help me (PHP beginner) Pin
Mohibur Rashid11-Aug-11 18:51
professionalMohibur Rashid11-Aug-11 18:51 
GeneralRe: help me (PHP beginner) Pin
Ahmad Alweshahi12-Aug-11 1:03
Ahmad Alweshahi12-Aug-11 1:03 
GeneralRe: help me (PHP beginner) Pin
User 171649212-Aug-11 0:16
professionalUser 171649212-Aug-11 0:16 
GeneralRe: help me (PHP beginner) Pin
Ahmad Alweshahi12-Aug-11 3:01
Ahmad Alweshahi12-Aug-11 3:01 
GeneralRe: help me (PHP beginner) Pin
cjoki16-Aug-11 11:08
cjoki16-Aug-11 11:08 
Questionphp and mysql related firefox problem Pin
doitnow114711-Aug-11 0:46
doitnow114711-Aug-11 0:46 
AnswerRe: php and mysql related firefox problem Pin
Mohibur Rashid11-Aug-11 18:45
professionalMohibur Rashid11-Aug-11 18:45 
GeneralRe: php and mysql related firefox problem Pin
doitnow114711-Aug-11 19:21
doitnow114711-Aug-11 19:21 
GeneralRe: php and mysql related firefox problem Pin
Mohibur Rashid11-Aug-11 22:48
professionalMohibur Rashid11-Aug-11 22:48 
GeneralRe: php and mysql related firefox problem Pin
doitnow114711-Aug-11 23:18
doitnow114711-Aug-11 23:18 
GeneralRe: php and mysql related firefox problem Pin
doitnow114711-Aug-11 23:28
doitnow114711-Aug-11 23:28 
AnswerRe: php and mysql related firefox problem Pin
Peter_in_278011-Aug-11 23:39
professionalPeter_in_278011-Aug-11 23:39 
GeneralRe: php and mysql related firefox problem Pin
doitnow114711-Aug-11 23:44
doitnow114711-Aug-11 23:44 
GeneralRe: php and mysql related firefox problem Pin
Peter_in_278012-Aug-11 0:01
professionalPeter_in_278012-Aug-11 0:01 
GeneralRe: php and mysql related firefox problem Pin
doitnow114712-Aug-11 0:02
doitnow114712-Aug-11 0:02 
GeneralRe: php and mysql related firefox problem Pin
Mohibur Rashid12-Aug-11 0:12
professionalMohibur Rashid12-Aug-11 0:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.