Jump to content

Recommended Posts

Hey I finally got this code working yesterday, when the user enters a name into the form and submits it the specific users details should be shown on the next page, this was working fine yesterday and when i turned my laptop on today it is not working, I am not getting any errors just not displaying the user details?? Any ideas? Heres the code

 

Form:

 

<table width="300" border="1" align="center" cellpadding="2" cellspacing="1" bgcolor="#9999cc">

<tr>

<form name="form1" method="post" action="getdetails.php">

<td>

<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">

<tr>

<td colspan="3"><strong><center>Personal Details</center> </strong></td>

</tr>

<tr>

<td width="78">Username</td>

<td width="6">:</td>

<td width="294"><input name="submit" type="text" id="username"></td>

</tr>

<tr>

 

<td> </td>

<td> </td>

<td><input type="submit" name="Submit" value="Get Details"></td>

</tr>

</table>

</td>

</form>

</tr>

</table>

 

 

getdetails.php

 

<html>

<head>

<link rel="stylesheet" type ="text/css" href="anything2.css"

</head>

 

<body>

 

 

<div id="container">

 

<div id="header"><img src="imagesb.jpg" alt="Cool Image" align="left">

<img src="images.jpg" alt="Cool Image" align="right"><center><b><font size="6.5"><br><br>User Details</b></center></font>

 

</div>

 

 

<div id="leftnav"><center>

<br><br>

<input type= "button" style="width:120px;" value="Home" onClick="window.location= 'home.php' ">

<br><br>

<input type= "button" style="width:120px;" value="Club Details" onClick="window.location= 'clubdetails.php' ">

<br><br>

<input type= "button" style="width:120px;" value="Future Events" onClick="window.location= 'futureevents.php' ">

<br><br>

<input type= "button" style="width:120px;" value="News" onClick="window.location= 'news.php' ">

<br><br>

<input type= "button" style="width:120px;" value="FAQ" onClick="window.location= 'faq.php' ">

<br><br>

<input type= "button" style="width:120px;" value="Wall" onClick="window.location= 'wall.php' ">

<br><br>

<input type= "button" style="width:120px;" value="About Us" onClick="window.location= 'about.php' ">

</div>

 

<div id="body">

<br><br>

<?php

mysql_connect ("localhost","root","")

or die("Cannot connect to Database");

mysql_select_db ("test");

 

 

 

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

$username=mysql_real_escape_string(trim($_POST['Submit'])); 

$sql = "select * from memberdetails WHERE username='$username'";

      $result = mysql_query ($sql);

 

      while ($row = mysql_fetch_array($result))

                        {

              $username= $row["username"];

              $firstname= $row["firstname"];

              $surname= $row["surname"];

              $dob= $row["dob"];

              $totalwins= $row["totalwins"]; 

              $totalloses= $row["totalloses"];

              $email= $row["email"];

              $country= $row["country"];

  $info= $row["info"];

 

echo "<b><u>Username:</b></u>  $username<br>";

echo "<b><u>Firstname:</b></u> $firstname<br>";

echo "<b><u>Surname: </b> </u> $surname<br>";

echo "<b><u>Date of Birth:</b></u> $dob<br>";

echo "<b><u>Total Chess Wins:</b></u>  $totalwins<br>";

echo "<b><u>Total Chess loses:</b></u> $totalloses<br>";

echo "<b><u>Email Address: </b></u> $email<br>";

echo "<b><u>Born in: </b></u> $country<br>";

echo "<b><u>Other Details:</b></u>  $info<br><br><br>";

          }}

?>

<a href="delete.php">Delete User</a>

<div id="footer">This is the footer</div>

 

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/260394-code-not-working-anymore/
Share on other sites

getdetails.php

 

<html>

<head>

<link rel="stylesheet" type ="text/css" href="anything2.css"

</head>

 

<body>

 

 

<div id="container">

 

<div id="header"><img src="imagesb.jpg" alt="Cool Image" align="left">

<img src="images.jpg" alt="Cool Image" align="right"><center><b><font size="6.5"><br><br>User Details</b></center></font>

 

</div>

 

 

<div id="leftnav"><center>

<br><br>

<input type= "button" style="width:120px;" value="Home" onClick="window.location= 'home.php' ">

<br><br>

<input type= "button" style="width:120px;" value="Club Details" onClick="window.location= 'clubdetails.php' ">

<br><br>

<input type= "button" style="width:120px;" value="Future Events" onClick="window.location= 'futureevents.php' ">

<br><br>

<input type= "button" style="width:120px;" value="News" onClick="window.location= 'news.php' ">

<br><br>

<input type= "button" style="width:120px;" value="FAQ" onClick="window.location= 'faq.php' ">

<br><br>

<input type= "button" style="width:120px;" value="Wall" onClick="window.location= 'wall.php' ">

<br><br>

<input type= "button" style="width:120px;" value="About Us" onClick="window.location= 'about.php' ">

</div>

 

<div id="body">

<br><br>

<?php

mysql_connect ("localhost","root","")

or die("Cannot connect to Database");

mysql_select_db ("test");

 

 

 

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

$username=mysql_real_escape_string(trim($_POST['Submit'])); 

