Jump to content

[SOLVED] Displaying information in a update form


dark22horse

Recommended Posts

Hi guys

 

I can display the information in a table.  But now I need to display it in a form, so I can edit it and then upload it to the database.  I have the form from my upload page, But I can not seem to get the information to appear back in it.

 

<html>
<head>
    <title>Untitled Page</title>

<link href="images/CliftonMotors.css" rel="stylesheet" type="text/css">
</head>
<body style="margin:0;">
<TABLE WIDTH=775 height="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
	<TD height="89" COLSPAN=2>
		<table width="100%"  border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="374"><img src="images/toplogo2.gif" width=374 height=89 alt=""></td>
                <td><TABLE width="401" BORDER=0 CELLPADDING=0 CELLSPACING=0>
                  <TR>
                    <TD COLSPAN=11> <IMG SRC="images/jd_b038_02.gif" WIDTH=401 HEIGHT=40 ALT=""></TD>
                  </TR>
                    <TR>
                    <TD><a href="index.html"><IMG SRC="images/home.gif" ALT="" WIDTH=56 HEIGHT=49 border="0"></a></TD>
                    <TD><IMG SRC="images/navspacer2.gif" WIDTH=1 HEIGHT=49 ALT=""></TD>
                    <TD><a href="Cars.php"><IMG SRC="images/car.gif" ALT="" WIDTH=53 HEIGHT=49 border="0"></a></TD>
                    <TD><IMG SRC="images/navspacer2.gif" WIDTH=1 HEIGHT=49 ALT=""></TD>
                    <TD><a href="Location.html"><IMG SRC="images/location.gif" ALT="" WIDTH=72 HEIGHT=49 border="0"></a></TD>
                    <TD><IMG SRC="images/navspacer2.gif" WIDTH=1 HEIGHT=49 ALT=""></TD>
                    <TD><a href="Feedback.html"><IMG SRC="images/feedback.gif" ALT="" WIDTH=72 HEIGHT=49 border="0"></a></TD>
                    <TD><IMG SRC="images/navspacer2.gif" WIDTH=1 HEIGHT=49 ALT=""></TD>
                    <TD><a href="Repairs.html"><IMG SRC="images/repair.gif" ALT="" WIDTH=72 HEIGHT=49 border="0"></a></TD>
                    <TD><IMG SRC="images/navspacer2.gif" WIDTH=1 HEIGHT=49 ALT=""></TD>
                    <TD><a href="About us.html"><IMG SRC="images/about us.gif" ALT="" WIDTH=71 HEIGHT=49 border="0"></a></TD>
                  </TR>
                </TABLE></td>
              </tr>
            </table></TD>
</TR>
<TR>
	<TD valign="top" background="images/pixi_1.gif"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><TABLE width="553" BORDER=0 CELLPADDING=0 CELLSPACING=0>
             
            </TABLE></td>
          </tr>
          <tr>
            <td height="18" background="images/pixi_grey.gif" style="padding-left:40;padding-top:5;padding-right:35;"><h1>Welcome to Clifton Motors</h1></td>
          </tr>
          <tr>
            <td style="padding-left:40;padding-top:25; padding-right:35;padding-bottom:25;">

<?

$id=$_GET['id'];
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","");

//select which database you want to edit
mysql_select_db("car"); 

//select the table
$result = mysql_query("select * from car WHERE id = '$id' ");

//WHERE status1 = 'for sale'
//grab all the content
while($r=mysql_fetch_array($result))
{

}

//[id] => 1 
//[price] => £150000 
//[description] => this is a expensive 
//[photo] => 114369546_58f1ef86b6_m.jpg 
//[status1] => Sold )


echo <form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input type="id" name="MAX_FILE_SIZE" value="" />

Price<input type="text" name="price" length="20" value = ""/><br/>
description<textarea name="description" rows="5" cols="35"></textarea><br/>
Choose a file to upload: <input name="photo" type="file" /> <br />
Choose a file to upload: <input name="photo1" type="file" /> <br />
Choose a file to upload: <input name="photo2" type="file" /> <br />
Choose a file to upload: <input name="photo3" type="file" /> 
Car of the week<input type="text" name="car_of_the_week" length="20" value = ""/><br/>
status<input type="text" name="status1" length="20" value = "jjjj"/><br/>
<input type="submit" value="Upload Files" /><br />

