Jump to content

displaying data in textbox from mysql db (PHP)


synchro_irl

Recommended Posts

hey

 

im trying to pull data from a mysql database and display it in texboxes,

 

 

 

here is the code sample:

 

 

 

<?php
$con = mysql_connect()
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("mydatabase", $con);

mysql_query("UPDATE mytable SET availability  = '23 weeks'
WHERE userid = '2'");

$result = mysql_query("SELECT * FROM mytable");
echo "<table border='1'>
<tr>
<th>Type</th>
<th>Location</th>
<th>Availability</th>
<th>StarRating</th>
<th>name</th>
<th>email</th>
<th>username</th>

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


  
echo "<tr>";
  echo "<td>" . $row['type'] . "</td>";
  echo "<td>" . $row['location'] . "</td>";
  echo "<td>" . $row['availability'] . "</td>";
  echo "<td>" . $row['StarRating'] . "</td>";

echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
  echo "</tr>";
  }


mysql_close($con);
?>

 

 

 

 

 

the above code works, but it displays teh data in a table, that is uneditable, i need to display the data in textboxes, or somethying that will allow edit them, and then save changes, i.e. updating the table.

 

 

 

can someone PLEASE help me on this one, its killing me

 

 

 

thanks :)

 

 

sorry if i already posted a thread like this one, but i felt i didnt get the point across, thanks!

 

Link to comment
Share on other sites

You need to put your content in textboxes and surround it with a form - set the form action to run the update

 

<form action="formaction.php">

while($row = mysql_fetch_array($result))  {

  echo '<td><input type="text" value="' . $row['location'] . '></td>';

}

echo '<input type="submit">';

</form>

 

Try googling for forms to find a tutorial!  HTH  :)

Link to comment
Share on other sites

 

tanks for replying to my thread, i tried the code sample u posted, but its printing ot nothig, can u please help me find a good tutoprial online, im useless at googling!

please

 

 

 

You need to put your content in textboxes and surround it with a form - set the form action to run the update

 

<form action="formaction.php">

while($row = mysql_fetch_array($result))  {

  echo '<td><input type="text" value="' . $row['location'] . '></td>';

}

echo '<input type="submit">';

</form>

 

Try googling for forms to find a tutorial!  HTH   :)

Link to comment
Share on other sites

Try http://www.tizag.com/phpT/forms.php - this site has been really helpful to me to get the basics of a lot of stuff.

 

The code I posted was obviously cut down. In full then

 

 

<?php
$con = mysql_connect()
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("mydatabase", $con);

mysql_query("UPDATE mytable SET availability  = '23 weeks'
WHERE userid = '2'");

$result = mysql_query("SELECT * FROM mytable");
echo "<table border='1'>
<tr>
<th>Type</th>
<th>Location</th>
<th>Availability</th>
<th>StarRating</th>
<th>name</th>
<th>email</th>
<th>username</th>

</tr>";
<form action="formaction.php">
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo '<td><input type="text" value="' . $row['type'] . '"></td>';
  ...rest of information here
  echo "</tr>";
  }
</form>

mysql_close($con);
?>

Link to comment
Share on other sites

thank u so much for that, but its showing up with error for line:

 

<form action="formaction.php">

 

am i suppose to create 'foraction.php, what shoudl it do?

 

thanks again

 

 

Try http://www.tizag.com/phpT/forms.php - this site has been really helpful to me to get the basics of a lot of stuff.

 

The code I posted was obviously cut down. In full then

 

 

<?php
$con = mysql_connect()
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("mydatabase", $con);

mysql_query("UPDATE mytable SET availability  = '23 weeks'
WHERE userid = '2'");

$result = mysql_query("SELECT * FROM mytable");
echo "<table border='1'>
<tr>
<th>Type</th>
<th>Location</th>
<th>Availability</th>
<th>StarRating</th>
<th>name</th>
<th>email</th>
<th>username</th>

</tr>";
<form action="formaction.php">
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo '<td><input type="text" value="' . $row['type'] . '"></td>';
  ...rest of information here
  echo "</tr>";
  }
</form>

mysql_close($con);
?>

Link to comment
Share on other sites

Again, you need to understand the basis of forms and how they work.

 

There will be more code that you need to add, without doubt - whether the form is submitted using post or get, setting the action that is required when the form is submitted etc.

 

If you don't know how a form works, then you need to find out. Google "php forms" and you will find loads of help.

 

But basically, the form action, formaction.php, should contain the code to process the form - in this case, update the database. So yes, you do need to create this file.

 

In order to get the help you require, you need to understand forms.

Like I said, google "php forms" and have a go yourself, then come back to us if you still need help!  :)

Link to comment
Share on other sites

thanks so so much!

I GOT IT TO WORK WOHOO

THANKS FOR UR HELP!

 

but now i need to update the table, and i have done everything neccesary for this to work, but im getting a: Not Found

 

The requested URL /pluralism/--WEBBOT-SELF-- was not found on this server.

 

 

error.

 

wat s this?

Link to comment
Share on other sites

Well done!  ;D

 

What is  /pluralism/--WEBBOT-SELF--  referring to?

Is this the form action?

If you can give a little bit more info that would great!

 

 

pluralism s just the folder all my files are in,  webbot -self is referring to the button 'Update' being clicked.

 

