0

I input the previous inputted values via php variables into the value section of the input tag, but when I go to modify it and update it to the database, the value still stays the same. Is there anyways to combine the two , so that for instance when a user wants to update their listing they could? Thanks.

3
Contributors
5
Replies
23
Views
1 Year
Discussion Span
Last Post by vivosmith
0

post some code

the value in the db stays the same?
the value on the form doesn't get updated?

need a little more info

0
<?php
include('mysqli_connect.php');
echo"Success";
echo '<a href="?logout"> Logout? </a>';
if(isset($_GET['logout']))
{
header ("Location: enter_passcode.html");
}
if(isset($_GET['pass']))
{
$pass=$_GET['pass'];
echo 'pass is set';
$set="SELECT title, ad_body, contact, zip_code, price, email FROM ads WHERE password=SHA1('$pass')"; 
$gets=mysqli_query($dbc,$set);
$results=mysqli_fetch_array($gets,MYSQLI_BOTH);
$contact=$results[2];
$ad_body=$results[1];
$zip_code=$results[3];
$price=$results[4];
$email=$results[5];
$title=$results[0];
echo "GET is set".$pass;

}else{ echo 'Get is not set';}
?>
<html>
<form method="post" action="post.php">
Title:
<input type="text"  name="title" value="<?php echo $title; ?>" size="30" /><p>

<textarea name="ad" rows="10" cols="40" size="150" >
<?php echo htmlspecialchars($ad_body); ?>
</textarea><p>

<input type="hidden" name="passcode" value="<?php echo $pass ?>" size=12 />

Zip Code :<input type="password" name="passcode" value="<?php echo $zip_code; ?>" size=12 />
Contact:<input type="text" name="contact" value="Enter a website,email, phone number, or other contact detail customers can use to contact you. " size=120/>
<p>Price:<input type="text" name="price" value="$<?php echo $price; ?> " size=50/>
Email:<input type="text" name="email" value="<?php echo $email; ?>"size=50/>
<input type="submit" name="Submit" />
<input type="hidden" name="submitted"/>

</form>

</html> 

Which is then posted to here:

<?php 
include('mysqli_connect.php');
if(isset($_POST['contact']) && isset($_POST['passcode']) && isset($_POST['email']) && isset($_POST['price']) && isset($_POST['title']) && isset($_POST['ad']))
{
$pass=$_POST['passcode'];
$email=$_POST['email'];
$price=$_POST['price'];
$title=$_POST['title'];
$contact=$_POST['contact'];
$ad=$_POST['ad'];
$w="UPDATE ads SET email='$email', price='$price', title='$title', contact='$contact', ad_body='$ad' WHERE password=SHA1('$pass');";
$select=mysqli_query($dbc,$w);
if(!empty($select))
{

echo "Success";
}else{echo "Fail";}
}

?>
0

Thanks. This is just a prototype in my XAMPP environment, and I did add mysqli_real_escape_string to the first page, but I will need to add it to the second. The passcode is a unique ID akin to save passwords for games. I plan on cross refferencing the email sent with the passcode to make sure it matches with the email, otherwise you are screwed. Or I could make a seperate password and rename the current password ID. I am still working on it yet.

As for output, when I check, it does change to whatever I edit it as, but it does not get uploaded to the databse. Weird. I will check the DB connection.

0

Figured it out. I had copied passcode to use as a template for other inputs, but forgot to rename it, and used the zipcode instead. Then in a panic I took out the ' ' from the variables in the SQL query, which resulted in NULL. I was able to get it to finally show on the databse so I am set to go. Might need to change a few things, but at least I have an almost working prototype. :) After I get everything set up I will work on getting security to be a bit tighter :) .

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.