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

Linux, Apache, MySQL, PHP

 
QuestionWeb service: PHP SoapClient Pin
PHP Rocks31-Jul-11 21:09
PHP Rocks31-Jul-11 21:09 
QuestionPhp Sessions Pin
nishinilu27-Jul-11 5:40
nishinilu27-Jul-11 5:40 
AnswerRe: Php Sessions Pin
Gerben Jongerius27-Jul-11 20:33
Gerben Jongerius27-Jul-11 20:33 
AnswerRe: Php Sessions Pin
Claudio Ludovico Panetta29-Jul-11 6:05
Claudio Ludovico Panetta29-Jul-11 6:05 
AnswerRe: Php Sessions Pin
Arunkumar.Koloth15-Jan-12 1:31
Arunkumar.Koloth15-Jan-12 1:31 
Questionhow to preg_replace the last comma? Pin
mabrahao26-Jul-11 4:01
mabrahao26-Jul-11 4:01 
AnswerRe: how to preg_replace the last comma? Pin
Peter_in_278026-Jul-11 14:58
professionalPeter_in_278026-Jul-11 14:58 
QuestionUpdate multiple rows in a dynamic table Dreamweaver CS5.5 Pin
sir_amin16-Jul-11 22:32
sir_amin16-Jul-11 22:32 
hello there



i want to update multiple rows which comes from a dynamic table in Dreamweaver CS5 (a loop in php) here is my Mysql table :

CREATE TABLE `register`.`s_lessons` (<br />
`lid` int( 5 ) NOT NULL ,<br />
`sid` int( 9 ) NOT NULL ,<br />
`term` int( 5 ) NOT NULL ,<br />
`tid` int( 5 ) NOT NULL ,<br />
`point` double NOT NULL DEFAULT '0',<br />
PRIMARY KEY ( `lid` , `sid` , `term` ) ,<br />
KEY `tid` ( `tid` ) ,<br />
KEY `point` ( `point` )<br />
) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_persian_ci;


and this is my page source code:

<?php require_once('../Connections/register.php'); ?><br />
<?php<br />
session_start();<br />
if (!function_exists("GetSQLValueString")) {<br />
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") <br />
{<br />
  if (PHP_VERSION < 6) {<br />
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;<br />
  }<br />
<br />
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);<br />
<br />
  switch ($theType) {<br />
    case "text":<br />
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";<br />
      break;    <br />
    case "long":<br />
    case "int":<br />
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";<br />
      break;<br />
    case "double":<br />
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";<br />
      break;<br />
    case "date":<br />
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";<br />
      break;<br />
    case "defined":<br />
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;<br />
      break;<br />
  }<br />
  return $theValue;<br />
}<br />
}<br />
<br />
$colname1_rs1 = "-1";<br />
if (isset($_GET['term'])) {<br />
  $colname1_rs1 = $_GET['term'];<br />
}<br />
$colname_rs1 = "-1";<br />
if (isset($_GET['lid'])) {<br />
  $colname_rs1 = $_GET['lid'];<br />
}<br />
$colname2_rs1 = "-1";<br />
if (isset($_SESSION['tid'])) {<br />
  $colname2_rs1 = $_SESSION['tid'];<br />
}<br />
mysql_select_db($database_register, $register);<br />
$query_rs1 = sprintf("SELECT s_lessons.sid, s_lessons.lid, s_lessons.term, s_lessons.tid, s_lessons.point FROM s_lessons WHERE s_lessons.lid = %s AND s_lessons.term = %s AND s_lessons.tid  = %s", GetSQLValueString($colname_rs1, "int"),GetSQLValueString($colname1_rs1, "int"),GetSQLValueString($colname2_rs1, "int"));<br />
$rs1 = mysql_query($query_rs1, $register) or die(mysql_error());<br />
$row_rs1 = mysql_fetch_assoc($rs1);<br />
$totalRows_rs1 = mysql_num_rows($rs1);<br />
$count=mysql_num_rows($rs1);<br />
<br />
<br />
<br />
$editFormAction = $_SERVER['PHP_SELF'];<br />
if (isset($_SERVER['QUERY_STRING'])) {<br />
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);<br />
}<br />
<br />
for ($j = 0, $len = count($_POST['lid']); $j < $len; $j++) {<br />
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {<br />
  $updateSQL = sprintf("UPDATE s_lessons SET point=%s WHERE tid=%s, lid=%s, sid=%s, term=%s",<br />
                       GetSQLValueString($_POST['point'] [$j], "double"),<br />
                            GetSQLValueString($_SESSION['tid'], "int"),<br />
                       GetSQLValueString($_POST['lid'] [$j], "int"),<br />
                            GetSQLValueString($_POST['sid'] [$j], "int"),<br />
                            GetSQLValueString($_POST['term'] [$j], "int"));<br />
<br />
  mysql_select_db($database_register, $register);<br />
  $Result1 = mysql_query($updateSQL, $register) or die(mysql_error());<br />
}<br />
  $updateGoTo = "student_lists.php";<br />
  if (isset($_SERVER['QUERY_STRING'])) {<br />
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";<br />
    $updateGoTo .= $_SERVER['QUERY_STRING'];<br />
  }<br />
  header(sprintf("Location: %s", $updateGoTo));<br />
}<br />
<br />
?><br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta name="keywords" content="" /><br />
<meta name="description" content="" /><br />
<meta http-equiv="content-type" content="text/html; charset=utf-8" /><br />
<title>r</title><br />
<link href="styles/style.css" rel="stylesheet" type="text/css" media="screen" /><br />
<link href="styles/in_styles.css" rel="stylesheet" type="text/css" media="screen" /><br />
</head><br />
<body><br />
<div id="wrapper"><br />
     <div id="header-wrapper"><br />
          <br />
     </div><br />
     <!-- end #header --><br />
     <div id="page"><br />
          <div id="page-bgtop"><br />
               <div id="page-bgbtm"><br />
                    <div id="content"><br />
                         <div class="post"><br />
                           <div style="clear: both;"><br />
                        <form name="form1" id="form1" method="post" action="<?php echo $editFormAction; ?>"><br />
                        <table border="1" align="center"><br />
                          <tr><br />
                            <th>Student ID</th><br />
                            <th>Lesson ID</th><br />
                            <th>Semester</th><br />
                            <th>Point</th><br />
                            <br />
                          </tr><br />
                          <?php do { ?><br />
                            <tr><br />
                              <td class="data"><label for="sid[]"></label><br />
                              <input name="sid[]" type="text" id="sid[]" value="<?php echo $row_rs1['sid']; ?>" size="9" readonly="readonly" /></td><br />
                              <td class="data"><label for="lid[]"></label><br />
                              <input name="lid[]" type="text" id="lid[]" value="<?php echo $row_rs1['lid']; ?>" size="5" readonly="readonly" /></td><br />
                              <td class="data"><label for="term[]"></label><br />
                              <input name="term[]" type="text" id="term[]" value="<?php echo $row_rs1['term']; ?>" size="4" readonly="readonly" /></td><br />
                              <td><label for="point[]"></label><br />
                                <input name="point[]" type="text" id="point[]" value="<?php echo $row_rs1['point']; ?>" size="4" />                              <br />
                          </tr><br />
                          <br />
                            <?php } while ($row_rs1 = mysql_fetch_assoc($rs1)); ?><br />
                        </table><br />
                        <p><br />
                          <input type="submit" name="Submit" id="Submit" value="Submit" /><br />
                          <input type="hidden" name="MM_update" value="form1" /><br />
                        </p><br />
                        </form><br />
                           </div><br />
                         </div><br />
                    <div style="clear: both;"><br />
                </div><br />
                    </div><br />
                    <!-- end #content --><br />
                    <br />
                    <!-- end #sidebar --><br />
                    <div style="clear: both;"> </div><br />
               </div><br />
          </div><br />
     </div><br />
     <!-- end #page --><br />