here is the code, here is a sample of just what i think is relevant to the error:

 

<h2 class="title"><a href="#">Welcome to Search4Trade</a></h2>
							<blockquote>
								<div class="entry">
									<form action="--WEBBOT-SELF--" method="POST">
										<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
										<p>
<input type="submit" name="submit" value="Update"></p>
									</form>
									<?php
$con = mysql_connect("localhost","root","clio172");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


mysql_select_db("mydatabase", $con);
if (isset($_POST['submit'])) { 

    
$name = $_POST['name'];
$email = $_POST['email'];
$type = $_POST['type'];
$location = $_POST['location'];
$availability = $_POST['availability'];
$username = $_POST['username'];
$password = md5($_POST['password']);



$query = "INSERT INTO mytable (name, email,Type, location, availability, username)
VALUES('$name', '$email','$type','$location','$availability','$username')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "Successfully Updated";
   
    




}




$result = mysql_query("SELECT * FROM mytable");
echo "<table border='1'>
<tr>
<th>Type</th>
<th>Location</th>
<th>Availability</th>
<th>StarRating</th>
<th>name</th>
<th>email</th>
<th>username</th>

</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo '<td><input type="text" value="' . $row['type'] . '"></td>';
echo '<td><input type="text" value="' . $row['location'] . '"></td>';
echo '<td><input type="text" value="' . $row['availability'] . '"></td>';
echo '<td><input type="text" value="' . $row['StarRating'] . '"></td>';
echo '<td><input type="text" value="' . $row['name'] . '"></td>';
echo '<td><input type="text" value="' . $row['email'] . '"></td>';
echo '<td><input type="text" value="' . $row['username'] . '"></td>';
  
  echo "</tr>";
  }



mysql_close($con);
?>

 

 

 

and here s the entire file, just incase the sample isnt enough!

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Name       : Pluralism
Description: A two-column, fixed-width template fit for 1024x768 screen resolutions.
Version    : 1.0
Released   : 20071218

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Search4Trade</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper" style="width: 961px; height: 564px">
<div id="wrapper2">
	<div id="header">
		<div id="logo">
			<h1><font size="6">
			<a href="edit/search4trade.net/index.html">search4trade.net</a></font></h1>
		</div>
		<div id="menu">
			<ul>
				<li></li>
				<li>
				<a href="Search1.html">Search </a></li>
				<li>
				<a href="Login1.php">Login</a></li>
				<li>
				<a href="phpBB2/index.php">Forum</a></li>
				<li>
				<a href="registration.html">Register</a></li>
				<li>
				<a href="adreviews111.html">Star Rating</a></li>
				<li>
				<a href="contact.php">Contact</a></li>
			</ul>
		</div>
	</div>
	<div id="page">
		<div id="content" style="width: 861px; height: 227px">
			<div class="post">
				<blockquote>
					<blockquote>
						<blockquote>
							<h2 class="title"><a href="#">Welcome to Search4Trade</a></h2>
							<blockquote>
								<div class="entry">
									<form action="--WEBBOT-SELF--" method="POST">
										<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
										<p>
<input type="submit" name="submit" value="Update"></p>
									</form>
									<?php
$con = mysql_connect("localhost","root","clio172");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


mysql_select_db("mydatabase", $con);
if (isset($_POST['submit'])) { 

    
$name = $_POST['name'];
$email = $_POST['email'];
$type = $_POST['type'];
$location = $_POST['location'];
$availability = $_POST['availability'];
$username = $_POST['username'];
$password = md5($_POST['password']);



$query = "INSERT INTO mytable (name, email,Type, location, availability, username)
VALUES('$name', '$email','$type','$location','$availability','$username')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "Successfully Updated";
   
    




}




$result = mysql_query("SELECT * FROM mytable");
echo "<table border='1'>
<tr>
<th>Type</th>
<th>Location</th>
<th>Availability</th>
<th>StarRating</th>
<th>name</th>
<th>email</th>
<th>username</th>

</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo '<td><input type="text" value="' . $row['type'] . '"></td>';
echo '<td><input type="text" value="' . $row['location'] . '"></td>';
echo '<td><input type="text" value="' . $row['availability'] . '"></td>';
echo '<td><input type="text" value="' . $row['StarRating'] . '"></td>';
echo '<td><input type="text" value="' . $row['name'] . '"></td>';
echo '<td><input type="text" value="' . $row['email'] . '"></td>';
echo '<td><input type="text" value="' . $row['username'] . '"></td>';
  
  echo "</tr>";
  }



mysql_close($con);
?>


</div>
							</blockquote>
						</blockquote>
					</blockquote>
				</blockquote>
			</div>
		</div>
	</div>
</div>
</div>
<blockquote>
<p align="center"> <span style="font-family: Angsana New;">                                                                                    Copyright © 
Search4Trade.net 2008</span>                                                                                               
</p>
</blockquote>
</body>


</html>

Link to comment
Share on other sites

OK, I would say your problem is

 

<form action="--WEBBOT-SELF--" method="POST">

 

This needs to be something readable.

 

What are you trying to do with the form action - reload the same page?

 

<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">

 

The server is trying to find a file named --WEBBOT-SELF-- so you need to enter something here that the server can read. HTH!

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.