/    Sign up×
Community /Pin to ProfileBookmark

Passing row data to url

I would like to thank you guys for pointing me in the right direction last time.

I have run into another problem.

I basically have a page where users add details about a book into the data base. The user name of a person who added a particular book is also added to the dbase without the user having to enter his/her user name. And this is done using sessions. I now want the user name of the user to be displyed in the url when somenone (user) does a search about a particular book. So when the search results are displayed in the table, the user name of the person who added that book will be displayed in the url and not the table. The user name with the search term will be displayed in the url and the other search results in the table.
At the moment I managed to get it to do this but it just displays the random user name stored in the table not according to the person who added the particular book.
Hope this is clear

Here is the code where users add book details to dbase

[code=php]<?php session_start(); ?>
<?php

// suppress or turn off notice errors or warnings
error_reporting (E_ALL ^ E_NOTICE);

// checking for submit
$submit = $_POST[‘submit’];

// form data and stripping of html tags
$title = strip_tags($_POST[‘title’]);
$author = strip_tags($_POST[‘author’]);
$edition = strip_tags($_POST[‘edition’]);
$publicationdate = strip_tags($_POST[‘publicationdate’]);
$isbnnumber = strip_tags($_POST [‘isbnnumber’]);
$condition = strip_tags($_POST[‘condition’]);
$price = strip_tags($_POST[‘price’]);
$category = strip_tags($_POST[‘category’]);

$camnumber = $_SESSION[‘camnumber’];
if($submit)
{
// user registration by connecting to database
$connect = mysql_connect(“”, “”, “”);
mysql_select_db (“”);

$isbncheck = mysql_query (“SELECT isbnnumber FROM books WHERE isbnnumber =’$isbnnumber ‘”);
$count = mysql_num_rows($isbncheck);

if ($count!=0)
{
die (“<span style=’color:red’ name=’PHPSpan’><b>ISBN Number has to be unique</b></span>”);
}
// check for that all fields have been entered
if ($title&&$author&&$edition&&$publicationdate&&$isbnnumber&&$condition&&$price&&$category&&$camnumber)
{

if (!is_numeric($price))
{
echo “<span style=’color:red’ name=’PHPSpan’><b>Price must be a an interger</b></span>”;
}
else
{
// check for character length of isbn number
if (strlen($isbnnumber)>13)
{
echo “<span style=’color:red’ name=’PHPSpan’><b>Length of ISBN Number should not be more than 13 characters</b></span>”;
}
else
{
// check title name and author length
if (strlen($title)>50||strlen($author)>60)
{
echo “<span style=’color:red’ name=’PHPSpan’><b>Length of Title and Author is too long</b></span>”;
}
else
{
//check condition length
if (strlen($condition)>10||strlen($condition)<4)
{
echo “<span style=’color:red’ name=’PHPSpan’><b>Condition should be between 10 and 4 characters</b></span>”;
}
else
{
// edition length
if (strlen($edition)>6||strlen($edition)<2)
{
echo “<span style=’color:red’ name=’PHPSpan’><b>Edition must be between 6 and 2 characters</b></span>”;
}
else
{
// code to connect to database was here
//$query = (“SELECT camnumber FROM register”);
//$result = mysql_query($query);

//while($row = mysql_fetch_array($result, MYSQL_ASSOC))
//{
//echo “Cam number {$row[‘camnumber’]}”;

//mysql_query(“UPDATE `books` SET `camnumber`='”.(session_id()).”‘ WHERE camnumber=’$camnumber'”);

//mysql_query(“INSERT INTO books SET camnumber='”.$_SESSION[‘camnumber’].”‘, location='”.$_SESSION[‘rgister.php’].”‘”)
//if ($_SESSION[‘camnumber’])
$queryreg = mysql_query(”

INSERT INTO books VALUES(”,’$title’,’$author’,’$edition’,’$publicationdate’,’$isbnnumber’,’$condition’,’$price’,’$category’,’$camnumber’)

“);

die(“You book has been added <a href =’index2.php’> Return to login page</a>”);
//}

}
}
}
}

}

}
else
echo “<span style=’color:red’ name=’PHPSpan’><b>Please fill in all fields</b></span><br />”;
}

?> [/code]

And this is the code which displays the search result

[code=php]<?php session_start (); ?>
<?php
error_reporting (E_ALL ^ E_NOTICE);

$var = $_GET[‘title’];
$var1 = $_GET[‘author’];
$s =$_GET[‘s’];
$camnumber = $_SESSION[‘camnumber’];
$trimmed = trim($var);
$trimmed1 = trim($var1);
//$_SESSION[‘camnumber’] = $dbcamnumber;

