[SOLVED] error in php code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sanjay123456
    New Member
    • Sep 2006
    • 125

    [SOLVED] error in php code

    Dear friends


    Following peace of code for whenever we click for the next botton
    then next question will come to database but its not working . some problem in this code so tell me where its wrong ?

    [PHP]

    *<?php*
    session_start() ;
    if (!isset($_SESSI ON['count']))


    $_SESSION['count'] = 1;
    if (isset($_POST['submitted'])) {


    $con = mysql_connect(" localhost","roo t","123456") ;


    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db ("my_db", $con);
    $sql="select * from quest where count =
    $_SESSION['count']";$r=mysql_quer y($sql);


    if (!r)
    {
    die('Error: ' . mysql_error());
    exit();


    }


    while($row = mysql_fetch_arr ay($r))
    {*?>**<h3><p* style="color: #0000ff"*>**<?p hp* echo
    $row['que'];*?>**<table* border='0'*><tr ><td* valign='top'*>< input*
    type='radio' name='quiz' value='4' */></td><td>**<?php* echo
    $row['op1'];*?><br></td></tr>**<tr><td* valign='top'*>< input*
    type='radio' name='quiz' value='3' */></td><td>**<?php* echo
    $row['op2'];*?><br></td></tr>**<tr><td* valign='top'*>< input*
    type='radio' name='quiz' value='2' */></td><td>**<?php* echo
    $row['op3'];*?><br></td></tr>**<tr><td* valign='top'*>< input*
    type='radio' name='quiz' value='1' */></td><td>**<?php* echo
    $row['op4'];*?>**<br></td></tr>**</table>**<br></p></h3>*
    *<?php*


    }mysql_close($c on)


    echo 'This is question no. '.$_SESSION['count'];
    $_SESSION['count'] += 1;

    }*?>*


    *<!DOCTYPE *HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"*>*
    *<html><head><t itle>*Questionn aire*</title></head>*
    *<body>*
    *<form* name="myform" method="POST" action="*<?php* echo
    $_SERVER['PHP_SELF']; *?>*"*>*
    *<input* type="submit" VALUE="Click here for the next question *<?php*
    echo $_SESSION['count']; *?>*" */>*
    *<input* type="hidden" name="submitted " value="1" */>*
    *</form></body></html>*



    [/PHP]


    sanjay
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    What are all those asterisks (about 100) doing in the code. If you try to run that, it is logical it doesn't work!

    By the way, I see that you have started this new thread while it is really a continuation of the thread at http://www.thescripts.com/forum/thread555608.html
    Now what are you trying to accomplish with having 2 threads for the same problem?
    The sample that was provided was tested and worked. So it must be in your MySQL code or display code because that was not included in the sample.

    Ronald :cool:

    Comment

    • sanjay123456
      New Member
      • Sep 2006
      • 125

      #3
      sir

      sorry for unwanted asterstic

      Real code r following


      [PHP]



      <?php

      session_start() ;

      if (!isset($_SESSI ON['count']))

      $_SESSION['count'] = 1;

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


      $con = mysql_connect(" localhost","roo t","123456") ;

      if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

      mysql_select_db ("my_db", $con);

      $sql="select * from quest where count = $_SESSION['count']";
      $r=mysql_query( $sql);


      if (!r)
      {
      die('Error: ' . mysql_error());
      exit();
      }

      while($row = mysql_fetch_arr ay($r))
      {
      ?>
      <h3><p style="color: #0000ff">
      <?php echo $row['que'];
      ?>
      <table border='0'><tr> <td valign='top'><i nput type='radio' name='quiz' value='4' /></td><td>
      <?php echo $row['op1'];
      ?><br></td></tr>
      <tr><td valign='top'><i nput type='radio' name='quiz' value='3' /></td><td>
      <?php echo $row['op2'];
      ?><br></td></tr>
      <tr><td valign='top'><i nput type='radio' name='quiz' value='2' /></td><td>
      <?php echo $row['op3'];
      ?><br></td></tr>
      <tr><td valign='top'><i nput type='radio' name='quiz' value='1' /></td><td>
      <?php echo $row['op4'];
      ?>
      <br></td></tr>
      </table>
      <br></p></h3>

      <?php
      }
      mysql_close($co n)

      echo 'This is question no. '.$_SESSION['count'];
      $_SESSION['count'] += 1;
      }
      ?>

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

      <html><head><ti tle>Questionnai re</title></head>

      <body>

      <form name="myform" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">

      <input type="submit" VALUE="Click here for the next question <?php echo $_SESSION['count']; ?>" />

      <input type="hidden" name="submitted " value="1" />

      </form></body></html>


      [/PHP]


      sanjay

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        The first error that springs in the eye is the select statement you use. It should be [php]$sql="select * from quest where count = " . $_SESSION['count'];[/php]

        Ronald :cool:

        Comment

        • sanjay123456
          New Member
          • Sep 2006
          • 125

          #5
          Sir
          A very very thanks to u problem is solved.

          sanjay

          Comment

          Working...