Jump to content

kunyomi

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kunyomi's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi guys, I'm trying to UPDATE the image that has been already in the database with another image using a form in PHP. I got the uploading working all fine already. Just the edit part. With this code, I get no error, but the MySQL table is not written with the new image name and the image does not get uploaded into the 'uploads' folder. <?php include ("dbConfig.php"); require ("check.php"); if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") { if (!isset($_POST["submit"])) { $id2 = $_GET["id2"]; $sql = "SELECT * FROM contacts WHERE id2=$id2"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form action="<?php $v=explode('?',$_SERVER['PHP_SELF']); echo $v[0]; ?>" method="post"> <input type=hidden name="id2" value="<?php echo $myrow["id2"]; ?>"> Name: <INPUT TYPE="text" NAME="name" VALUE="<?php echo $myrow["name"]; ?>" SIZE=30><br> Email: <INPUT TYPE="text" NAME="email" VALUE="<?php echo $myrow["email"]; ?>" SIZE=30><br> Who: <INPUT TYPE="text" NAME="age" VALUE="<?php echo $myrow["age"]; ?>" SIZE=30><br> Birthday: <INPUT TYPE="text" NAME="birthday" VALUE="<?php echo $myrow["birthday"]; ?>" SIZE=30><br> Address: <TEXTAREA NAME="address" ROWS=10 COLS=30><?php echo $myrow["address"]; ?></TEXTAREA><br> Number: <INPUT TYPE="text" NAME="number" VALUE="<?php echo $myrow["number"]; ?>" SIZE=30><br> Contact Image: <INPUT NAME="uploadedfile" VALUE="<?php echo $myrow["uploadedfile"]; ?>" TYPE="file" /><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <?php } } $target = "C:/Program Files/xampp/htdocs/cas/uploads/"; $target = $target . basename( $_FILES['uploadedfile']['name']); if (isset($_POST['submit'])) { $id2 = mysql_real_escape_string(stripslashes($_POST["id2"])); $name = mysql_real_escape_string(stripslashes($_POST["name"])); $email = mysql_real_escape_string(stripslashes($_POST["email"])); $age = mysql_real_escape_string(stripslashes($_POST["age"])); $birthday = mysql_real_escape_string(stripslashes($_POST["birthday"])); $address = mysql_real_escape_string(stripslashes($_POST["address"])); $number = mysql_real_escape_string(stripslashes($_POST["number"])); $uploadedfile=($_FILES['uploadedfile']['name']); $sql = "UPDATE contacts SET name='$name', email='$email', age='$age', birthday='$birthday', address='$address', number='$number', uploadedfile='$uploadedfile' WHERE id2=$id2"; $result = mysql_query($sql) or die(mysql_error()); echo "<div align=\"center\"><b>Thank you! Information updated.</b><br><br>"; echo "<a href=\"http://localhost/cas/contacts.php\">Contacts</a>"; echo " | "; echo "<a href=\"http://localhost/cas/members.php\">Member Home</a>";echo " | "; echo "<a href=\"http://localhost/cas/logout.php\">Logout</a></div>";echo " "; //check image upload status if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target)) { echo "Thank you, " . $_SESSION["valid_user"];echo ". Not you? <a href=\"http://localhost/cas/logout.php\">Click here.</a>"; echo "<br>"; //Tells you if its all ok echo "<br>"; echo "The file <b>". basename( $_FILES['uploadedfile']['name']). "</b> has been uploaded."; echo "</div>"; } else { //Gives and error if its not echo "<div align=\"center\">"; echo "Sorry, there was a problem uploading your file."; echo "</div>"; } } ?>
  2. Hey guys, I've just started coding php, for a school project. I'm creating a member login system with functions to add/edit contacts. Currently I'm stuck at updating the contacts. I'm able to pull up data into a form in a page called 'edit.php', but after updating and clicking submit, it just returns a blank page and the SQL database is not updated. This is the code from 'edit.php'. <? include ("dbConfig.php"); require ("check.php"); if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") { if (!isset($_POST["submit"])) { $id2 = $_GET["id2"]; $sql = "SELECT * FROM contacts WHERE id2=$id2"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form action="edit.php" method="post"> <input type=hidden name="id2" value="<?php echo $myrow["id2"] ?>"> Name:<INPUT TYPE="text" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br> Email:<INPUT TYPE="text" NAME="email" VALUE="<? echo $myrow["email"] ?>" SIZE=30><br> Who:<INPUT TYPE="text" NAME="age" VALUE="<?php echo $myrow["age"] ?>" SIZE=30><br> Birthday:<INPUT TYPE="text" NAME="birthday" VALUE="<? echo $myrow["birthday"] ?>" SIZE=30><br> Address:<TEXTAREA NAME="address" ROWS=10 COLS=30><? echo $myrow["address"] ?></TEXTAREA><br> Number:<INPUT TYPE="text" NAME="number" VALUE="<? echo $myrow["number"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? } ?> <? if ($_POST["$submit"]) { $id2 = $_POST["id2"]; $name = $_POST["name"]; $email = $_POST["email"]; $age = $_POST["age"]; $birthday = $_POST["birthday"]; $address = $_POST["address"]; $number = $_POST["number"]; $sql = "UPDATE contacts SET name='$name',email='$email',age='$age',birthday='$birthday',address='$address',number='$number' WHERE id2=$id2"; $result = mysql_query($sql); echo "Thank you! Information updated."; } } ?> Please help, truly appreciated.
×
×
  • 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.