0

Im creating an script that selects data from a data table and then shows all the information from that row of data and allows you to edit the text. Currently there is no information appearing in the boxes:

Here is what the data table looks like currently

Here is what the data should look like, as you can see the information should already be present but it gives you the option to edit the file.

So there are 3 files:


File Number 1: Typing in the ID Number:

<!DOCTYPE.html>
<html>
<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<HTML>
<BODY>
<form method="post" action="export1.php">
Enter ID:<input type="Text" id="id" name="id"><br>
<input type="Submit" name="Submit ID" value="Submit">
</form>


</BODY>
</HTML>

File Number 2: Option to edit the data:

<?php

$db = mysqli_connect("somedb", "someuser", "somepassword");
mysqli_select_db($db,"leadlist");
$id=$_POST['export'];
mysqli_query($db, "SELECT * FROM `leadlist` WHERE id=$id");

$id = mysqli_real_escape_string($link, $_REQUEST['id']);
$fname = mysqli_real_escape_string($link, $_REQUEST['fname']);
$sname = mysqli_real_escape_string($link, $_REQUEST['sname']);
$address = mysqli_real_escape_string($link, $_REQUEST['address']);
$email = mysqli_real_escape_string($link, $_REQUEST['email']);
$phone = mysqli_real_escape_string($link, $_REQUEST['phone']);
$package = mysqli_real_escape_string($link, $_REQUEST['package']);
$active = mysqli_real_escape_string($link, $_REQUEST['active']);
$mac = mysqli_real_escape_string($link, $_REQUEST['mac']);

?>
<!DOCTYPE.html>
<html>
<head>
    <title></title>
    <link href="userscript.css" type="text/css" rel="stylesheet">
</head>
<body>
    <div id="textentryhead">
        <h1>Reave</h1>
    </div>
    <div id="textentry">
    <div>
        <form action="exportcode1.php" method="post">
    <p>
        <label for="firstName">First Name :</label><br>
        <input type="text" name="fname" placeholder="<?php echo $fname ?>" id="fname">
        <hr>
    </p>
    <p>
        <label for="lastName">Last Name :</label><br>
        <input type="text" name="sname" placeholder="<?php echo $sname ?>" id="sname">
        <hr>
    </p>
    <p>
        <label for="emailAddress">Address :  </label><br>
        <input type="text" name="address" placeholder="<?php echo $address ?>" id="address">
        <hr>
    </p>
     <p>
        <label for="firstName">Email Address :   </label><br>
        <input type="text" name="email" placeholder="<?php echo $email ?>" id="email">
        <hr>
    </p>
    <p>
        <label for="lastName">Phone Number :</label><br>
        <input type="text" name="phone" placeholder="<?php echo $phone ?>" id="phone">
        <hr>
    </p>
      <p>
        <label for="emailAddress">Package Type :</label><br>
        <input type="text" name="package" placeholder="<?php echo $package ?>" id="package">
        <hr>
    </p>
      <p>
        <label for="emailAddress">Package Status :</label><br>
        <input type="text" name="active" placeholder="<?php echo $active ?>" id="active">
        <div id="help"><h6><a href="help.php">Help</a></h6></div>
        <hr>
    </p>
    <p>
        <label for="emailAddress">MAC Address :</label><br>
        <input type="text" name="mac" placeholder="<?php echo $mac ?>" id="mac">
        <hr>
    </p>
    <input type="submit" value="Submit">
</form>
    </div>
</div>
</body>

File Number 3: Adding the new data into a different data table:

<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

$fname = mysqli_real_escape_string($link, $_REQUEST['fname']);
$sname = mysqli_real_escape_string($link, $_REQUEST['sname']);
$address = mysqli_real_escape_string($link, $_REQUEST['address']);
$email = mysqli_real_escape_string($link, $_REQUEST['email']);
$phone = mysqli_real_escape_string($link, $_REQUEST['phone']);
$package = mysqli_real_escape_string($link, $_REQUEST['package']);
$active = mysqli_real_escape_string($link, $_REQUEST['active']);
$mac = mysqli_real_escape_string($link, $_REQUEST['mac']);


$sql = "INSERT INTO CData (fname, sname, address, email, phone, package, active, mac) VALUES ('$fname', '$sname', '$address', '$email', '$phone', '$package', '$active', '$mac')";
if(mysqli_query($link, $sql)){

                mysqli_close($conn);
                header("Location: ");




                exit;

} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// Close connection
mysqli_close(

So if someone can help me get this working it would be great. :)

ventaquil
  • 2,780
  • 3
  • 23
  • 48
  • One thing i noticed is that you are using placeholders to display data which are actual values of each field. using the `value` property of the input would be more relevant than using the `placeholder` one i think. – hugodecasta Mar 03 '19 at 00:29
  • The value input is working better, but it's not displaying the information still. And thanks for your previous comment ;) – Michael Cunningham Mar 03 '19 at 00:39
  • `$db = mysqli_connect(");` - is ugly. I am sure it's just a mistake in the question. But it's breaking the color coding. – ArtisticPhoenix Mar 03 '19 at 00:39
  • @ArtisticPhoenix fixed – ventaquil Mar 03 '19 at 01:23
  • 1
    Not sure why you would want them as placeholders and not the value, but you should not be using `_REQUEST` and you should be checking if the form was posted before doing any of this. https://stackoverflow.com/questions/2142497/whats-wrong-with-using-request – ArtisticPhoenix Mar 03 '19 at 01:27
  • Shouldn't $id=$_POST['export']; be $id=$_POST['id'];, and if you are sending a _POST request, use _POST in place of all those _REQUEST, keep things organized! – Stephanie Temple Mar 03 '19 at 01:32
  • Still haven't got it working. please if anyone can help that would be great. – Michael Cunningham Mar 03 '19 at 16:45

0 Answers0