Hi. I am busy building my first application in PHP. I am having some troubles though with a script that is not returning any data from MySQL.
The script seems to run fine though. How can I troubleshoot it ifI don't even know where to start.
Here is the script in question:
<?php
if (isset($_POST['submit']) && $_POST['submit'] == "Update") {
$city_update = "SELECT * FROM areas WHERE area_id = '" . $_POST['city'] ."'";
$result_city_update = mysql_query($city_update)
or die(mysql_error());
$row_city = mysql_fetch_array($result_city_update);
$query_update = "UPDATE customers SET cust_firstname = '" .
$_POST['firstname'] . "', last_name = '" .
$_POST['lastname'] . "', cust_pwd = (PASSWORD('" .
$_POST['password'] . "')), cust_addr1 = '" .
$_POST['addr1'] . "', cust_addr2 = '" .
$_POST['addr2'] . "', cust_city = '" .
$_POST['city'] . "', cust_province = '" .
$row_city['province'] . "', cust_zip = '" .
$row_city['zip'] . "', cust_phone = '" .
$_POST['phone'] . "', cust_cell = '" .
$_POST['cell'] . "', cust_fax = '" .
$_POST['fax'] . "', email = '" .
$_POST['email'] . "', cust_type = '" .
$_POST['type'] . "', cust_acclvl = '" .
$_POST['acclvl'] . "' " .
"WHERE cust_id = '" . $_POST['id'] . "'";
$result_update = mysql_query($query_update)
or die(mysql_error());
$query = "SELECT * FROM customers WHERE cust_id = '" . $_POST['id'] . "'";
$result = mysql_query($query)
or die(mysql_error());
$row = mysql_fetch_array($result);
/* $hobbies = explode(", ", $row['hobbies']) */
$query2 = "SELECT * FROM areas ORDER BY area_city";
$result2 = mysql_query($query2)
or die('Could not get cities; ' . mysql_error());
$row2 = mysql_fetch_array($result2);
?>
<b>User information has been updated.</b><br>
<a href="admin_area.php">Click here</a> to return to the admin area.
<form action="update_user.php" method="post">
<input type="hidden" name="id" value="<?php echo $_POST['id']; ?>">
First Name: <br /><input type="text" name="first_name"
value="<?php echo $row['first_name']; ?>"><br /><br />
Last Name: <br /><input type="text" name="last_name"
value="<?php echo $row['last_name']; ?>"><br /><br />
Password: <br /><input type="password" name="password"
value=""> Not displayed<br /><br />
Address line1: <br /><input type="text" name="addr1"
value="<?php echo $row['cust_addr1']; ?>"><br /><br />
Address line2: <br /><input type="text" name="addr2"
value="<?php echo $row['cust_addr2']; ?>"><br /><br />
Town/City: <br /><select name="city">
<option value="" selected="selected">Select a city</option>
<?php while ($row2 = mysql_fetch_array($result2)){
echo " <option value=\"" . $row2['area_id'] ."\">" . $row2['area_city'] .
"</option>\n";} ?>
</select><br /><br />
Province: <br /><input disabled type="text" name="province"
value="<?php echo $row['cust_province']; ?>"> - Will update once info saved<br /><br />
Zip: <br /><input disabled type="text" name="zip"
value="<?php echo $row['cust_zip']; ?>"> - Will update once info saved<br /><br />
Phone: <br /><input type="text" name="phone"
value="<?php echo $row['cust_phone']; ?>"><br /><br />
Cell: <br /><input type="text" name="cell"
value="<?php echo $row['cust_cell']; ?>"><br /><br />
Fax: <br /><input type="text" name="fax"
value="<?php echo $row['cust_fax']; ?>"><br /><br />
Email: <br /><input type="text" name="email"
value="<?php echo $row['cust_email']; ?>"><br /><br />
Type: (buyer or registrar) <br />Buyer: <input type="radio" name="type"
value="<?php echo $row['cust_acclvl']; ?>" id="<?php echo $row['cust_acclvl']; ?>">
Registrar: <input type="radio" name="type"
value="<?php echo $row['cust_acclvl']; ?>" id="<?php echo $row['cust_acclvl']; ?>"><br /><br />
<input type="hidden" name="acclvl"
value="<?php echo $row['cust_acclvl']; ?>"><br /><br />
<input type="submit" name="submit" value="Update">
</form>
<?php
} else {
$city_update2 = "SELECT * FROM areas WHERE area_id = '" . $_POST['city'] ."'";
$result_city_update2 = mysql_query($city_update2)
or die(mysql_error());
$row_city2 = mysql_fetch_array($result_city_update2);
$query = "SELECT * FROM customers WHERE cust_id = '" . $_GET['id'] . "'";
$result = mysql_query($query)
or die(mysql_error());
$row = mysql_fetch_array($result);
$query2 = "SELECT * FROM areas ORDER BY area_city";
$result2 = mysql_query($query2)
or die('Could not get cities; ' . mysql_error());
$row2 = mysql_fetch_array($result2);
?>
<form action="update_user.php" method="post">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
First Name: <br /><input type="text" name="first_name"
value="<?php echo $row['first_name']; ?>"><br /><br />
Last Name: <br /><input type="text" name="last_name"
value="<?php echo $row['last_name']; ?>"><br /><br />
Password: <br /><input type="password" name="password"
value=""> Not displayed<br /><br />
Address line1: <br /><input type="text" name="addr1"
value="<?php echo $row['cust_addr1']; ?>"><br /><br />
Address line2: <br /><input type="text" name="addr2"
value="<?php echo $row['cust_addr2']; ?>"><br /><br />
Town/City: <br /><select name="city">
<option value="" selected="selected">Select a city</option>
<?php while ($row2 = mysql_fetch_array($result2)){
echo " <option value=\"" . $row2['area_id'] ."\">" . $row2['area_city'] .
"</option>\n";} ?>
</select><br /><br />
Province: <br /><input disabled type="text" name="province"
value="<?php echo $row['cust_province']; ?>"> - Will update once info saved<br /><br />
Zip: <br /><input disabled type="text" name="zip"
value="<?php echo $row['cust_zip']; ?>"> - Will update once info saved<br /><br />
Phone: <br /><input type="text" name="phone"
value="<?php echo $row['cust_phone']; ?>"><br /><br />
Cell: <br /><input type="text" name="cell"
value="<?php echo $row['cust_cell']; ?>"><br /><br />
Fax: <br /><input type="text" name="fax"
value="<?php echo $row['cust_fax']; ?>"><br /><br />
Email: <br /><input type="text" name="email"
value="<?php echo $row['cust_email']; ?>"><br /><br />
Type: (buyer or registrar) <br />Buyer: <input type="radio" name="type"
value="<?php echo $row['cust_acclvl']; ?>" id="<?php echo $row['cust_acclvl']; ?>">
Registrar: <input type="radio" name="type"
value="<?php echo $row['cust_acclvl']; ?>" id="<?php echo $row['cust_acclvl']; ?>"><br /><br />
<input type="hidden" name="acclvl"
value="<?php echo $row['cust_acclvl']; ?>"><br /><br />
<input type="submit" name="submit" value="Update">
<input type="button" value="Cancel" onclick="history.go(-1);">
</form>
<?php
}
?>