Jump to content

doforumda

Members
  • Posts

    300
  • Joined

  • Last visited

    Never

Posts posted by doforumda

  1. hi i have one form. there are three fields which are to be filled by the user. and then there are two buttons. ob clicking first button i want to save user's provided data to the database display the same page again. and on clicking second button the provided data will be saved and will be taken to next page.

     

    my problem is with these buttons how can i set up these buttons to do the the action?

     

    my code is here

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form name="form1" method="post" action="">
      <label>Degree Name:
      <input type="text" name="textfield" id="textfield">
      </label>
      <p>
        <label>CGPA:
        <input type="text" name="textfield2" id="textfield2">
        </label>
      </p>
      <p>
        <label>Institute:
        <input type="text" name="textfield3" id="textfield3">
        </label>
      </p>
      <p>
        <label>
        <input type="submit" name="button" id="button" value="Save And Add Another">
        </label>
      </p>
      <p>
        <label>
        <input type="submit" name="button2" id="button2" value="Save And Proceed to Next Step">
        </label>
    </p>
    </form>
    <?php
    $db = mysql_connect("localhost");
    mysql_select_db("job", $db);
    $addcv = mysql_query("insert into cv
    						(
    							degree,
    							cgpa,
    							institute
    						) 
    							values
    						(
    							'".$degree."',
    							'".$cgpa."',
    							'".$institute."',
    						)");
    echo "Your data is added.";
    ?>
    </body>
    </html>
    

  2. i have problem with following code.

    $namecheck = mysql_query("select * from cv where apply = '$apply' AND name='$name' AND cnic='$cnic' AND email='$email'");
    $countname = mysql_num_rows($namecheck);
    
    if($countname != 0)
    {
    die("You have already applied for this vacancy.<br><br><a href='cv_form.php'>Click Here</a> to go back.");
    }

     

    what this query does is if all the data in the columns are equal with the data in the variables then the if condition becomes true. what i want is if any of the columns becomes equal then if condition should become true.

     

    how to do this?

  3. please tell me what i am doing wrong in this query. it displays this error

     

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\wamp\www\dynamic\quiz2.php on line 77

     

    my query is

    $namecheck = mysql_query("select * from cv where name = '$name',apply='$apply' and email='$email'");
    $countname = mysql_num_rows($namecheck);
    
    if($countname != 0)
    {
    die("You have already applied for this vacancy.");
    }

  4. i need help with date function

     

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    $db = mysql_connect("localhost");
    mysql_select_db("test", $db);
    
    $query = "select * from date";
    $result = mysql_query($query);
    while($record = mysql_fetch_assoc($result))
    {
    echo $record['date']."<br><br>";
    }
    ?>
    </body>
    </html>

     

    through above code i am trying to echo date from database. but the problem is it echoes in this format "year month day" but i want it in "day month year" format

     

    how can i do this?

  5. hi i create a pagination and its code is down below

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    mysql_connect("localhost");
    mysql_select_db("test");
    
    $per_page = 5;
    $start = $_GET['start'];
    
    $record_count = mysql_num_rows(mysql_query("select * from data"));
    
    $max_pages = $record_count/$per_page;
    
    if(!$start)
    $start = 0;
    
    $get = mysql_query("select * from data limit $start, $per_page");
    while($row=mysql_fetch_assoc($get))
    {
    $name = $row['name'];
    $age = $row['age'];
    
    echo $name." (".$age.")<br>";
    }
    $prev = $start - $per_page;
    $next = $start + $per_page;
    
    if(!($start<=0))
    echo "<a href='pagination.php?start=$prev'>Prev</a> ";
    
    $i=1;
    
    for($x=0;$x<$record_count;$x=$x+$per_page)
    {
    if($start!=$x)
    	echo " <a href='pagination.php?start=$x'>$i</a> ";
    else
    	echo " <a href='pagination.php?start=$x'><b>$i</b></a> ";
    $i++;
    }
    
    if(!($start>=$record_count-$per_page))
    echo " <a href='pagination.php?start=$next'>Next</a>";
    ?>
    </body>
    </html>
    

     

    problem in this code is when i load this page first time then it displays this error

    Notice: Undefined index: start in D:\wamp\www\examples\pagination.php on line 14

     

    but when i click next or prev buttons then it works fine.

    how this can be solved?

  6. hi

     

    i have following code

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <!--<meta http-equiv="refresh" content="51;url=quiz2action.php" />-->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <div id = "time"></div>
    
    <script type = "text/javascript">
    }
    
    function display(secs) {
    if (secs <= 0) { 
    alert("Your time is up!");
    return;
    }
    secs--;
    document.getElementById("time").innerHTML = "You have " +
    Math.floor(secs/60) + ":" + (secs % 60 < 10 ? "0" : "" ) + (secs % 60) + " left";
    setTimeout("display("+secs+")",1000);
    }
    
    display(51); // 300 seconds = 5 minutes
    
    </script>
    <p>
    <form name="form1" method="post" action="quiz2action.php">
      <?php
    $db = mysql_connect("localhost");
    mysql_select_db("videoshop", $db);
    
    //$queryquestions = "SELECT * FROM quiz ORDER BY RAND()" or die();
    $queryquestions = "SELECT * FROM quiz" or die(); 
    $resultquestions = mysql_query($queryquestions) or die();
    
    while($rowquestions = mysql_fetch_array($resultquestions))
    {
       $questionid = $rowquestions['id'];
       $question = $rowquestions['question'];
       $answerone = $rowquestions['option1'];
       $answertwo = $rowquestions['option2'];
       $answerthree = $rowquestions['option3'];
       $answerfour = $rowquestions['option4'];
       echo "   
        <b>Question $questionid: $question</b><br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"1\"> $answerone <br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"2\"> $answertwo <br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"3\"> $answerthree <br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"4\"> $answerfour <br>";
       
       echo "<br><br>";
    }
    
    ?>
    </p>
      <label>
      <input type="submit" name="Submit" id="button" value="Submit">
      </label>
    </form>
    <p> </p>
    </body>
    </html>

     

    above is the code of quiz which is created in php. that quiz is fine. the problem in in js script above the php script.

    what i want is when the time of 5 mins is completed then i want to disable all those radio buttons except submit button.

     

    how can this be done?

  7. i am using this insert query

     

    $query = "INSERT into cv(quiz) values('".$score."') WHERE id='".$lastId."'" or die(mysql_error());

     

    but this is not working it displays this error

    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 'WHERE id=25' at line 1

     

    how to remove this error

  8. i have a php variable on one page

    $lastId = mysql_insert_id($db);
    echo $lastId;

     

    i want to send this variable and the value in it to second page when i click on submit button

     

    i already tried this but it is not working

    $lastId = $_POST["lastId"];

     

    this displays this error

     

    Notice: Undefined index: lastId in D:\wamp\www\dynamic\quiz2action.php on line 30

     

    how can this be solved

  9. hi i have created a dynamic select menu using php. i have a problem in that which is when the user select any value in that menu and press submit then it does not pass to next page.

     

    my code is here

     

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    $db = mysql_connect("localhost");
    mysql_select_db("test", $db);
    $query = "SELECT * FROM day" or die(mysql_error()); // id='".$id."'
    //echo $query;
    $result = mysql_query($query) or die(mysql_error());
    
    
    ?>
    <form name="form1" method="post" action="date.php">
      <label>Date:
      <select name="day" id="day">
      <?php while( $row = mysql_fetch_array($result) ) { ?>
        <option value="<?php $row['id']; ?>"><?php echo $row['day']; ?></option>
        <?php } ?>
      </select>
      </label>
      <p>
        <label>
        <input type="submit" name="button" id="button" value="Submit">
        </label>
      </p>
    </form>
    </body>
    </html>
    

     

    the next page is

    <?php
    $day = $_POST["day"];
    
    echo $day;
    ?>

  10. i have following form for date

     

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form name="form1" method="post" action="date.php">
      <label>Date:
      <select name="day" id="day">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
      </select>
      </label>
      -
      <label>
      <select name="month" id="month">
        <option value="1">Jan</option>
        <option value="2">Feb</option>
        <option value="3">Mar</option>
        <option value="4">Apr</option>
        <option value="5">May</option>
      </select>
      </label> 
      -
      <label>
      <select name="year" id="year">
        <option value="2000">2000</option>
        <option value="2001">2001</option>
        <option value="2002">2002</option>
        <option value="2003">2003</option>
        <option value="2004">2004</option>
      </select>
      </label>
      <p>
        <label>
        <input type="submit" name="button" id="button" value="Submit">
        </label>
      </p>
    </form>
    </body>
    </html>
    

     

    and here is the php page

     

    <?php
    $day = $_POST["day"];
    $month = $_POST["month"];
    $year = $_POST["year"];
    
    $date = date($day." ".$month." ".$year);
    //$date = date("Y m d");
    echo $date;
    $db = mysql_connect("localhost");
    mysql_select_db("test", $db);
    $query = "insert into date
    						(
    							date
    						) 
    							values
    						(
    							'".$date."'
    						)";
    //echo $query;
    $result = mysql_query($query) or die(mysql_error());
    
    echo "your date is added";
    ?>

     

    when i select any date from form and press submit button it adds only this 0000-00-00 to my table. i want date to be inserted to my table not 0s. how can i solve this problem

  11. hi

     

    i have following script and i want to a problem in it. the problem is when this page first loads it displays this error

    `Notice: Undefined index: page in D:\wamp\www\dynamic\index1.php on line 26`

    and then it displays the content in home.php which is in else statment. this only occurs when the page loads for the first time. after that if i click any link it works fine.

     

    <body>
    <table width="70%" align="center">
    <tr>
        	<td>
            	<h1>My Web Page</h1>
            </td>
        </tr>
    </table>
    <table width='70%' align="center">
    <tr>
    	<td width="13%" valign="top" align="left">
            	<b>
                <a href="index1.php?page=home">Home</a><br>
               	<a href="index1.php?page=tutorials">Tutorials</a>
              </b>
          </td>
          <td width="87%" align="left">
            	<?php
    				if($_GET["page"])
    				{
    					$page = $_GET["page"];
    					include($page.".php");
    				}
    				else
    				{
    					include("home.php");
    				}
    
    		?>      
           </td>
    </tr>
    </table>
    </body>

     

    how this problem can be removed.

  12. i have a quiz website and timer script js. what i want is when the user starts quiz, countdown of five minutes will also start. user will hhave to complete quiz in five mins. if user does not succeed to complete in given time then user will automatically taken to next page and his score will shown to him.

     

    i already have scripts for both quiz and timer but i dont know how do i integrate them and how to take user to next page. my code is here

     

    quiz.php

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <div id = "time"></div>
    
    <script type = "text/javascript">
    
    function display(secs) {
    if (secs <= 0) { 
    alert("Your time is up!");
    return;
    }
    secs--;
    document.getElementById("time").innerHTML = "You have " +
    Math.floor(secs/60) + ":" + (secs % 60 < 10 ? "0" : "" ) + (secs % 60) + " left";
    setTimeout("display("+secs+")",1000);
    }
    
    display(301); // 300 seconds = 5 minutes
    
    </script>
    <p>
    <form name="form1" method="post" action="quiz2action.php">
      <?php
    
    $db = mysql_connect("localhost");
    mysql_select_db("videoshop", $db);
    
    $queryquestions = "SELECT * FROM quiz" or die(); 
    $resultquestions = mysql_query($queryquestions) or die();
    
    while($rowquestions = mysql_fetch_array($resultquestions))
    {
       $questionid = $rowquestions['id'];
       $question = $rowquestions['question'];
       $answerone = $rowquestions['option1'];
       $answertwo = $rowquestions['option2'];
       $answerthree = $rowquestions['option3'];
       $answerfour = $rowquestions['option4'];
       echo "   
        <b>Question $questionid: $question</b><br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"1\"> $answerone <br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"2\"> $answertwo <br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"3\"> $answerthree <br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"4\"> $answerfour <br>";
       
       echo "<br><br>";
    }
    
    ?>
    </p>
    
      <label>
      <input type="submit" name="button" id="button" value="Submit">
      </label>
    </form>
    <p> </p>
    </body>
    </html>

  13. i find what was the problem. that if condition should be like this

     

    if($result && mysql_num_rows($result))

    {

          $score++;

    }

     

    now this quiz website is almost completed except one thing and that is timer. i want to a five minutes timer. the user will have five minutes to complete the quiz if user doesnt succeed in completing quiz in given time then quiz should disable and shows him his result. that timer should appear on the page.

    how this can be achieve

  14. still same problem i change the values in correct column as you said but still have the same problem

     

    it displays the following output on second script

     

    SELECT * FROM quiz WHERE id=1 AND correct=2

    SELECT * FROM quiz WHERE id=2 AND correct=3

    SELECT * FROM quiz WHERE id=3 AND correct=1

    SELECT * FROM quiz WHERE id=4 AND correct=3

    SELECT * FROM quiz WHERE id=5 AND correct=2

     

    your score is 5/5

×
×
  • 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.