</form>

?>                
          </td>
          </tr>
      </table></TD>

</TR>
<TR>
	<TD background="images/pixi_2.gif" height="37" COLSPAN=2 style="padding-left:40;">© Keith Coatsworth. </TD>
  </TR>
<TR>
	<TD height="7" COLSPAN=2 background="images/pixi_grey.gif"><IMG SRC="images/spacer.gif" WIDTH=775 HEIGHT=7 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</html>

 

ive got so far, but I am unsure what to do next really.  Cheers

Link to comment
Share on other sites

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

I can't see where the form is for the update, but what you need to do is take the same variables you used to display the information in the table and, in the <input> tag, put that variable in the value attribute.  If you are using textareas, then you need to put the variable inbetween the <textarea> tags.

Link to comment
Share on other sites

The form from above.

 

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input type="id" name="MAX_FILE_SIZE" value="$id" />

Price<input type="text" name="price" length="20" value = "$price"/><br/>
description<textarea name="description" rows="5" cols="35"></textarea><br/>
Choose a file to upload: <input name="photo" type="file" /> <br />
Choose a file to upload: <input name="photo1" type="file" /> <br />
Choose a file to upload: <input name="photo2" type="file" /> <br />
Choose a file to upload: <input name="photo3" type="file" /> 
Car of the week<input type="text" name="car_of_the_week" length="20" value = ""/><br/>
status<input type="text" name="status1" length="20" value = "jjjj"/><br/>
<input type="submit" value="Upload Files" /><br />

</form>

 

If anyone has a link to an example, also I keep getting an error on the <form> tag with the php, do I need to put echo infront?

Link to comment
Share on other sites

Here is the example, just place your sql returned values.

hope this helps.

regards,

 

<form> 
<table width='100%' border='1'>
  <tr>
    <td>Manufacturer </td>
    <td><input type='text' name='f_manufact' value='<?php print "$row[make]";?>'> </td>
    <td>Model </td>
    <td><input type='text' name='f_model' value='<?php print "$row[model]";?>'> </td>
  </tr></table></form>

Link to comment
Share on other sites

I have tried that, as you can see below!

 

<?

$id=$_GET['id'];
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","");

//select which database you want to edit
mysql_select_db("car"); 

//select the table
$result = mysql_query("select * from car WHERE id = '$id' ");

//grab all the content
while($r=mysql_fetch_array($result))
{

}


   $price=$r["price"];
   $description=$r["description"];
   $photo=$r["photo"];
   $id=$r["id"];
   print_r($id);

?>

<form enctype="multipart/form-data" action="uploader.php" method="POST"> 
<table width='100%' border='1'>
  <tr>
    <td>Price</td>
    <td><input type='text' name='price' value='<?php print "$price";?>'> </td>
    <td>Description</td>
    <td><input type='text' name='description' value='<?php print "$description";?>'> </td>
  </tr>
</table>
</form>

 

It doesnt bring back any information with the form.

Link to comment
Share on other sites

Instead of

while($are=mysql_fetch_array($result))

 

 

Try:

<?php
$query = "select * from car WHERE id = '$id' ";
$result = mysql_query($query);
$num = mysql_num_rows($result);

