Jump to content

[SOLVED] real noob trying to make button to submit result


didgydont

Recommended Posts

hi all

im trying to learn php ive been using www.w3schools.com to make my self a client data base but now im trying to make a button to submit a $result the code i tried is this

 

echo "<table border='2'>

<tr>

<th>id #</th>

<th>Client Name</th>

</tr>";while($row = mysql_fetch_array($result))

  {

  echo "<tr>";

  echo "<td>" . $row['Uid'] . "</td>";

  echo "<td>" . $row['FirstName'] ." ". $row['LastName'] . "</td>";

    echo "<td>" <form action="idsearch.php" method="post">

<input type=". $row['Uid'] ." name="Uid" /> <br />

<input type="submit" VALUE="Show Details" />

</form>

"</tr>";

  }

echo "</table>";mysql_close($con);

?>

 

thank you for your time also does anyone know of any other good sites for learning php

Link to comment
Share on other sites

thank you for your reply it must have been realy bad if you couldnt understand i started trying to learn about 4 days ago. the code bellow is what ive done so fare and it works great but rather than have to enter the Uid in a form at the bottom of the page i was trying to make a button beside the user that automaticly grabbed the Uid and when pressed would send it to idsearch.php i love php so far just some things have banging my head against the wall  ;) i will have a look at those links in the mean time thank you again ..

 

<html>

                <?php

$con = mysql_connect("localhost","database_name","mypassword");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }mysql_select_db("database_name", $con);

$result = mysql_query("SELECT * FROM clients

ORDER BY FirstName");

 

echo "<table border='2'>

<tr>

<th>id #</th>

<th>Client Name</th>

</tr>";while($row = mysql_fetch_array($result))

  {

  echo "<tr>";

  echo "<td>" . $row['Uid'] . "</td>";

  echo "<td>" . $row['FirstName'] ." ". $row['LastName'] . "</td>";

"</tr>";

  }

echo "</table>";mysql_close($con);

?>

<form action="idsearch.php" method="post">

ID#: <input type="text" name="Uid" /> <br />

<input type="submit" VALUE="Show Details" />

</form>

 

<br /><br />

 

 

</html>

 

 

Link to comment
Share on other sites

In your idsearch.php page, get the number from the input box for your id and do the query e.g.

<?php
// this value will come from text box named Uid
$id = $_POST['Uid'];
echo $id;
// you can query the table and search from the id 
$query = mysql_query("SELECT * FROM table WHERE id=$id");
// and display just like you did above... 
?>

Link to comment
Share on other sites

i already have that in idsearch.php what i was trying to do was remove the form from the bottom of the page and replace it with a show details button that would send the uid to my idsearch.php thank you for your imput i think im gonna go crazy  ;D still fun though

 

<html>

<?php

$con = mysql_connect("localhost","database_name","mypassword");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }mysql_select_db("database_name", $con);

 

$result = mysql_query("SELECT * FROM clients WHERE Uid='$_POST[uid]'");

 

while($row = mysql_fetch_array($result))

  {

  echo "<b>Name:</b>" . " " . $row['FirstName'] ." ". $row['LastName'];

    echo "<br />";

 

      if (empty ($row['Address']))

    {echo "<b>Address:</b> None.";}

else

    {echo "<b>Address:</b>" . " " . $row['Address'];}

    echo "<br />";

 

    if (empty ($row['Mobile']))

    {echo "<b>Mobile Number:</b> None.";}

else

    {echo "<b>Mobile Number:</b>" . " " . $row['Mobile'];}

    echo "<br />";

 

  if (empty ($row['Land']))

    {echo "<b>Land Line:</b> None.";}

else

    {echo "<b>Land Line:</b>" . " " . $row['Land'];}

    echo "<br />";

 

if (empty ($row['Email']))

    {echo "<b>Email:</b> None.";}

else

    {echo "<b>Email:</b>" . " " . $row['Email'];}

 

    echo "<br />";

  echo "<br />";

  echo "<br />";

  echo "<br />";

  }mysql_close($con);

?>

 

<br /><br />

 

 

</html>

Link to comment
Share on other sites

just an update this solved my problem the show details button made my table look funny but it works

 

echo "<table border='2'>

<tr>

<th>id #</th>

<th>Client Name</th>

<th>Client details</th>

</tr>";while($row = mysql_fetch_array($result))

  {

  $uid = $row['Uid'];

  echo "<tr>";

  echo "<td>" . $row['Uid'] . "</td>";

  echo "<td>" . $row['FirstName'] ." ". $row['LastName'] . "</td>";

  echo "<td>";

  echo "<form action=\"idsearch.php\" method=\"post\">";

  echo "<input type=\"hidden\" name=\"Uid\" value=\"$uid\"  /> <br />";

  echo "<input type=\"submit\" VALUE=\"Show Details\" />" ;

  echo "</form>";

  echo "</td>";

"</tr>";

  }

echo "</table>";mysql_close($con);

Link to comment
Share on other sites

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.