ianhaney50 Posted October 10, 2015 Share Posted October 10, 2015 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 Quote Link to comment https://forums.phpfreaks.com/topic/298523-edit-customers-record-php-id-issue/ Share on other sites More sharing options...
hyster Posted October 10, 2015 Share Posted October 10, 2015 (edited) $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 October 10, 2015 by hyster Quote Link to comment https://forums.phpfreaks.com/topic/298523-edit-customers-record-php-id-issue/#findComment-1522902 Share on other sites More sharing options...
ianhaney50 Posted October 11, 2015 Author Share Posted October 11, 2015 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 Quote Link to comment https://forums.phpfreaks.com/topic/298523-edit-customers-record-php-id-issue/#findComment-1522923 Share on other sites More sharing options...
Tommie84 Posted October 11, 2015 Share Posted October 11, 2015 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). Quote Link to comment https://forums.phpfreaks.com/topic/298523-edit-customers-record-php-id-issue/#findComment-1522928 Share on other sites More sharing options...
Barand Posted October 11, 2015 Share Posted October 11, 2015 To have $row['id'] in your results you need to select "id" in your query. Quote Link to comment https://forums.phpfreaks.com/topic/298523-edit-customers-record-php-id-issue/#findComment-1522931 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.