$i = 0;
while ($i<$num) {
$price = mysql_result($result, $i, 'price'); //do this for each variable
?>

then you should be able to echo the $price and the other variables into the form value.

 

 

Let me know if this solves the issue.

Link to comment
Share on other sites

No didn't work mate.  Cheers, it doesnt actually load the page, comes up with this,

 

Fatal error: Maximum execution time of 60 seconds exceeded in C:\Program Files\xampp\htdocs\site\Update_car.php on line 62

 

That line is the one you said put in.

Link to comment
Share on other sites

Man I am tired... I forgot:

 

<?php
$query = "select * from car WHERE id = '$id' ";
$result = mysql_query($query);
$num = mysql_num_rows($result);

$i = 0;
while ($i<$num) {
$price = mysql_result($result, $i, 'price'); //do this for each variable
?>

HTML FORM STUFF HERE

<?php
++$i;
}

?>

 

Sorry about that. That should work though.

 

Link to comment
Share on other sites

Cheers, as i said i got it working.  I am now trying to update the database.  Im using the following code.

 

<?

$id=$_GET['id'];
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","");

//select which database you want to edit
mysql_select_db("car"); 


$query = "select * from car WHERE id = '$id' ";
$result = mysql_query($query);
$num = mysql_num_rows($result);

$i = 0;
while ($i<$num) {
$price = mysql_result($result, $i, 'price'); //do this for each variable
   	$description= mysql_result($result, $i, 'Description');
   	$photo=$r["photo"];
   	$id=$r["id"];
   	

?>


<html>
<body>

<form enctype="multipart/form-data" action="uploader.php" method="POST"> 
<table width='100%' border='1'>
  <tr>
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    <td>ID</td>
    <td><input type="hidden" name="id" value="print "$id" /></td>
    <td>Price</td>
    <td><input type='text' name='price' value='<?php print "$price";?>'> </td>
    <td>Description</td>
    <td><input type='text' name='description' value='<?php print "$description";?>'> </td>
    <td>Car of the Week</td>
    <td><input type="text" name="car_of_the_week" length="20" value = ""/></td>
    <td>Status</td>
    <td><input type="text" name="status1" length="20" value = "jjjj"/></td>
    <td>Photo</td>
    <td><input name="photo" type="file" /></td>
    <td>Photo1</td>
    <td><input name="photo1" type="file" /></td>
    <td>Photo2</td>
    <td><input name="photo2" type="file" /></td>
    <td><input name="photo3" type="file" /></td>
    <td><input type="submit" value="Upload Files" /></td>

  </tr>
</table>
</form>

<?
++$i;
}
?>
                
</BODY>
</html>

 

Uploader.php

 

<?
require_once("mysql_config.php");

$target_path = $target_path . basename( $_FILES['photo']['name']); 
$_FILES['photo']['tmp_name'];

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['photo']['name']); 

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path)) {

echo "The file ".  basename( $_FILES['photo']['name']). " has been uploaded";

$sql_string = "UPDATE car(price, description, photo, photo1, photo2, photo3, car_of_the_week, status1) VALUES ('".$_POST['price']."', '".$_POST['description']."', '".$_FILES['photo']['name']."','".$_FILES['photo1']['name']."', '".$_FILES['photo2']['name']."', '".$_FILES['photo3']['name']."', '".$_POST['car_of_the_week']."', '".$_POST['status1']."')";

echo "<br/>SQL STRING WE WANT TO RUN: ".$sql_string;

echo "db connection: ".$dbconn;
echo "table connection: ".$table;

$ok = mysql_query($sql_string);

echo "OK: ".$ok;

if($ok){
	echo "<h2>all is good, upload another</h2>";
} else {
	echo "<h2>check the string".$sql_string."</h2>";
}

} else{

echo "There was an error uploading the file, please try again!";

}

?>

 

I think my problem is this string

 

$sql_string = "UPDATE car(price, description, photo, photo1, photo2, photo3, car_of_the_week, status1) VALUES ('".$_POST['price']."', '".$_POST['description']."', '".$_FILES['photo']['name']."','".$_FILES['photo1']['name']."', '".$_FILES['photo2']['name']."', '".$_FILES['photo3']['name']."', '".$_POST['car_of_the_week']."', '".$_POST['status1']."')";

 

anyhelp:)

Link to comment
Share on other sites

What error are you getting? MySQL Error or the once you customized "There was an error uploading the file, please try again!"?

 

Also, I highly recomend against directly entering $_POST['variable_name'] directly into your MySQL. Poses a huge security risk.

Link to comment
Share on other sites

Ive got a new string,

 

$sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3\', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `car`.`id` = '$id'LIMIT 1;;

 

But that doesnt work either.

Link to comment
Share on other sites

Hi darkhorse, I only had a minute to check out the code but I noticed a few errors in your new string:

 

$sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3\', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `car`.`id` = '$id'LIMIT 1;;

 

You have a slash after $photo3 and two semi-colons at the end. You also need a smace between $id and LIMIT 1.

 

Try that.

