Latest Posts in PHP

in PHP
 
0
 

Hi, all

I'm working on a website that is comprised of two iframes within several nested divs ( the frames named "frame-menu" and "frame-main"). Displaying as such:

<div id="wrapper">
    <div id="header">Header text/image goes here</div>
    <div id="menu"><iframe name="frame-menu" id="frame-menu" src="menu.php" frameborder="0" height="30"></iframe></div>
    <div id="main"><iframe name="frame-main" id="frame-main" src="login.php" frameborder="0" width="878" height="700"></iframe></div>
    <div id="footer"><A HREF="about.php" TARGET="frame-main">About Us</A> - Contact</div>
    <div id="bottom">&copy;2015</div>
</div>

When the user logs on via the 'login.php' form, I'd like to reload the 'menu.php' file in the 'frame-menu' frame, to run the PHP conditionals to change the "log in" link to a "log out" link. However, I can't figure out a way to get the menu.php file to reload.

I've tried adding headers to the code of beginning of the page that loads after the user logs in...

header('Window-target: frame-menu');
header('Location: https://www.website.com/menu.php');

and had no luck.

I know this can be accomplished via Javascript, but I'm rather hesitant to use it, as users can turn it off, and, well, completely screw up my login process...

Does anyone have any suggestions for me on this?

Thank you!

Re: in PHP
 
0
 

Hi,

check the data models in the Education section at:

If it does not help, write about your project, try to define the basic information you would need to create such application. This should help you to shed some light and then you can ask more specific help, at the moment your question is very generic, so it's difficult to give an appropriate help.

Re: in PHP
 
0
 

Hi,

I got the same issues that you have described with both APIs, but standing at the documentation I cannot help:

as it seems that your queries are correct, and their results aren't. Try to contact their assistance services to understand if you have to do something different.

in PHP
 
0
 

I want to display images based on what user checked from number of checkboxs. I'm trying this code, but it not working

<!Doctype html>
<html><body>
<form method="post" action="" id="myForm">
    <div class="opt-first">
    <h1><b>Subject</b></h1>
        <input type="checkbox" value="Account/Finance" name="subject[]" /> Account/Finance<br />
        <input type="checkbox" value="Marketing" name="subject[]" /> Marketing<br />
        <input type="checkbox" value="" name="subject[]" /> Other
    </div>

    <div class="opt">
    <h1><b>Type</b></h1>
        <input type="checkbox" value="Exam" name="Type[]" /> Exam<br />
        <input type="checkbox" value="Project" name="Type[]" /> Project<br />
        <input type="checkbox" value="Assignment" name="Type[]" /> Assignment
    </div>

    <div >
    <h1><b>Tasks</b></h1>
        <input type="checkbox" value="Report" name="Task[]" /> Report<br />
        <input type="checkbox" value="Presentation" name="Task[]" /> Presentation<br />
        <input type="checkbox" value="Assay" name="Task[]" /> Assay<br />
        <input type="checkbox" value="Case study" name="Task[]" /> Case study<br />
        <input type="checkbox" value="Teaching" name="Task[]" /> Teaching<br/>
        <input type="checkbox" value="Website Design" name="Task[]" /> Website Design<br/>
        <input type="checkbox" value="Short Answer" name="Task[]" /> Short Answer

    </div>
    <div><h1><b>Group/Individual </b></h1>
            <input type="checkbox" value="Yes" name="member[]" /> Group Work<br />
        <input type="checkbox" value="" name="member[]" /> Individual <br />
</div>    
    <input type="submit" value="Show" class="submit" />
</form>

<?php

