Jump to content

edit customers record php id issue


ianhaney50

Recommended Posts

Hi

 

I am in the middle of making a edit customers details php page and came across a id issue, it is adding odd numbers to the id instead of the correct id it should be

 

below is my coding for the view customers php page

<?php

        $con=  mysqli_connect("localhost", "username", "password", "username");
        if(!$con)
       {
           die('not connected');
       }
            $con=  mysqli_query($con, "SELECT plans_name, machine1, machine2, machine3, machine4, machine5, customer_name, customer_email, customer_phone, DATE_FORMAT(date_purchased_plan, '%d/%m/%Y') AS date_purchased_plan from plans");
			
       ?>
        <div>
        
            <td>Customers</td>
         <table>
            <th>Support Plan</th>
                    <th>Machine 1</th>
                    <th>Machine 2</th>
                     <th>Machine 3</th>
                    <th>Machine 4</th>
                    <th>Machine 5</th>
                    <th>Customer Name</th>
                    <th>Customer Email</th>
                    <th>Customer Phone</th>
                    <th>Plan Purchase Date</th>
                    <th colspan="2">Actions</th>

            </tr>

        <?php

             while($row=  mysqli_fetch_array($con))
             {
                 ?>
            <tr>
                <td><?php echo $row['plans_name']; ?></td>
                <td><?php echo $row['machine1']; ?></td>
                <td><?php echo $row['machine2']; ?></td>
                <td><?php echo $row['machine3'] ;?></td>
                <td><?php echo $row['machine4'] ;?></td>
                <td><?php echo $row['machine5'] ;?></td>
                <td><?php echo $row['customer_name'] ;?></td>
                <td><?php echo $row['customer_email'] ;?></td>
                <td><?php echo $row['customer_phone'] ;?></td>
                <td><?php echo $row['date_purchased_plan'];?></td>
                <td><a href="edit-customer.php?id=' . $row['id'] . '">Edit</a></td>
                <td><a href="delete.php?id=' . $row['id'] . '" onClick="return confirm('."'Are you sure you want to delete this record?');".'">Delete</a></td>
            </tr>
        <?php
             }
             ?>
             </table>
            </div>

In the url when I click on edit, the url looks like the following

 

http://www.it-doneright.co.uk/admin/edit-customer.php?id=%27%20.%20$row[%27id%27]%20.%20%27

 

see the issue with the %27%20 etc.

 

is there something I need to add in the view-customers.php file?

 

Thank you in advance

 

Ian

Link to comment
Share on other sites

$row['id'] is not inside php so its showing it as plain text

 <td><a href="edit-customer.php?id=' . $row['id'] . '">Edit</a></td>
 <td><a href="delete.php?id=' . $row['id'] . '" onClick="return confirm('."'Are you sure you want to delete this record?');".'">Delete</a></td>

to

<td><a href="edit-customer.php?id="<?php echo $row['id'] ?>">Edit</a></td>
<td><a href="delete.php?id="<?php echo $row['id'] ?>" onClick="return confirm('."'Are you sure you want to delete this record?');".'">Delete</a></td>

should work

Edited by hyster
Link to comment
Share on other sites

Hi hyster

 

Thank you so much for the reply, appreciate it

 

I put the coding in and got the following error within the table that displays the results from the database

 

Notice: Undefined index: id in /home/sites/it-doneright.co.uk/public_html/admin/view-customers.php on line 79
" onClick="return confirm('."'Are you sure you want to delete this record?');".'">Delete
Link to comment
Share on other sites

I myself write most of the content in PHP. therefore i open PHP at the beginning of the page and end it on the very bottom.

the method is than like this:

<?php

$test = "Hello World";

dbconnect(); //a function to make db connection and set $con

while ($row = mysqli_fetch_array($con));
{
     echo "here is a db entry <a href='link'>" . $row['machine1'] . "</a>";

     echo "here is a second link <button onClick='window.location.href=\"http://www.google.nl\";'>a button</button>";

     echo "This is an inline test message: $test. <br> that can be used in an echo";
}

?>

with this method:

- you can write PHP everywhere on the page without opening/closing php tags (<?php  ?>)

- all HTML is echoed with "double quotes" and concatenated to the PHP with dots.

- if you need quotes in an echoed html line you use single quotes (it wont interfere with the PHP code)

- if you need a third set of quotes like in the 2nd echo you escape the double quotes with the PHP escape char \

- on the third echo you see a variable output without any quotes.

 

not saying this is a MUST method.. but for me it makes things simple and reduce errors. (especcialiy the one you have now).

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.