antbates1991 Posted February 22, 2014 Share Posted February 22, 2014 (edited) So I've created a form that allows an estate agent to store customer information. I am now trying to allow this information to be edited in a HTML form. I can't figure out how to get the selected row to be echoed into my form fields and then updated back into the database. Here is my code so far. if (isset($_POST['showcatalogue'])) { $showallcustomers = "SELECT * from CustomerTable"; $allcustomerresults = mysql_query($showallcustomers); echo"<div class='page-restrict-output'>"; echo "<form method='post' action='customer-viewer'>"; echo "<input id='editcustomerbutton' type='Submit' name='editcustomerbtn' value='Edit Customer' /><br><br /></td></tr>"; echo "Here are the results, Select only ONE Customer to edit or the operation will FAIL. <br>"; echo "<br>"; echo"<table id='selectcustomertable' border='1'>"; echo "<tr><th>FirstName</th><th>SecondName</th><th>Address Line 1</th><th>Address Line 2</th><th>Address Line 3</th><th>Post Code</th><th>Customer ID</th><th>Phone Number</th><th>E-Mail</th><th>Edit Customer</th></tr>"; while($row = mysql_fetch_array($allcustomerresults)) { echo "<tr><td>"; echo $row['FirstName']; echo "</td><td>"; echo $row['SecondName']; echo "</td><td>"; echo $row['AddressLine1']; echo "</td><td>"; echo $row['AddressLine2']; echo "</td><td>"; echo $row['AddressLine3']; echo "</td><td>"; echo $row['PostCode']; echo "</td><td>"; echo $row['CustomerID']; echo "</td><td>"; echo $row['PhoneNumber']; echo "</td><td>"; echo $row['EMail']; echo "</td><td>"; echo $row['EditCustomer']; echo "<input id='selectcustomerbutton' type='checkbox' name='selectedCustomerIDS[]' value='$row[CustomerID]' /></td></tr>"; echo" </form>"; echo "</div>"; } $_POST['selectedCustomerIDS']; { echo "<form id=alleditcustomerform action='customer-viewer' autocomplete='on' method='post' onsubmit='return(validatecustomer());' >"; echo "<input type='hidden' name='savechanges' value='true' />"; echo "<br>"; foreach($_POST['selectedCustomerIDS'] as $CustomerIDforedit){ echo " You have selected Customer Number $CustomerIDforedit"; $theselectedrow = "SELECT row from CustomerTable WHERE '$CustomerIDforedit' = '$CustomerID'"; $theselectedrowresults = mysql_query($theselectedrow); $count = mysql_num_rows($theselectedrowresults); if ($count == 1) { $FirstName = $_GET['FirstName']; $SecondName = $_GET['SecondName']; $AddressLine1 = $_GET['AddressLine1']; $AddressLine2 = $_GET['AddressLine2']; $AddressLine3 = $_GET['AddressLine3']; $PostCode = $_GET['PostCode']; $PhoneNumber = $_GET['PhoneNumber']; $EMail = $_GET['EMail']; $IdealPrice = $_GET['IdealPrice']; $IdealLocation = $_GET['IdealLocation']; $IdealNumberOfBedrooms = $_GET['IdealNumberofBedrooms']; $IdealSize = $_GET['IdealSize']; echo "<br>"; echo "<label for='FirstName'>First Name*:</label><br>"; echo "<input id='FirstName' type='text' maxlength='20' name='FirstName' value='$row[FirstName]' pattern='^[a-zA-Z]{2,20}$' required /><br>"; echo "<br>"; echo "<label for='SecondName'>Second Name*:</label><br>"; echo "<input id='SecondName' type='text' maxlength='20' name='SecondName' value='$row[SecondName]' pattern='^[a-zA-Z]{2,20}$' required /><br>"; echo "<br>"; echo "<label for='AddressLine1'>Address Line 1*:</label><br>"; echo "<input id='AddressLine1' type='text' maxlength='30' name='AddressLine1' value='$row[AddressLine1]' required /><br>"; echo "<br>"; echo "<label for='AddressLine2'>Address Line 2*:</label><br>"; echo "<input id='AddressLine2' type='text' maxlength='30' name='AddressLine2' value='$row[AddressLine2]' required /><br>"; echo "<br>"; echo "<label for='AddressLine3'>Address Line 3*:</label><br>"; echo "<input id='AddressLine3' type='text' maxlength='30' name='AddressLine3' value='$row[AddressLine3]' required /><br>"; echo "<br>"; echo "<label for='PostCode'>Post Code (with a space)*:</label><br>"; echo "<input id='PostCode' type='text' maxlength='10' name='PostCode' value='$row[PostCode]' pattern='[A-Za-z]{1,2}[0-9Rr][0-9A-Za-z]? [0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}' required /><br>"; echo "<br>"; echo "<label for='PhoneNumber'>Phone Number*:</label><br>"; echo "<input id='PhoneNumber' type='tel' maxlength='11' name='PhoneNumber' value='$row[PhoneNumber]' pattern='^\s*\(?(020[7,8]{1}\)?[ ]?[1-9]{1}[0-9{2}[ ]?[0-9]{4})|(0[1-8]{1}[0-9]{3}\)?[ ]?[1-9]{1}[0-9]{2}[ ]?[0-9]{3})\s*$' required /><br>"; echo "<br>"; echo "<label for='EMail'>Email Address*:</label><br>"; echo "<input id='EMail' type='email' maxlength='50' name='EMail' value='$row[EMail]' required /><br>"; echo "<br>"; echo "<label for='IdealLocation'>Ideal Location:</label><br>"; echo "<input id='IdealLocation' type='text' maxlength='10' value='$row[IdealLocation]' name='IdealLocation' /><br>"; echo "<br>"; echo "<label for='IdealPrice'>Ideal Price:</label><br>"; echo "<input id='IdealPrice' type='number' min='10000' max='100000000000' value='$row[IdealPrice]' step='100' maxlength='12' name='IdealPrice' pattern='^\\$?(([1-9](\\d*|\\d{0,2}(,\\d{3})*))|0)(\\.\\d{1,2})?$' required /><br>"; echo "<br>"; echo "<label for='IdealNumberofBedrooms'>Ideal Number of Bedrooms:</label><br>"; echo "<input id='IdealNumberofBedrooms' type='number' max='10' maxlength='10' min='1' value='$row[IdealNumberofBedrooms]' name='IdealNumberofBedrooms' step='1' value='1' /><br>"; echo "<br>"; echo "<label for='IdealSize'>Ideal Size (M2):</label><br>"; echo "<input id='IdealSize' type='number' max='100000' maxlength='10' min='20' step='10' value='$row[IdealSize]' name='IdealSize' step='1' value='1' /><br>"; echo "<br>"; echo "<input id='Submit' type='submit' name='savechanges' value='Submit Changes' /><br>"; } } if (isset($_POST['savechanges'])) { $FirstName = $_POST['FirstName']; $SecondName = $_POST['SecondName']; $AddressLine1 = $_POST['AddressLine1']; $AddressLine2 = $_POST['AddressLine2']; $AddressLine3 = $_POST['AddressLine3']; $PostCode = $_POST['PostCode']; $PhoneNumber = $_POST['PhoneNumber']; $EMail = $_POST['EMail']; $IdealPrice = $_POST['IdealPrice']; $IdealLocation = $_POST['IdealLocation']; $IdealNumberOfBedrooms = $_POST['IdealNumberofBedrooms']; $IdealSize = $_POST['IdealSize']; $error; $addcustomer = "SELECT * FROM CustomerTable WHERE EMail = '$EMail'"; $resultaddcustomer = mysql_query($addcustomer); $count = mysql_num_rows($resultaddcustomer); if ($count == 1) { $_POST["EMail"] = $EMail; echo 'Sorry the Email Address you entered already has an account. Press your browsers back button to return. '; } else { # Validate First Name # // if its not alpha numeric, throw error if (!ctype_alpha($FirstName)) { $error .= '<p>First name should be letters only.</p>'; echo $error; } // if first_name is not 3-20 characters long, throw error if (strlen($FirstName) < 3 OR strlen($FirstName) > 20) { $error .= '<p>First name should be within 3-20 characters long.</p>'; echo $error; } # Validate Last Name # // if its not alpha numeric, throw error if (!ctype_alpha($SecondName)) { $error .= '<p>Last name should be letters only.</p>'; echo $error; } // if last_name is not 3-20 characters long, throw error if (strlen($SecondName) < 3 OR strlen($SecondName) > 20) { $error .= '<p>Last name should be within 3-20 characters long.</p>'; echo $error; } # Validate Email # // if email is invalid, throw error if (!filter_var($EMail, FILTER_VALIDATE_EMAIL)) { // you can also use regex to do same echo $error .= '<p>Enter a valid email address.</p>'; } # Validate Phone # // if phone is invalid, throw error if (!ctype_digit($PhoneNumber) OR strlen($PhoneNumber) != 11) { $error .= '<p>Enter a valid phone number.</p>'; echo $error; } if (empty($error)){ $queryuploadcustomer = "UPDATE CustomerTable (FirstName, SecondName, AddressLine1, AddressLine2, AddressLine3, PhoneNumber, PostCode, EMail, IdealPrice, IdealLocation, IdealNumberofBedrooms, IdealSize) VALUES ('$FirstName', '$SecondName', '$AddressLine1', '$AddressLine2', '$AddressLine3', '$PhoneNumber', '$PostCode', '$EMail', '$IdealPrice', '$IdealLocation', '$IdealNumberOfBedrooms', '$IdealSize')"; } } } } } Edited February 22, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/ Share on other sites More sharing options...
denno020 Posted February 22, 2014 Share Posted February 22, 2014 What value is currently being echoed into your input fields? Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470017 Share on other sites More sharing options...
antbates1991 Posted February 22, 2014 Author Share Posted February 22, 2014 At the moment nothing. In the HTML code using the developer tools in chrome it shows <input id='FirstName' type='text' maxlength='20' value name='FirstName' /> It doesn't even show value='' just value. Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470019 Share on other sites More sharing options...
denno020 Posted February 22, 2014 Share Posted February 22, 2014 The way you are trying to print the value from $row is like this: $row[FirstName] It needs to be like this: $row['FirstName'] Notice the quotes. Easy to miss that because you have a tonne of single and double quotes going on in your code. Give that a try and see if it helps. Denno Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470021 Share on other sites More sharing options...
antbates1991 Posted February 22, 2014 Author Share Posted February 22, 2014 That doesn't work, if I change them to that I get unexpected''. on each line. Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470025 Share on other sites More sharing options...
denno020 Posted February 22, 2014 Share Posted February 22, 2014 (edited) Try this then: echo "<input id='FirstName' type='text' maxlength='20' name='FirstName' value='".$row['FirstName']."' pattern='^[a-zA-Z]{2,20}$' required /><br>"; Oh and don't change all of your input fields, just change one, until you get that one working, then apply the same changes to the rest. Will save you a tonne of time debugging Denno Edited February 22, 2014 by denno020 Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470026 Share on other sites More sharing options...
antbates1991 Posted February 22, 2014 Author Share Posted February 22, 2014 That runs fine with no errors but its the same result input id='FirstName' type='text' maxlength='20' value name='FirstName' Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470028 Share on other sites More sharing options...
denno020 Posted February 22, 2014 Share Posted February 22, 2014 Then you'll need to add a var_dump($row);die(); just after $row is set, so you can have a look-see at what's actually in that array. Perhaps you're getting your index incorrect.. Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470030 Share on other sites More sharing options...
antbates1991 Posted February 22, 2014 Author Share Posted February 22, 2014 (edited) Ok I've made some changes since I notice a issue with my SQL Query but it still doesn't work. I get the same issue. The $row = Null according to the var dump. The new code is below. if (isset($_POST['showcatalogue'])) { $showallcustomers = "SELECT * from CustomerTable"; $allcustomerresults = mysql_query($showallcustomers); echo"<div class='page-restrict-output'>"; echo "<form method='post' action='customer-viewer'>"; echo "<input id='editcustomerbutton' type='Submit' name='editcustomerbtn' value='Edit Customer' /><br><br /></td></tr>"; echo "Here are the results, Select only ONE Customer to edit or the operation will FAIL. <br>"; echo "<br>"; echo"<table id='selectcustomertable' border='1'>"; echo "<tr><th>FirstName</th><th>SecondName</th><th>Address Line 1</th><th>Address Line 2</th><th>Address Line 3</th><th>Post Code</th><th>Customer ID</th><th>Phone Number</th><th>E-Mail</th><th>Edit Customer</th></tr>"; while($row = mysql_fetch_array($allcustomerresults)) { echo "<tr><td>"; echo $row['FirstName']; echo "</td><td>"; echo $row['SecondName']; echo "</td><td>"; echo $row['AddressLine1']; echo "</td><td>"; echo $row['AddressLine2']; echo "</td><td>"; echo $row['AddressLine3']; echo "</td><td>"; echo $row['PostCode']; echo "</td><td>"; echo $row['CustomerID']; echo "</td><td>"; echo $row['PhoneNumber']; echo "</td><td>"; echo $row['EMail']; echo "</td><td>"; echo $row['EditCustomer']; echo "<input id='selectcustomerbutton' type='checkbox' name='selectedCustomerIDS[]' value='$row[CustomerID]' /></td></tr>"; echo" </form>"; echo "</div>"; } $_POST['selectedCustomerIDS']; { echo "<form id=alleditcustomerform action='customer-viewer' autocomplete='on' method='post' onsubmit='return(validatecustomer());' >"; echo "<input type='hidden' name='savechanges' value='true' />"; echo "<br>"; foreach($_POST['selectedCustomerIDS'] as $CustomerIDforedit){ echo " You have selected Customer Number $CustomerIDforedit"; $theselectedrow = "SELECT * from CustomerTable WHERE 'CustomerID' = '$CustomerIDforedit'"; $theselectedrowresults = mysql_query($theselectedrow); $count = mysql_num_rows($theselectedrowresults); if ($count == 1) { $FirstName = $_GET['FirstName']; $SecondName = $_GET['SecondName']; $AddressLine1 = $_GET['AddressLine1']; $AddressLine2 = $_GET['AddressLine2']; $AddressLine3 = $_GET['AddressLine3']; $PostCode = $_GET['PostCode']; $PhoneNumber = $_GET['PhoneNumber']; $EMail = $_GET['EMail']; $IdealPrice = $_GET['IdealPrice']; $IdealLocation = $_GET['IdealLocation']; $IdealNumberOfBedrooms = $_GET['IdealNumberofBedrooms']; $IdealSize = $_GET['IdealSize']; echo "<br>"; echo "<label for='FirstName'>First Name*:</label><br>"; echo "<input id='FirstName' type='text' maxlength='20' name='FirstName' '".$row['FirstName']."' pattern='^[a-zA-Z]{2,20}$' required /><br>"; echo "<br>"; echo "<label for='SecondName'>Second Name*:</label><br>"; echo "<input id='SecondName' type='text' maxlength='20' name='SecondName' value='$row[SecondName]' pattern='^[a-zA-Z]{2,20}$' required /><br>"; echo "<br>"; echo "<label for='AddressLine1'>Address Line 1*:</label><br>"; echo "<input id='AddressLine1' type='text' maxlength='30' name='AddressLine1' value='$row[AddressLine1]' required /><br>"; echo "<br>"; echo "<label for='AddressLine2'>Address Line 2*:</label><br>"; echo "<input id='AddressLine2' type='text' maxlength='30' name='AddressLine2' value='$row[AddressLine2]' required /><br>"; echo "<br>"; echo "<label for='AddressLine3'>Address Line 3*:</label><br>"; echo "<input id='AddressLine3' type='text' maxlength='30' name='AddressLine3' value='$row[AddressLine3]' required /><br>"; echo "<br>"; echo "<label for='PostCode'>Post Code (with a space)*:</label><br>"; echo "<input id='PostCode' type='text' maxlength='10' name='PostCode' value='$row[PostCode]' pattern='[A-Za-z]{1,2}[0-9Rr][0-9A-Za-z]? [0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}' required /><br>"; echo "<br>"; echo "<label for='PhoneNumber'>Phone Number*:</label><br>"; echo "<input id='PhoneNumber' type='tel' maxlength='11' name='PhoneNumber' value='$row[PhoneNumber]' pattern='^\s*\(?(020[7,8]{1}\)?[ ]?[1-9]{1}[0-9{2}[ ]?[0-9]{4})|(0[1-8]{1}[0-9]{3}\)?[ ]?[1-9]{1}[0-9]{2}[ ]?[0-9]{3})\s*$' required /><br>"; echo "<br>"; echo "<label for='EMail'>Email Address*:</label><br>"; echo "<input id='EMail' type='email' maxlength='50' name='EMail' value='$row[EMail]' required /><br>"; echo "<br>"; echo "<label for='IdealLocation'>Ideal Location:</label><br>"; echo "<input id='IdealLocation' type='text' maxlength='10' value='$row[IdealLocation]' name='IdealLocation' /><br>"; echo "<br>"; echo "<label for='IdealPrice'>Ideal Price:</label><br>"; echo "<input id='IdealPrice' type='number' min='10000' max='100000000000' value='$row[IdealPrice]' step='100' maxlength='12' name='IdealPrice' pattern='^\\$?(([1-9](\\d*|\\d{0,2}(,\\d{3})*))|0)(\\.\\d{1,2})?$' required /><br>"; echo "<br>"; echo "<label for='IdealNumberofBedrooms'>Ideal Number of Bedrooms:</label><br>"; echo "<input id='IdealNumberofBedrooms' type='number' max='10' maxlength='10' min='1' value='$row[IdealNumberofBedrooms]' name='IdealNumberofBedrooms' step='1' value='1' /><br>"; echo "<br>"; echo "<label for='IdealSize'>Ideal Size (M2):</label><br>"; echo "<input id='IdealSize' type='number' max='100000' maxlength='10' min='20' step='10' value='$row[IdealSize]' name='IdealSize' step='1' value='1' /><br>"; echo "<br>"; echo "<input id='Submit' type='submit' name='savechanges' value='Submit Changes' /><br>"; } } if (isset($_POST['savechanges'])) { $FirstName = $_POST['FirstName']; $SecondName = $_POST['SecondName']; $AddressLine1 = $_POST['AddressLine1']; $AddressLine2 = $_POST['AddressLine2']; $AddressLine3 = $_POST['AddressLine3']; $PostCode = $_POST['PostCode']; $PhoneNumber = $_POST['PhoneNumber']; $EMail = $_POST['EMail']; $IdealPrice = $_POST['IdealPrice']; $IdealLocation = $_POST['IdealLocation']; $IdealNumberOfBedrooms = $_POST['IdealNumberofBedrooms']; $IdealSize = $_POST['IdealSize']; $error; $addcustomer = "SELECT * FROM CustomerTable WHERE EMail = '$EMail'"; $resultaddcustomer = mysql_query($addcustomer); $count = mysql_num_rows($resultaddcustomer); if ($count == 1) { $_POST["EMail"] = $EMail; echo 'Sorry the Email Address you entered already has an account. Press your browsers back button to return. '; } else { # Validate First Name # // if its not alpha numeric, throw error if (!ctype_alpha($FirstName)) { $error .= '<p>First name should be letters only.</p>'; echo $error; } // if first_name is not 3-20 characters long, throw error if (strlen($FirstName) < 3 OR strlen($FirstName) > 20) { $error .= '<p>First name should be within 3-20 characters long.</p>'; echo $error; } # Validate Last Name # // if its not alpha numeric, throw error if (!ctype_alpha($SecondName)) { $error .= '<p>Last name should be letters only.</p>'; echo $error; } // if last_name is not 3-20 characters long, throw error if (strlen($SecondName) < 3 OR strlen($SecondName) > 20) { $error .= '<p>Last name should be within 3-20 characters long.</p>'; echo $error; } # Validate Email # // if email is invalid, throw error if (!filter_var($EMail, FILTER_VALIDATE_EMAIL)) { // you can also use regex to do same echo $error .= '<p>Enter a valid email address.</p>'; } # Validate Phone # // if phone is invalid, throw error if (!ctype_digit($PhoneNumber) OR strlen($PhoneNumber) != 11) { $error .= '<p>Enter a valid phone number.</p>'; echo $error; } if (empty($error)){ $queryuploadcustomer = "UPDATE CustomerTable (FirstName, SecondName, AddressLine1, AddressLine2, AddressLine3, PhoneNumber, PostCode, EMail, IdealPrice, IdealLocation, IdealNumberofBedrooms, IdealSize) VALUES ('$FirstName', '$SecondName', '$AddressLine1', '$AddressLine2', '$AddressLine3', '$PhoneNumber', '$PostCode', '$EMail', '$IdealPrice', '$IdealLocation', '$IdealNumberOfBedrooms', '$IdealSize')"; } } } } } Edited February 22, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470031 Share on other sites More sharing options...
denno020 Posted February 22, 2014 Share Posted February 22, 2014 (edited) Are you sure you're actually getting results from your SQL query? Have you got phpmyadmin or something similar that you can use to test your query? Also, can you post your code inside [ code ] tags, makes it much easier to read Edited February 22, 2014 by denno020 Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470032 Share on other sites More sharing options...
antbates1991 Posted February 22, 2014 Author Share Posted February 22, 2014 (edited) That might be the issue, here is what I think it should be doing. The CustomerID for this test in the database is 13. If I do SELECT * FROM `CustomerTable` WHERE `CustomerID` = 13 in phpmyadmin. I get the result returned. The ID that it taken from the form is stored in $CustomerIDforedit. I echo this out after a customer is selected and that also says 13, or whatever ID corresponds the record you have selected. So when I select from the database using $theselectedrow = "SELECT * from CustomerTable WHERE 'CustomerID' = '$CustomerIDforedit'"; that should select the Customer ID from the database that is equal to the number stored in $CustomerIDforedit. So if $CustomerIDforedit is echoing out 13 it should select record 13. Edited February 22, 2014 by antbates1991 Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470033 Share on other sites More sharing options...
Ch0cu3r Posted February 22, 2014 Share Posted February 22, 2014 (edited) Here you have not got the results from the query. You have only queried the database $theselectedrow = "SELECT * from CustomerTable WHERE 'CustomerID' = '$CustomerIDforedit'"; $theselectedrowresults = mysql_query($theselectedrow); $count = mysql_num_rows($theselectedrowresults); You need to get the results from the query using one of the mysql_fetch_* functions. Eg $row = mysql_fetch_assoc($theselectedrowresults); // echo the form for editing record If your query returns multiple results, then you'll need to use a while loop while($row = mysql_fetch_assoc($theselectedrowresults)) { // echo form for editing record } Edited February 22, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470034 Share on other sites More sharing options...
antbates1991 Posted February 22, 2014 Author Share Posted February 22, 2014 I've added this and now if I place the form in a while loop it is not echoed. Does this mean the while loop is not finding any rows for the condition? and var_dump($row);die(); shows bool(false). Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470037 Share on other sites More sharing options...
denno020 Posted February 22, 2014 Share Posted February 22, 2014 Does this mean the while loop is not finding any rows for the condition? That's what appears to have happened.. Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470038 Share on other sites More sharing options...
Ch0cu3r Posted February 22, 2014 Share Posted February 22, 2014 I've added this and now if I place the form in a while loop it is not echoed. Does this mean the while loop is not finding any rows for the condition? and var_dump($row);die(); shows bool(false). Where have place that? Before or after you defined $row? Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470039 Share on other sites More sharing options...
antbates1991 Posted February 22, 2014 Author Share Posted February 22, 2014 After. I've done some more editing, I've changed the query to $theselectedrow = "SELECT * from CustomerTable WHERE 'CustomerID' = '13'"; As I know this works and selects the record in phpmyadmin. But here I get no result again just bool(false). Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470040 Share on other sites More sharing options...
denno020 Posted February 22, 2014 Share Posted February 22, 2014 You have opened a connection to the database haven't you? I'm not sure if you get exceptions thrown if you try and execute a query without first selecting the database.. Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470041 Share on other sites More sharing options...
antbates1991 Posted February 22, 2014 Author Share Posted February 22, 2014 (edited) Yes the connection is open. If it wasn't the database wouldn't be able to list the database contents in the table. Before you select a customer to edit. Edited February 22, 2014 by antbates1991 Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470042 Share on other sites More sharing options...
Ch0cu3r Posted February 22, 2014 Share Posted February 22, 2014 After. I've done some more editing, I've changed the query to $theselectedrow = "SELECT * from CustomerTable WHERE 'CustomerID' = '13'"; As I know this works and selects the record in phpmyadmin. But here I get no result again just bool(false). So your code is this $theselectedrow = "SELECT * from CustomerTable WHERE 'CustomerID' = '13'"; var_dump($row);die(); Then, it will always be null. Because a) you have not executed the query and b) you haven't define $row. Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470043 Share on other sites More sharing options...
antbates1991 Posted February 22, 2014 Author Share Posted February 22, 2014 The code looks like this $theselectedrow = "SELECT * from CustomerTable WHERE 'CustomerID' = '13'"; $theselectedrowresults = mysql_query($theselectedrow); $row = mysql_fetch_assoc($theselectedrowresults); Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470044 Share on other sites More sharing options...
Ch0cu3r Posted February 22, 2014 Share Posted February 22, 2014 (edited) Ok, check to make sure your query is returning an error. $theselectedrow = "SELECT * from CustomerTable WHERE 'CustomerID' = '13'"; $theselectedrowresults = mysql_query($theselectedrow); if(!$theselectedrowresults) { echo '<p><b>Database error:</b> ' . mysql_error() . '</p>'; } else { if(mysql_num_rows($theselectedrowresults)) { $row = mysql_fetch_assoc($theselectedrowresults); var_dump($row); } else { echo 'No results returned from query'; } } Edited February 22, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470047 Share on other sites More sharing options...
antbates1991 Posted February 22, 2014 Author Share Posted February 22, 2014 (edited) It's returning no results found. Edited February 22, 2014 by antbates1991 Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470048 Share on other sites More sharing options...
Solution Ch0cu3r Posted February 22, 2014 Solution Share Posted February 22, 2014 Remove the quotes, from around CustomerID in your query. So it is $theselectedrow = "SELECT * from CustomerTable WHERE CustomerID = 13"; Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470049 Share on other sites More sharing options...
antbates1991 Posted February 22, 2014 Author Share Posted February 22, 2014 Perfect that is all it is. It's now fully working with all the results echoing into the fields. Thanks you so much Quote Link to comment https://forums.phpfreaks.com/topic/286405-editing-a-users-record/#findComment-1470051 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.