if (isset($_POST['Subject']) && isset($_POST['Type']) && isset($_POST['Task'])&& isset($_POST['member']))
{
    $con=mysqli_connect("localhost","FYP","123","FYP");
echo "<div>";

    foreach ($_POST['Subject'] as $Subject)
    {
        foreach ($_POST['Type'] as $Type)
        {
            foreach ($_POST['Task'] as $Task)
            {
                foreach ($_POST['member'] as $member)
                {
                $sql= mysqli_query($con, "SELECT R_Name FROM rubric_sample WHERE Subject='$Subject' AND Type='$Type' AND Task='$Task' AND Group='$member'");
                while($row = mysqli_fetch_array($sql)){
                    echo "<img src='/Rubrics/".$row['R_Name']." alt='Rubrics Sample ' style='width:128px;height:128px'>";
                }
                }
            }
        }
    }

  echo "</div>";
}

?>



</body></html>

Could you please help me to correct my code or suggest me a better way to do it

in PHP
 
0
 

Hello,

I have created a select product using a different way like frst we select product from dropdown and click on next button on next page the dropdown have to show the company names i.e only that companies which belongs to the selected product but i am bit confused how it will work i tried to use v_id like company id but its not working can anyone help me out.

Database structure

CREATE TABLE IF NOT EXISTS `products` (
  `prod_id` int(11) NOT NULL AUTO_INCREMENT,
  `product_name` varchar(255) NOT NULL,
  `product_price` int(20) NOT NULL,
  `prod_details` text NOT NULL,
  `v_id` int(11) NOT NULL,
  `v_name` varchar(45) NOT NULL,
  PRIMARY KEY (`prod_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;

--
-- Dumping data for table `products`
--

INSERT INTO `products` (`prod_id`, `product_name`, `product_price`, `prod_details`, `v_id`, `v_name`) VALUES
(6, 'Samsung Elite Book', 1200, 'Samsung Ci3 Laptop with 8GM ram 2 years official international warranty ', 3, 'Samsung'),
(8, 'Samsung Galaxy S5', 400, 'This is anew just launched product having great features then ever buy now and get your self with a valuable product', 3, 'Samsung'),
(9, 'Samsung Galaxy S4', 350, 'Samsung Galaxy S4 this product is one of the most using cellphone in the market', 3, 'Samsung'),
(10, 'LED', 0, 'wewewewe', 3, 'Samsung'),
(11, 'TV ', 500, 'ajksdjadkaskdbkasdbkasdklkasdkbkasdksbadklbaskdbjksad', 6, 'Azeem'),
(12, 'Iphone', 500, 'gasdhasgdghasdgha', 7, 'Noman'),
(13, 'Air Condintion', 600, 'This is new product in market now', 3, 'Samsung');

First page when you try to select the product

<form method="POST" action="select_vendor.php?id=<?php echo $product_id; ?>">
            <div id="order">
                <?php
                    $query      = "SELECT * FROM products";
                    $query_confirm  = mysqli_query($connection, $query);

                    echo "<select name='product'>";
                    echo "<option>" . "Select Product" . "</option>";
                    while ($row_product = mysqli_fetch_assoc($query_confirm)) {
                        $product_id = $row_product["v_id"];
                        $product = $row_product["v_name"];
                        echo "<option>" . $product . "</option>";
                    }

                    echo "</select>";
                ?>

                <input type="submit" value="NEXT >" class="btn-green" name="submit" />
            </div>
            </form>

Now this is the second page where you wil be seleting the company of your choice

<?php
                if (isset($_POST['submit'])) {
                    $product_info = $_POST['product'];
                }
                $id = $_GET['id'];
                echo "Your Select Product" . " " .$product_info;
                echo "<br />";
                echo "<a href='index.php'>Cancel</a>";

            ?>


            <div id="order">
                <?php
                    $query      = "SELECT * FROM products WHERE v_id={$id} LIMIT 1";
                    $query_confirm  = mysqli_query($connection, $query);

                    echo "<select name='product'>";
                    echo "<option>" . "Select Vendor" . "</option>";
                    while ($row_product = mysqli_fetch_assoc($query_confirm)) {
                        $product_vendor = $row_product["v_name"];
                        echo "<option>" . $product_vendor . "</option>";
                    }

                    echo "</select>";
                ?>

                <input type="submit" value="VIEW PRODUCT >" class="btn-green" />
            </div>

I am also not getting the link as well on the action if I had get the link i beleive it would be easy enough to to do so

Thank You in advance

Re: in PHP
 
1
 

Enclose each row (and ID and a delete button) within form tags and add a hidden input that holds the value. You will have as many forms as there rows. When you delete (submit), the value in the hidden input field will get over to the next script. And you do not need a name attribute in the list item element.

<h1>YOUR COURSES</h1>
<ol>
<?php
$con=mysqli_connect("localhost","FYP","123","FYP");
$sql= mysqli_query($con, "SELECT C_Code FROM F_COURSES WHERE F_ID=".$_SESSION['userid']);
while($row = mysqli_fetch_array($sql)){

    // I added a little bit of a styling to the form to display correctly
    echo "<li><form method='post' action='delete.php' style='display:inline;'>" . $row['C_Code'] . "<input type='submit' value='Delete'>";

    // this line adds a hidden input
    echo "<input name='course' type='hidden' value='" . $row['C_Code'] . "'></form></li>";
}
?>
</ol>

I hope having a form inside a list item element isn't bad coding. But I've seen that arround.

Comments
Thank you it work
Re: in PHP
 
0
 

This was exactly what i wanted. So grateful.

I tried implementing scribd which worked fine except that it doesnt give me the exact search like when using their front end search.

Below is my code:

    $result = simplexml_load_file("http://api.scribd.com/api?method=docs.search&api_key=$scribd_api_key&num_start=0&num_results=100&query=$barcode&my_user_id=33616452&scope=all&simple=false");
    //echo $result->result_set->result[0]->title;
     $totalResultsAvailable = $result->result_set[totalResultsAvailable];
     $totresultsreturned = $result->result_set[totalResultsReturned];
    // echo "<tr><td>&nbsp;</td><td>No of results: $totalResultsAvailable </td></tr>";
    foreach ($result->result_set->result as $rsinfo):
        $doc_id=$rsinfo->doc_id;
        $access_key=$rsinfo->access_key;
        $title=$rsinfo->title;
        $description=$rsinfo->description;
        $tags=$rsinfo->tags;
        $license=$rsinfo->license;
        $thumbnail_url=$rsinfo->thumbnail_url;
        $page_count=$rsinfo->page_count;
        $download_formats=$rsinfo->download_formats;
        $reads=$rsinfo->reads;
        $uploaded_by=$rsinfo->uploaded_by;
        $uploader_id=$rsinfo->uploader_id;
        $when_uploaded=$rsinfo->when_uploaded;
        $when_updated=$rsinfo->when_updated;
        $block_count=$rsinfo->block_count;
endforeach;
Re: in PHP
 
0
 

That... looks very unfamilliar to me in terms of creating and running procedures... try this instead:

delimiter //
drop procedure if exists GetEvents//
create procedure GetEvents(IN iVal1 int,
                           IN iVal2 int)
begin

select * from myTable where Col1 = iVal1 and Col2 = iVal 2;

end//
delimiter ;

then to call...

you will likely need to use mysqli->multi_query()

because of this, you will likely have to manually sanitze your incoming data, using mysql->real_escape_string() on each parameter.

Of course, from there, it's just using the PHP/MySQLi interface and going from there...

You seem to be familliar with how to connect, etc.. so I spared you that bit. If you need any other help, show some new code and we can go from there.

Side note: if I recall, when I started getting back into PHP a while ago, PDO had awful support for stored procedures. THe only interface for them was with mySQLi, unless you were using PDO with a TSQL server (which is microsoft, not mySQL/whoever owns it now). Anyone know if PDO is now a good interface for mySQL and stored procedures?

Re: in PHP
 
1
 

Try if it works fine from the mysql client, because it returns this error to me:

ERROR 1414 (42000): OUT or INOUT argument 2 for routine dbase.test_proc is not a variable or NEW pseudo-variable in BEFORE trigger

You can try to bypass the error by setting a variable before calling the procedure, like this:

DROP PROCEDURE IF EXISTS test_proc;
DELIMITER $$
CREATE PROCEDURE `test_proc`(In user_id varchar(100), OUT message varchar(1000))
BEGIN
 set message ='OK';
END $$
DELIMITER ;

-- as suggested here: https://bugs.mysql.com/bug.php?id=25970#c195094
SET @test = 'world';
CALL test_proc('hello', @test);
SELECT @test;

In PDO this becomes:

<?php

    $conn = require './pdo.php';

    $ret = 'world';
    $sso = 'hello';

    $stmt1 = $conn->prepare("SET @test = ?");
    $stmt1->execute(array($ret));

    $stmt2 = $conn->prepare("CALL test_proc(?, @test)");
    $stmt2->execute(array($sso));

    $query = $conn->query("SELECT @test as result")->fetch(PDO::FETCH_OBJ);

    echo $query->result;

Which seems to return fine to me: OK.

Re: in PHP
 
0
 

To define different formats you have to append the parameter httpAccept to the link, for example:

&httpAccept=application/json
&httpAccept=application/xml
&httpAccept=application/atom+xml
&httpAccept=application/rss+xml

Documentation: http://www.nature.com/developers/documentation/api-references/opensearch-api/#apiref

So to get the document in XML format you would write:

$url = 'http://api.nature.com/content/opensearch/request?queryType=searchTerms&query=darwin&httpAccept=application/xml';

Accessing the information is not simple, here I will explain three methods with, from the hardest to the easiest:

  • xml
  • json
  • json (as array)

XML

When using the XML method you have to check the source to read the namespaces used to define the document. With SimpleXML you can get the list by using this method getDocNamespaces():

$content = simplexml_load_file($url);
print_r($content->getDocNamespaces(true, true));

Which returns:

Array
(
    [xsi] => http://www.w3.org/2001/XMLSchema-instance
    [srw] => http://docs.oasis-open.org/ns/search-ws/sru-2-0-response
    [] => http://docs.oasis-open.org/ns/search-ws/sru-2-0-response
    [ns1] => http://docs.oasis-open.org/ns/search-ws/sru-2-0-response
    [dc] => http://purl.org/dc/elements/1.1/
    [dcterms] => http://purl.org/dc/terms/
    [pam] => http://prismstandard.org/namespaces/pam/2.0/
    [prism] => http://prismstandard.org/namespaces/basic/2.1/
    [xhtml] => http://www.w3.org/1999/xhtml
    [ns2] => http://docs.oasis-open.org/ns/search-ws/sru-2-0-response
    [ns3] => http://docs.oasis-open.org/ns/search-ws/sru-2-0-response
    [ns4] => http://www.nature.com/opensearch/ns/sru/
)

If you read the document structure you will see:

<records>
    <record>
        <recordData>
            <pam:message
                xmlns:dc="http://purl.org/dc/elements/1.1/"
                xmlns:dcterms="http://purl.org/dc/terms/"
                xmlns:pam="http://prismstandard.org/namespaces/pam/2.0/"
                xmlns:prism="http://prismstandard.org/namespaces/basic/2.1/"
                xmlns:xhtml="http://www.w3.org/1999/xhtml"
                xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
                xsi:schemaLocation="http://prismstandard.org/namespaces/pam/2.0/ http://prismstandard.org/schemas/pam/2.1/pam.xsd">

                <pam:article>
                    <xhtml:head>
                        <dc:identifier>doi:10.1038/081007a0</dc:identifier>
                        <dc:title>&lt;i&gt;The &lt;span&gt;Darwin&lt;/span&gt; Celebrations at Cambridge&lt;/i&gt;</dc:title>
                        ...
                        <prism:publicationDate>1909-07-01</prism:publicationDate>
                        ...

So to access the information under the object recordData you have to load the namespaces for:

  • pam:
  • xhtml:
  • dc: & prism:

Basically to get the first record you have to do this:

# loading the content, no need of file_get_contents
$content = simplexml_load_file($url);

# loading the pam namespace
$pam    = $content->records->record[0]->recordData->children('http://prismstandard.org/namespaces/pam/2.0/');

# loading the xhtml namespace
$xhtml  = $pam->message->article->children('http://www.w3.org/1999/xhtml');

# loading the dc namespace
$dc     = $xhtml->head->children('http://purl.org/dc/elements/1.1/');

# loading the prism namespace
$prism  = $xhtml->head->children('http://prismstandard.org/namespaces/basic/2.1/');

print_r($dc);
print_r($prism);

Which returns:

# dc objects
SimpleXMLElement Object
(
    [identifier] => doi:10.1038/081007a0
    [title] => <i>The <span>Darwin</span> Celebrations at Cambridge</i>
    [publisher] => Nature Publishing Group
    [description] => <p>A GENERAL account of the proceedings of the Darwin celebrations at Cambridge on June 22-24, and a list of distinguished delegates and other representatives of science who came from the four corners of the earth to proclaim the greatness of Charles Darwin and his work, was given in last week's NATURE. As the chief speeches were delivered on the day we went to press, and on Thursday last, we were prevented from including any report of them in the article, which, however, we are now able to supplement. Short speeches were made in the Senate House on June 23, when the delegates were received by the Chancellor, Lord Rayleigh, and the addresses were presented; and also at the banquet given in the evening of that day.</p>
)

# prism objects
SimpleXMLElement Object
(
    [productCode] => nature
    [publicationName] => Nature
    [doi] => 10.1038/081007a0
    [publicationDate] => 1909-07-01
    [volume] => 81
    [number] => 2070
    [startingPage] => 7
    [endingPage] => 14
    [url] => http://dx.doi.org/10.1038/081007a0
    [genre] => Research
    [copyright] => © 1909 Nature Publishing Group
)

JSON

By using JSON you don't have to load the namespaces. For example:

$url = 'http://api.nature.com/content/opensearch/request?queryType=searchTerms&query=darwin&httpAccept=application/json';
$content = json_decode(file_get_contents($url));

The variable $content will return some objects that will be accessible through the alternative syntax for the variable names:

print_r($content->feed->entry[0]->{'sru:recordData'}->{'pam:message'}->{'pam:article'}->{'xhtml:head'});

This will return the same information returned by the XML example:

stdClass Object
(
    [dc:identifier] => doi:10.1038/081007a0
    [dc:title] => <i>The <span>Darwin</span> Celebrations at Cambridge</i>
    [prism:productCode] => nature
    [dc:creator] => 
    [prism:publicationName] => Nature
    [prism:issn] => 
    [prism:eIssn] => 
    [prism:doi] => 10.1038/081007a0
    [dc:publisher] => Nature Publishing Group
    [dc:description] => <p>A GENERAL account of the proceedings of the Darwin celebrations at Cambridge on June 22-24, and a list of distinguished delegates and other representatives of science who came from the four corners of the earth to proclaim the greatness of Charles Darwin and his work, was given in last week's NATURE. As the chief speeches were delivered on the day we went to press, and on Thursday last, we were prevented from including any report of them in the article, which, however, we are now able to supplement. Short speeches were made in the Senate House on June 23, when the delegates were received by the Chancellor, Lord Rayleigh, and the addresses were presented; and also at the banquet given in the evening of that day.</p>
    [prism:publicationDate] => 1909-07-01
    [prism:coverDate] => 
    [prism:aggregationType] => 
    [prism:volume] => 81
    [prism:number] => 2070
    [prism:startingPage] => 7
    [prism:endingPage] => 14
    [prism:url] => http://dx.doi.org/10.1038/081007a0
    [prism:channel] => 
    [prism:section] => 
    [dc:subject] => 
    [prism:genre] => Research
    [prism:copyright] => © 1909 Nature Publishing Group
)

JSON (as array)

The last method requires a simple change to the json_decode() function, by adding the second argument as boolean TRUE the object will be converted to a simple array, so:

$content = json_decode(file_get_contents($url), TRUE);
print_r($content['feed']['entry'][0]['sru:recordData']['pam:message']['pam:article']['xhtml:head']);

Hope is this what you were asking for.

Solved in PHP
 
0
 

this code will display all courses user has

<h1>YOUR COURSES</h1> <form action="delete.php" method="POST"><ol>
    <?php
    $con=mysqli_connect("localhost","FYP","123","FYP");
$sql= mysqli_query($con, "SELECT C_Code FROM F_COURSES WHERE F_ID=".$_SESSION['userid']);
while($row = mysqli_fetch_array($sql)){
echo "<li name='course'>".$row['C_Code']."<input type='submit'  value='Delete'>";}

    ?></ol></form>

I need when user click on delete button that course delete from F_courses

<?php
session_start();
if (! empty($_SESSION['logged_in']))
{
    $con=mysqli_connect("localhost","FYP","123","FYP");
    $id=$_SESSION['userid'];
    $course=$_POST["course"];


            $sql="DELETE FROM F_COURSES WHERE F_ID='$id' AND C_Code='$course'";
            mysqli_query($con,$sql);

            header ("location: mycourses.php");

}
else
{
    echo 'You are not logged in. <a href="login.html">Click here</a> to log in.';
}

Could you please help me how to correct my code
Thank you

in PHP
 
0
 

Dear frnds..

i want to devlope a website in php for school results, website as like as indiaresult.com. But i m not getting how its database should be developed. so pls help me and share your think about it...

thank you

HITEsh

Re: in PHP
 
0
 

Below is not working either -

$data = $conn->query("call test_prod('502275248', @message);")->fetchAll(PDO::FETCH_ASSOC);
$message = $conn->query("select @message;")->fetchAll(PDO::FETCH_ASSOC);
print_r($data);
echo '<br />';
echo $message;
Re: in PHP
 
0
 

Please I'm having an issue with this even after using json_decode and simplexml_load_string

$url = 'http://api.nature.com/content/opensearch/request?queryType=searchTerms&query=military+defense';    
     $contents = file_get_contents($url); 
    $nature = simplexml_load_string($contents);
//echo $nature->{1}->records;
  //  $json = json_decode($contents, true);
echo $nature->asXML()

It is not serialized

OP Kudos: in PHP
 
0
 

Hi,
I have created a test procedure (for the sake of example to get this working) called test_proc like below -

DELIMITER $$

CREATE DEFINER=`tloken`@`%` PROCEDURE `test_proc`(In user_id varchar(100), OUT message varchar(1000))
BEGIN

 set message ='OK';
END

and calling it from php test page like below -

    $sso = $_GET['sso'];
    $ret = '';
    echo $RepExecutQry = "call test_proc(?, ?)";

$stmt = $conn->Prepare($RepExecutQry);


$stmt->bindParam(1, $sso, PDO::PARAM_INT, 10);
$stmt->bindParam(2, $ret, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 32);

$stmt->execute();

print "Values of bound parameters _after_ CALL:\n";
print "  1: {$ret} 2: {$sso}\n"     

Also tried the solution with bindValue(), but the procedure doesn't return anything.
$conn is a pdo connection object and created properly, tested with var_dump($conn) already.
any suggestions would be valued and appreciated. Thank you

Re: in PHP
 
0
 

@Sophia

hi, could you show us the form used to submit the POST values to your script?

PHP Tag Cloud