</div><br />
<!-- end #footer --><br />
</body><br />
</html><br />
<?php<br />
mysql_free_result($rs1);<br />
?>


All i want is that when users click on SUBMIT button values of point column in s_lessons(database table) be updated by new entries from user.



i did my best and result with that code is :



You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' lid=888, sid=860935422, term=902' at line 1



I would appreciate any idea.



with prior thanks
AnswerRe: Update multiple rows in a dynamic table Dreamweaver CS5.5 Pin
Gerben Jongerius17-Jul-11 3:17
Gerben Jongerius17-Jul-11 3:17 
GeneralRe: Update multiple rows in a dynamic table Dreamweaver CS5.5 Pin
sir_amin17-Jul-11 3:44
sir_amin17-Jul-11 3:44 
Questionsamba question... Pin
Albert Holguin8-Jul-11 9:27
professionalAlbert Holguin8-Jul-11 9:27 
AnswerRe: samba question... Pin
Albert Holguin8-Jul-11 11:06
professionalAlbert Holguin8-Jul-11 11:06 
AnswerRe: samba question... Pin
Jörgen Sigvardsson4-Sep-11 8:33
Jörgen Sigvardsson4-Sep-11 8:33 
Questionproblem with session varaibles Pin
MacRaider48-Jul-11 7:01
MacRaider48-Jul-11 7:01 
GeneralRe: problem with session varaibles Pin
MacRaider48-Jul-11 7:54
MacRaider48-Jul-11 7:54 
GeneralRe: problem with session varaibles Pin
MacRaider48-Jul-11 8:42
MacRaider48-Jul-11 8:42 
AnswerRe: problem with session varaibles Pin
MacRaider48-Jul-11 7:53
MacRaider48-Jul-11 7:53 
GeneralRe: problem with session varaibles Pin
Thomas.D Williams21-Jul-11 5:08
Thomas.D Williams21-Jul-11 5:08 
GeneralRe: problem with session varaibles Pin
MacRaider421-Jul-11 5:18
MacRaider421-Jul-11 5:18 
GeneralRe: problem with session varaibles Pin
Thomas.D Williams21-Jul-11 5:34
Thomas.D Williams21-Jul-11 5:34 
GeneralRe: problem with session varaibles Pin
MacRaider421-Jul-11 5:39
MacRaider421-Jul-11 5:39 
QuestionTrying to set more than one style at a time without CSS... [modified] Pin
Joan M6-Jul-11 23:40
professionalJoan M6-Jul-11 23:40 
GeneralRe: Trying to set more than one style at a time without CSS... Pin
Joan M7-Jul-11 4:47
professionalJoan M7-Jul-11 4:47 
GeneralRe: Trying to set more than one style at a time without CSS... Pin
Joan M7-Jul-11 5:30
professionalJoan M7-Jul-11 5:30 
AnswerRe: Trying to set more than one style at a time without CSS... Pin
Graham Breach7-Jul-11 3:12
Graham Breach7-Jul-11 3: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.