// rows to return
$limit = 1;
//$flag=0;
// check for an empty string and display a message.
if ($s == “” ){
$s=0;
}
if ($trimmed == “” && $trimmed1==””){
die(“<p><span style=’color:red’ name=’PHPSpan’>Please enter a search…</span></p>”);
}

// checking for length of characters
if (strlen($var) <= 2 && strlen ($var1) <= 2){
die(“<p><span style=’color:red’ name=’PHPSpan’>Search character is too short please enter full search character</span></p>”);
}

mysql_connect(“”,””,””);
mysql_select_db(“”) or die(mysql_error());

$query = “SELECT * FROM `books` WHERE `title` LIKE ‘%”.$_GET[‘title’].”%’ AND `author` LIKE ‘%”.$_GET[‘author’].”%'”;
//$query = “SELECT * FROM books WHERE author LIKE ‘%”.$_GET[‘author’].”%'”;
$numresults = mysql_query($query) or die(mysql_error());
$numrows = mysql_num_rows($numresults);

if ($numrows == 0){
echo “<h2>Results</h2>”;
echo “<p>Oops sorry, your search: &quot;” . $trimmed, $trimmed1 . “&quot; returned no results</p>”;
echo “Please try a different search”;
}

// next determine if s has been passed to script, if not use 0
if (empty($s)){
$s = 0;

}

// get results
$query .= ” LIMIT $s, $limit”;
$result = mysql_query($query) or die(mysql_query());

// what the person searched for
echo “<p>You searched for: &quot;” . $var, $var1 . “&quot;</p>”;

// show results set
echo “Results<br/>”;
//$count = 1 + $s ;

// display the results returned
while ($row = mysql_fetch_array($result)){
$title = $row[‘title’];
$author = $row[‘author’];
$edition = $row[‘edition’];
$publicationdate = $row [‘publicationdate’];
$isbnnumber = $row [‘isbnnumber’];
$condition = $row [‘condition’];
$price = $row[‘price’];
$category = $row[‘category’];
$camnumber = $row[‘camnumber’];

echo “<td><b>Title</b>, $title<br/><b>Author</b>, $author<br/><b>Edition</b>, $edition<br/><b>Publication Date</b>, $publicationdate
<br/><b>ISBN Number</b>, $isbnnumber<br/><b>Condition</b>, $condition<br/><b>Price</b>, $price<br/><b>Category</b>, $category</td><p>”;

$prev = $s – $limit;
$next = $s + $limit;

if(!($s<=0)){

echo ” <a href =’paging.php?s=”.$prev.”&title=”.$_GET[‘title’].”&author=”.$_GET[‘author’].”&camnumber=”.$row[‘camnumber’].”‘>Prev</a> “;
//echo “<a href=’paging.php?camnumber=$row[‘camnumber’]’>$row[0]</a>”;
}

$no = 1;
$no1=$no-1;

for ($pages = 0; $pages < $numrows; $pages += $limit){
//showing what page is selected or clicked
/*if($s != $pages){
//echo ” <a href =’paging.php?s=$pages’>$no</a> “;
//passing and preserving the variables used at the top within page numbers
echo ” <a href =’paging.php?s=”.$no.”&title=”.$_GET[‘title’].”&author=”.$_GET[‘author’].”‘>$no</a> “;
}else{
//echo ” <a href =’paging.php?s=$pages’><b>$no</b></a> “;
echo” <a href =’paging.php?s=”.$no.”&title=”.$_GET[‘title’].”&author=”.$_GET[‘author’].”‘>$no</a> “;
}*/
echo” <a href =’paging.php?s=”.$no1.”&title=”.$_GET[‘title’].”&author=”.$_GET[‘author’].”&camnumber=”.$row[‘camnumber’].”‘>$no</a> “;
$no++;
$no1=$no-1;
}

if (!($s >= $numrows – $limit)){
echo ” <a href=’paging.php?s=”.$next.=”&title=”.$_GET[‘title’].”&author=”.$_GET[‘author’].”&camnumber=”.$row[‘camnumber’].”‘>Next</a> “;
}
}
$a = $s + ($limit);
if ($a > $numrows){
$a = $numrows;
}

$b = $s + 1 ;
echo “<p>Showing results $b to $a of $numrows</p>”;

?>
<html>
<head>
<title>paging</title>
</head>
<body>
<form method=”LINK” action=”page1.htm”>
<input type=”submit” value=”Contact seller”>
</form>

<html>
<head>

</body>
</html>
[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @boxen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...