logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: PHP. $_POST not being recognised.
Author
twoheadedcow



Joined: 08 Feb 2008
Posts: 1

PostPosted: Fri 08 Feb '08 17:50    Post subject: PHP. $_POST not being recognised. Reply with quote

I am writing a contact database. Is it working okay apart from Update.

The script below lets the user pick the client, view it with the data displayed in text field form elements. Then they can click on update (CODE IN RED AT THE BOTTOM) which should overwrite the existing value, but it does not, it just enters in a blank result.

I can hard code a value into it and it works okay, but the $_POST is not picking up the value from the field and overwriting it.

Any ideas?

Thanks,
Phil

<?php
//connect to database
$mysqli = mysqli_connect("localhost", "hostsUn", "XXXXXXX", "hostsdomains");

if (!$_POST) {
//haven't seen the selection form, so show it
$display_block = "<h1 class='title'>View Client</h1><div class='entry'>";

//get parts of records
$get_list_sql = "SELECT id,
CONCAT_WS(', ', clientName) AS display_name
FROM client ORDER BY clientName";
$get_list_res = mysqli_query($mysqli, $get_list_sql) or die(mysqli_error($mysqli));

if (mysqli_num_rows($get_list_res) < 1) {
//no records
$display_block .= "<p><em>Sorry, no records to select!</em></p>";

} else {
//has records, so get results and print in a form
$display_block .= "
<form name= \"form1\" method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
<p><strong>Select a Record to View:</strong><br/>
<select name=\"sel_id\">
<option value=\"\">-- Select One --</option>";

while ($recs = mysqli_fetch_array($get_list_res)) {
$id = $recs['id'];
$display_name = stripslashes($recs['display_name']);

$display_block .= "<option value=\"".$id."\">".$display_name."</option>";
}

$display_block .= "
</select>
<p><input type=\"submit\" name=\"submit\" value=\"View Selected Entry\"></p>
</form>";

}
//free result
mysqli_free_result($get_list_res);

} else if ($_POST) {
//check for required fields
if ($_POST["sel_id"] == "") {
header("Location: updateentry.php");
exit;
}

//get master_info
$get_master_sql = "SELECT concat_ws(' ', clientName) as display_name
FROM client WHERE id = '".$_POST["sel_id"]."'";
$get_master_res = mysqli_query($mysqli, $get_master_sql) or die(mysqli_error($mysqli));

while ($name_info = mysqli_fetch_array($get_master_res)) {
$display_name = stripslashes($name_info['display_name']);
}



$display_block = "<form name= \"form2\" method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";

$display_block .= "<h1 class='title'>$display_name</h1><div class='entry'>";

//free result
mysqli_free_result($get_master_res);



#############################################################################################################
//get all hosting details

$get_hosting_sql = "SELECT domainURL FROM domainHosting WHERE id = '".$_POST["sel_id"]."'";

$get_hosting_res = mysqli_query($mysqli, $get_hosting_sql) or die(mysqli_error($mysqli));

if (mysqli_num_rows($get_hosting_res) > 0) {

$display_block .= "<h3>Hosting / Domain Settings:</h3><p><ul>";

while ($add_info = mysqli_fetch_array($get_hosting_res)) {
$domainUrl = $add_info['domainURL'];





$display_block .= "<h2>Domain and Hosting</h2><br /><p class='links'>
<strong>Domain Name:</strong><br/>
<input type=\"text\" name=\"domainURL_New\" size=\"30\" maxlength=\"200\" value=\"$domainUrl\"><br/>
</p><br /><br />";


}

$display_block .= "</p></ul>";
}

//free result
mysqli_free_result($get_hosting_res);

#############################################################################################################
}



$display_block .= "<input type=\"hidden\" name=\"master_id\" value=\"".$_GET["master_id"]."\">";
$display_block .= "<input type=\"submit\" name=\"submit\" value=\"Update Entry\">";

$display_block .= "</form>";






if (($_POST)){

$domainLOL = $_POST["domainURL_New"];

$get_update_sql = "UPDATE domainHosting SET domainUrl = '$domainLOL' WHERE id = '".$_POST["sel_id"]."'";
$get_update_res = mysqli_query($mysqli, $get_update_sql) or die(mysqli_error($mysqli));

}
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Fri 08 Feb '08 18:10    Post subject: Reply with quote

Things you can do.

enable error reporting

error_reporting(E_ALL & ~ E_NOTICE);

Check the outputs like

print_r($_POST);

give out the sql

echo $get_update_sql;

to see what is in it.
Back to top


Reply to topic   Topic: PHP. $_POST not being recognised. View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner