Jump to content

kney

Members
  • Posts

    140
  • Joined

  • Last visited

    Never

Posts posted by kney

  1. But this part of ur code will give more than 1 record right?

     

    <?php
    $result = mysqli_query ( $dbc, $query ); // Run The Query
    $rows = mysqli_num_rows($result);
    
    $question = stripslashes($row['question']);
    ?>
    

     

    and btw, where does the $row['question'] come from?

  2. Can't think of anything else right now..

    Hope this works..

     

    <?php
    $query1 = mysql_query("SELECT b_id FROM benefits");
    $i = 1;
    while ($row = mysql_fetch_array($query1)) {
         $count = mysql_num_rows($query1);
    
         if($i < $count){
         	echo $row['b_id'] . ",";
         }else{
    echo $row['b_id'];
         }
         $i++;
    }
    ?>
    

  3. I mean this:

     

    <?php
    session_start();
    $myusername=$_SESSION['myusername'];
    require "database.php";
    
    $messageid = $_GET['messageid'];
    $message = mysql_query("SELECT * FROM messages WHERE message_id = '$messageid' AND to_user = '$myusername'");
    $message=mysql_fetch_assoc($message);
    
    // problem is here atm getuname returns Resource id  instead of the username iam trying to reply to //
    $getuname= mysql_query("SELECT from_user FROM messages Where message_id='$message_id' AND to_user ='$myusername'");
    
    $uname = mysql_fetch_row($getuname);
    
    echo "<h1>Title: ".$message['message_title']."</h1><br><br>";
    echo "<h3>From: ".$message['from_user']."<br><br></h3>";
    echo "<h3>Message: <br>".$message['message_contents']."<br></h3>";
    
    echo '<form name="backfrm" method="post" action="inbox.php">';
    echo '<input type="submit" value="Back to Inbox">';
    // this where i need to the to user to carry over to the next page//
    echo '<a href="reply.php?username='". $uname[0] ."'">reply</a><br />';
    echo '</form>';
    ?>
    </body>
    </html>

  4. I don't know if this code is 100% correct but here goes...

     

     

    The HMTL page:

     

    <html>
    <head>
    <script type="text/javascript">
    function showHint(str)
    {
    if (str.length==0)
      {
      document.getElementById("txtHint").innerHTML="";
      return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","gethint.php?q="+str,true);
    xmlhttp.send();
    }
    </script>
    </head
    <body>
    
    <p><b>Start typing a name in the input field below:</b></p>
    <form>
    First name: <input type="text" onkeyup="showHint(this.value)" size="20" />
    </form>
    <p>Suggestions: <span id="txtHint"></span></p>
    
    </body>
    </html>

     

    The PHP page: (I think the while loop needs to be different)

     

    <?php
    $sql = mysql_query("SELECT name from members");
    
    //get the q parameter from URL
    $q=$_GET["q"];
    
    //lookup all hints from array if length of q>0
    if (strlen($q) > 0)
      {
      $hint="";
      while($result == mysql_fetch_array($sql))
        {
        if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
          {
          if ($hint=="")
            {
            $hint=$result[0];
            }
          else
            {
            $hint=$hint." , ".$result[0];
            }
          }
        }
      }
    
    // Set output to "no suggestion" if no hint were found
    // or to the correct values
    if ($hint == "")
      {
      $response="no suggestion";
      }
    else
      {
      $response=$hint;
      }
    
    //output the response
    echo $response;
    ?>
    

  5. XML Parsing Error: junk after document element

    Location: http://localhost:8080/php/script.php?file=test

    Rule Number 6, column 1:

     

    <?php
    
    session_start();
    
    define("CONST1", 5);
    define("CONST2", 10);
    define("CONSTERROR", false);
    define("REFRESH_TIME", 2);
    
    if(isset($_SESSION['views'])){
    $_SESSION['views']=$_SESSION['views']+1;
    }else{
    $_SESSION['views']=1;
    }
    
    if(!isset($_SESSION['decision'])){
    $_SESSION['decision'] = rand(1, CONST2);
    }
    
    function respond_xml($status, $message)
    {
        $out = new XMLWriter();
        $out->openURI("php://output");
        $out->setIndent(true);
    
        $out->startDocument("1.0", "ISO-8859-1");
        $out->startElement("statuscheck");
        $out->writeElement("status", $status);
        $out->writeElement("message", $message);
        $out->endElement();
        $out->endDocument();
        $out->flush();
    }
    
    function main()
    {
        header("Refresh: " . REFRESH_TIME . "; URL=http://localhost:8080/php/script.php?file=test");
        header("Content-type: text/xml");
    
        if (!isset($_GET["file"]))
            respond_xml("ERROR", "File parameter missing");
    
        while($_SESSION['views'] < CONST1){
            respond_xml("NOT OK", "File does not exist. ");
        }
    
        if($_SESSION['views'] >= CONST1 && CONSTERROR == true){
            respond_xml("ERROR", "Some error has occured!");
        }
        else{
            if($decision == 1){
                respond_xml("OK", "File exists. Decision: " . $_SESSION['decision']);
            }
            else{
                respond_xml("NOT OK", "File does not exist. Decision: " . $_SESSION['decision']);
            }
        }
    
    }
    
    main();
    
    ?>
    

  6. he means like this

     

    <?php
    session_start();
    include_once  'functions.php'; //This includes some common functions
    include_once  'connection.php';
    // Check if we have established an authenticated
    if (!isset($_SESSION["authenticatedUser"]))
    {
          $_SESSION["Login_Error"] = "Please Login before you process your order";
          header("Location: login.php");
    }
    
      //Otherwise we know all the details.
       $errorString = "";
      //Get the details from the payment page - validation required
        $total=$_POST["total"];
        $creditcard = trim($_POST["creditcard"]);
         if (empty($creditcard))
            $errorString .="The credit card field cannot be blank.";
         else if (strlen($creditcard) < 6)
            $errorString .="<br />Credit card field must be at least 6 characters.";             
        $expiry = trim($_POST["expiry"]);
         if (empty($expiry))
            $errorString .="<br />The expiry date cannot be blank.";
        //Create a timestamp for the order
        $date = time();
        //Check to see if temporary basket is OK
        if (!empty($errorString))
        {
         
          header("Location: payment.php?error=$errorString&total=$total");
        }
        else   // Else Update the cust_id for the items
        {   
           //Update the temporary order to a permanent order by associating a customer id
           $createOrder = "INSERT INTO Orders VALUES ".
                      "id = ".$_SESSION["id"]." , date = '$date', ".
                      " creditcard = '$creditcard', expirydate= '$expiry' " ;
          print $createOrder;
           if (!($result =  mysql_query ($createOrder, $connection)))
             die("Error with Creating order Query in process order"); 
            else  $OrderId = mysql_insert_id();   
           
        //Now add the basket items to the orders
        foreach ($_SESSION["basket"] as $basketItemArray) {
          //Calls the getPrice function in functions.php
          $itemPrice = getPrice($connection, $basketItemArray["ItemId"]);
           //Create the query to insert the item
         $addItem = "INSERT INTO Order_items VALUES (".$OrderId.",".$basketItemArray["ItemId"].",".$basketItemArray["quantity"].",".$itemPrice.")";         
           if (!($result =  mysql_query ($addItem, $connection)))
             die("Error creating item in addItem Query in process order"); 
         }     
        //Relocate to Receipt
         header("Location: orderReceipt.php?OrderId=$OrderId");
       } //end else 'No errors'
    ?> 

  7. It's usually a good idea to use <?php ?> to maintain portability.  If what you write gets moved to a system that has short_open_tag turned off (like your current system it seems) your code won't break.

  8. It has to be on the same page:

    If you want to use it on another page use:

    <?php
    $_SESSION['WhateverNameYouLike'] = $_POST['frmhowhear'];
    ?>
    

     

    But you got to remember to use

     

    <?php
         session_start();
    ?>
    

     

    on each page u use the session variable

    And to redirect to another page use this

     

    <?php
    if (isset($_POST['WhateverYourButtonsNameIs'])) { 
         header('Location: http://www.example.com/');
    }
    ?>
    

  9. I hope this helps...

     

    (Look in the code, I added a comment)

     

    Thanks very much for the help!

     

    There is a poblem still with score.php. I get the following error:

     

    Parse error: syntax error, unexpected '{' in line 28

     

    Why would this be?  I have tried swappiing the { around and deleting with the same result

     

    Help, as always, appreciated.

     

    Score.php

    
    <?php
      
    require_once('connectvars1.php');
    
    //Connect to the database
            $dbc = mysqli_connect(DB_Host, DB_User, DB_Password, DB_Name);
    
    // get all answers and add them to an array
    $query = 'SELECT autokey, answer FROM questions';
    
    $result = mysql_query($query);
    
    while ($row = mysql_fetch_assoc($result))
    
    {    
    $question_id = $row['autokey'];    
    
    $answer = $row['answer'];    
    
    $question_answers[$question_id] = $answer;
    }
    
    // loop through the posted ansers and compare
    
    foreach($question_answers as $question_id => $question_answer)
    {
    if(isset($_POST['question'][$question_id])    
           {
         $user_answer = $_POST['question'][$question_id];        
         if($user_answer == $question_answer)        
         {            
    	     echo "<p>Your answer was correct for Q{$question_id}!</p>";        
         }        
         else        
         {          
    	     echo "<p>Your answer was incorrect for Q{$question_id}.</p>";      
                 // you forgot to close here  
         }
                // you forgot to close here
    }
    }
       
        else    
    {        
    
    echo "<p>You didn't give an anser for Q{$question_id}.</p>";    
    }
    
    } 
    ?>
    

  10. <?php

    include ('connection.php');

     

    $username = mysql_real_escape_string($_POST['username5']);

    $password = mysql_real_escape_string($_POST['password5']);

     

    $results = mysql_query("SELECT url FROM merchants WHERE username='$username' AND password='$password'");

    if (mysql_num_rows($results)) {

        $values = mysql_fetch_array($results);

        $url = $values['url'];

        header("Location: $url");

    } else {

        echo 'Wrong data yo!';

    }

    ?>

     

    So something like this:

     

    <?php
    include ('connection.php');
    
    $username = mysql_real_escape_string($_POST['username5']);
    $password = mysql_real_escape_string($_POST['password5']);
    
    $results = mysql_query("SELECT * FROM merchants WHERE username='$username' AND password='$password'");
    if (mysql_num_rows($results)) {
         $values = mysql_fetch_array($results);
         $url = $values['url'];
         $_SESSION['userID'] = $values['id'];
         header("Location: $url");
    } else {
         echo 'Wrong data yo!';
    }
    ?>

     

    and on the other page where you check whether he can't view the page or not you do

     

    <?php
          if(!isset($_SESSION['userID'])){
                  // you can't watch the page
          }else{
                 // you can watch the page
                 // paste ur page code in here
          }
    ?>
    

  11. are you saying that every time the page is changed the session will be stopped for some reason?

    I'll try to do what your asking but I don't know why I should start it every time a page has been changed. Could you elaborate?

     

    edit: it works 0.0!

    please tell me what was wrong :D! I'd love to know.

    b.t.w. does this mean I have to start the session on every page that I go to from now on?

     

    If you don't put session_start(); on every page the session will not stay.

    Just include it in a header file and ur fine :)

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