Link to comment
Share on other sites

Hi changed the errors

 

But im till getting this error

 

Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\xampp\htdocs\site\uploader2.php on line 34

 

$sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `car`.`id` = '$id' LIMIT 1;

Link to comment
Share on other sites

 

 

 


<?
require_once("mysql_config.php");

$target_path = $target_path . basename( $_FILES['photo']['name']); 
$_FILES['photo']['tmp_name'];

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['photo']['name']); 

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path)) {

    echo "The file ".  basename( $_FILES['photo']['name']). " has been uploaded";

        $sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `car`.`id` = '$id' LIMIT 1;

echo "<br/>SQL STRING WE WANT TO RUN: ".$sql_string;

echo "db connection: ".$dbconn;
echo "table connection: ".$table;

$ok = mysql_query($sql_string);

echo "OK: ".$ok;

        if($ok){
	echo "<h2>all is good, upload another</h2>";
} else {
	echo "<h2>check the string".$sql_string."</h2>";
}
} else{

echo "There was an error uploading the file, please try again!";
}
?>

 

That is it. 

Link to comment
Share on other sites

Also, this code concerns me:

WHERE `car`.`id` = '$id' LIMIT 1;

 

You know that it is looking in your database bas for carid right? Like let's say you have a volvo in your car column and a number of 6000 in your id. It is actually looking for volvo6000 where $id is. I am guessing $id is numeric only since you received it from your database to begin with back on the previous page.

 

So because it is looking for volvo6000 and that doesn't exist, you won't have success in update.

Link to comment
Share on other sites

You were missing a ' :

$sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `id` = '$id' LIMIT 1';

 

 

Link to comment
Share on other sites

Done all the mate.  Didnt work

 

$sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1'';

 

What does the unexpected T_variable mean?

Link to comment
Share on other sites

You said that you are using this as your uploader.php file right?

<?
require_once("mysql_config.php");

$target_path = $target_path . basename( $_FILES['photo']['name']); 
$_FILES['photo']['tmp_name'];

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['photo']['name']); 

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path)) {

    echo "The file ".  basename( $_FILES['photo']['name']). " has been uploaded";

        $sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `car`.`id` = '$id' LIMIT 1;

echo "<br/>SQL STRING WE WANT TO RUN: ".$sql_string;

echo "db connection: ".$dbconn;
echo "table connection: ".$table;

$ok = mysql_query($sql_string);

echo "OK: ".$ok;

        if($ok){
	echo "<h2>all is good, upload another</h2>";
} else {
	echo "<h2>check the string".$sql_string."</h2>";
}
} else{

echo "There was an error uploading the file, please try again!";
}
?>

 

 

Where are you getting the $id variable from in you MySQL query UPDATE statment, not to mention all the other variables?

 

Did you set anything from your post?

 

EXP:

$description = $_POST['description'];

Link to comment
Share on other sites

yeah sorry, totally forgot bout that.

 

 

<?
require_once("mysql_config.php");

$target_path = $target_path . basename( $_FILES['photo']['name']); 
$_FILES['photo']['tmp_name'];

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['photo']['name']); 

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path)) {

echo "The file ".  basename( $_FILES['photo']['name']). " has been uploaded";

$sql_string = "UPDATE car SET price = '".$_POST['price']."', description ='".$_POST['description']."', photo = '".$_FILES['photo']['name']."', photo1 = '".$_FILES['photo1']['name']."', photo2 = '".$_FILES['photo2']['name']."', photo3 = '".$_FILES['photo3']['name']."', car_of_the_week = '".$_POST['car_of_the_week']."', status1 = '".$_POST['status1']."'"; 

echo "<br/>SQL STRING WE WANT TO RUN: ".$sql_string;

echo "db connection: ".$dbconn;
echo "table connection: ".$table;

$ok = mysql_query($sql_string);

echo "OK: ".$ok;


if($ok){
	echo "<h2>all is good, upload another</h2>";
} else {
	echo "<h2>check the string".$sql_string."</h2>";
}

} else{

echo "There was an error uploading the file, please try again!";

}

?>

 

I dont get the T variable error any more, but the last error is coming

 

echo "There was an error uploading the file, please try again!";

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.