$sql = "select * from memberdetails WHERE username='$username'";

      $result = mysql_query ($sql);

 

      while ($row = mysql_fetch_array($result))

                        {

              $username= $row["username"];

              $firstname= $row["firstname"];

              $surname= $row["surname"];

              $dob= $row["dob"];

              $totalwins= $row["totalwins"]; 

              $totalloses= $row["totalloses"];

              $email= $row["email"];

              $country= $row["country"];

  $info= $row["info"];

 

echo "<b><u>Username:</b></u>  $username<br>";

echo "<b><u>Firstname:</b></u> $firstname<br>";

echo "<b><u>Surname: </b> </u> $surname<br>";

echo "<b><u>Date of Birth:</b></u> $dob<br>";

echo "<b><u>Total Chess Wins:</b></u>  $totalwins<br>";

echo "<b><u>Total Chess loses:</b></u> $totalloses<br>";

echo "<b><u>Email Address: </b></u> $email<br>";

echo "<b><u>Born in: </b></u> $country<br>";

echo "<b><u>Other Details:</b></u>  $info<br><br><br>";

          }}

?>

<a href="delete.php">Delete User</a>

<div id="footer">This is the footer</div>

 

</body>

</html>

form

 

<table width="300" border="1" align="center" cellpadding="2" cellspacing="1" bgcolor="#9999cc">

<tr>

<form name="form1" method="post" action="getdetails.php">

<td>

<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">

<tr>

<td colspan="3"><strong><center>Personal Details</center> </strong></td>

</tr>

<tr>

<td width="78">Username</td>

<td width="6">:</td>

<td width="294"><input name="username" type="text" id="username"></td>

</tr>

<tr>

 

<td> </td>

<td> </td>

<td><input type="submit" name="Submit" value="Get Details"></td>

</tr>

</table>

</td>

</form>

</tr>

</table>

if (isset($_POST['Submit']))
{
    $username=mysql_real_escape_string(trim($_POST['username'])); //this needs to match the nameattr of the input field   
    $sql = "select * from memberdetails WHERE username='$username'";
    $result = mysql_query ($sql);

 

*snippet*

AyKay47 just one more question....

 

I have tried to add a function to allow the user to delete the user form the database if required. The code I have used is:

 

<?php

mysql_connect ("localhost","root","")

or die("Cannot connect to Database");

mysql_select_db ("test");

 

mysql_query ("DELETE FROM members WHERE username='$username'") or die (mysql_error));

    echo "User has been deleted";

header("Location: personaldetails.php");

 

 

?>

 

This is giving me an error on the mysql_query line.

 

I am not sure if i am using the correct format?

When the user enters the username into the form and is redirected to getdetail.php there is a link at the bottom of the page to "delete user":

 

<a href="delete.php">Delete User</a>

 

Is $username declared on my getdetails.php? or do i have to declare it on my delete.php?

 

Delete.php:

 

<?php

mysql_connect ("localhost","root","")

or die("Cannot connect to Database");

mysql_select_db ("test");

 

mysql_query ("DELETE FROM members WHERE username='$username'") or die ("Error- user has not been deleted");

    echo "User has been deleted";

//header("Location: personaldetails.php");

 

 

?>

 

When this function is working correctly should it delete the row completely from my database?

<a href="delete.php?username=<?php echo $username; ?>">Delete User</a>

Delete.php:

<?php
mysql_connect ("localhost","root","")
or die("Cannot connect to Database");
mysql_select_db ("test");
$username = $_GET['username'];
$username = mysql_real_escape_string($username);

mysql_query ("DELETE FROM members WHERE username='$username'") or die ("Error- user has not been deleted");
    echo "User has been deleted";
   //header("Location: personaldetails.php");


?>

When the user enters the username into the form and is redirected to getdetail.php there is a link at the bottom of the page to "delete user":

 

<a href="delete.php">Delete User</a>

 

Is $username declared on my getdetails.php? or do i have to declare it on my delete.php?

 

Delete.php:

 

<?php

mysql_connect ("localhost","root","")

or die("Cannot connect to Database");

mysql_select_db ("test");

 

mysql_query ("DELETE FROM members WHERE username='$username'") or die ("Error- user has not been deleted");

    echo "User has been deleted";

//header("Location: personaldetails.php");

 

 

?>

 

When this function is working correctly should it delete the row completely from my database?

 

Yup the reason it doesn't work is because you don't declare $username in delete, make sure like aykay's script that you use $_GET['username'] and when linking to the delete add ?username=$username otherwise the GET can't get it :)

 

 

Thanks everyone!!

working great.

 

Smerny thats what I plan to do next, the user "admin" is the administrator of the site and will be the only one ablt to delete users.

Any tips on this would be much appreciated. Should I have a page e.g. admindetails.php which the admin is directed to when he/she logs in, which has the delete function on this page and direct all other users to a getdetails.php where they can only view the details.

Or is there a more simple way of doing this?

 

 

depends on what you want to do... if there is a lot of stuff the admin needs to do, contain those things a separate section that can only be accessed when logged in as an admin..

 

if it's just small things.. you could put it on the same page. so the delete button would only show up if you are logged in as an admin...and of course protect the function after the button is clicked as well.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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