Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,174,477 members, 7,891,991 topics. Date: Wednesday, 17 July 2024 at 12:25 AM

Php Programmers, Please Help!!! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Php Programmers, Please Help!!! (1400 Views)

PHP Programmers Please Help With This Code / PHP Programmers, Pls Step In / Nairalanders Programmers Please I Need Your Help (2) (3) (4)

(1) (Reply) (Go Down)

Php Programmers, Please Help!!! by Onyiibazz: 6:31pm On Jul 09, 2015
echo '<p>Click to review price or set availability</p><a href = "test.php?id='.$row['id'].'">'.$row['type'].'</a>';

I have the code above, so i want it take the user to the link provide. So the code below is the test.php page. But once i submit the form, it doesn't update the database table rather it shows that the form field is empty error even when the said fields are not empty. Please you guys should help out a brother, IT IS URGENT. Thanks for the anticipated help!

<?php
session_start();
//Insert the page header
$page_title = 'Update Property';
require_once('p_header.php');
require_once('p_connectvars.php');
?>

<div id = "page" style = "background: url(images/tiles-bg.jpg) top left no-repeat; background-size: cover;">

<?php
//Show the navigation menu
echo '<div id = "navmenu">';
require_once('p_navmenu.php');
echo '</div>';

//Make sure the user is logged in before going any further
if(!isset($_SESSION['id'])){
echo '<p>Please <a href = "p_login.php">log in</a> to access this page.</p>';
exit();
}

//Connect to the database
$dbc = mysql_connect(host, user, password);
mysql_select_db('project');

if(isset($_POST['submit'])){
//Grab the profile data from the post
if(!empty($price) && !empty($availability) && !empty($id)){
if(isset($_GET['id'])){

$id = $_GET['id'];
}else{
$price = mysql_real_escape_string(trim($_POST['price']));
$availability = $_POST['availability'];
}
//Update the data in the database


$query = "UPDATE p_description SET price = '$price', availability = '$availability' WHERE id = '$id'";

mysql_query($query) or die(mysql_error());

//Confirm success with the user
echo '<p class = "success">Your property has been successfully updated.</p>';

mysql_close($dbc);
exit();
}else{
echo '<p class = "error">Please enter a new price and set availability</p>';
}

}

else{
//Grab the profile data from the database
$query = "SELECT id, price, availability FROM p_description WHERE id = '".$_GET['id']."'";
$data = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($data);
if($row != NULL){
$id = $row['id'];
$price = $row['price'];
$availability = $row['availability'];


}else{
echo '<p class = "error">There was a problem accessing the record.</p>';
}
}

mysql_close($dbc);
?>
<form method = "POST" action = "<?php echo $_SERVER['PHP_SELF']; ?>">
<input type = "hidden" name = "id" id = "id" value = "<?php echo $id;?>" />
<fieldset>
<legend>Property Information</legend>
<label for = "price">First name</label>
<input type = "text" name = "price" id = "price" value = "<?php if(!empty($price)) echo $price; ?>"/></br>
<label for = "availability">Availability</label>
<select name = "availability" id = "availability">
<option value = "1" <?php if(!empty($availability)&& $availability == '1') echo 'selected = "selected"'; ?>>Available</option"/>
<option value = "0" <?php if(!empty($availability) && $availability == '0') echo 'selected = "selected"'; ?>>Unavailable</option></select></br>
</fieldset>
<input type = "submit" value = "Save Profile" name = "submit"/>
</form>
</div>



cc dhtml18 and others
Re: Php Programmers, Please Help!!! by A7(m): 9:24pm On Jul 09, 2015
You just cant assign pseudo variables, to get your form inputs you have to use the form method and make a variable hold the records you wanted.

Onyiibazz:

if(isset($_POST['submit'])){
//Grab the profile data from the post
if(!empty($price) && !empty($availability) && !empty($id)){

The red above are undefined variables, they are just there, they hold nothing.

Use:

If (isset($_POST['Submit'])){
$price = $_POST['price'];
$availability = $_POST['availability'];
$id = $_POST['id'];

//you can then check if the fields are empty or not.

If (!empty($price) &&!empty($availability) &&!empty($id)){

//action here

}

}


Or use:


If (isset($_POST['Submit'])){
If(!empty($_POST['price']) &&!empty($_POST['availability']) &&!empty($_POST['id']) ){

//assign on variables.
$price = $_POST['price'];
$availability = $_POST['availability'];
$id = $_POST['id'];

//action here.
}
else {
//action here

}
}

Plus your codes are messy, use external styling or internal, the inline you are using is an eyesore.
Re: Php Programmers, Please Help!!! by Onyiibazz: 9:58pm On Jul 09, 2015
A7:
You just cant assign pseudo variables, to get your form inputs you have to use the form method and make a variable hold the records you wanted.



The red above are undefined variables, they are just there, they hold nothing.

Use:

If (isset($_POST['Submit'])){
$price = $_POST['price'];
$availability = $_POST['availability'];
$id = $_POST['id'];

//you can then check if the fields are empty or not.

If (!empty($price) &&!empty($availability) &&!empty($id)){

//action here

}

}


Or use:


If (isset($_POST['Submit'])){
If(!empty($_POST['price']) &&!empty($_POST['availability']) &&!empty($_POST['id']) ){

//assign on variables.
$price = $_POST['price'];
$availability = $_POST['availability'];
$id = $_POST['id'];

//action here.
}
else {
//action here

}
}

Plus your codes are messy, use external styling or internal, the inline you are using is an eyesore.

Thanks so much, my pc is currently off, no light. I'll try your suggestions when i get 2moro or later 2nite
Re: Php Programmers, Please Help!!! by FRInteractives: 10:50pm On Jul 09, 2015
if you are trying to grab the values from the url do this on the landing page

<?php
$_GET;
if (isset($_GET['id])) {
$id = $_GET['id'];
//other url values
}

Note: if you are passing values or sensitive data via a url stick to using some high security encryption so your links will be safe

1 Like

Re: Php Programmers, Please Help!!! by Urine: 11:11pm On Jul 09, 2015
Onyiibazz:


Thanks so much, my pc is currently off, no light. I'll try your suggestions when i get 2moro or later 2nite

Your usage of mysql caught my eye, you might want to use mysqli or PDO.

2 Likes

Re: Php Programmers, Please Help!!! by Nobody: 6:26am On Jul 10, 2015
Chisox! see codes. . . . . . . .e long like Oshodi bridge to Onitsha bridge!
Re: Php Programmers, Please Help!!! by Onyiibazz: 8:34am On Jul 10, 2015
dhtml18:
Chisox! see codes. . . . . . . .e long like Oshodi bridge to Onitsha bridge!

Oga, abeg say something na
Re: Php Programmers, Please Help!!! by Onyiibazz: 8:49am On Jul 10, 2015
FRInteractives:
if you are trying to grab the values from the url do this on the landing page

<?php
$_GET;
if (isset($_GET['id])) {
$id = $_GET['id'];
//other url values
}

Note: if you are passing values or sensitive data via a url stick to using some high security encryption so your links will be safe


I'm trying to pass the value of id via url. I'll try what you said if i get light today. Thanks
Re: Php Programmers, Please Help!!! by Nobody: 9:20am On Jul 10, 2015
The codes are too scattered for me to read - once the lines of code is exceeding 10. . . .i find it very hard to solve

1 Like

Re: Php Programmers, Please Help!!! by romme2u: 3:11am On Jul 11, 2015
dhtml18:
The codes are too scattered for me to read - once the lines of code is exceeding 10. . . .i find it very hard to solve

rather advised him to segment or separate the codes into data acquisition (model), data manipulation and the output (views) - separation of concerns tongue. i think it will be easier to pinpoint his problem than mixing it(php n html) up .
Re: Php Programmers, Please Help!!! by Nobody: 6:35am On Jul 11, 2015
^^^exactly, otherwise i will still run away from the thread. . . .
Re: Php Programmers, Please Help!!! by Onyiibazz: 1:10am On Jul 12, 2015
Thanks to all that contributed! I've fixed the issue. But i still have another i would want you guys to help me with, maybe il'll share that tomorow
Re: Php Programmers, Please Help!!! by Nobody: 1:12am On Jul 12, 2015
Fantastic, please try to keep your post short so that i will not run away again.
Re: Php Programmers, Please Help!!! by Onyiibazz: 1:13am On Jul 12, 2015
romme2u:


rather advised him to segment or separate the codes into data acquisition (model), data manipulation and the output (views) - separation of concerns tongue. i think it will be easier to pinpoint his problem than mixing it(php n html) up .

Please sir o! Hope you wouldn't mind explaining those terms above please! Am really new to programming!
Re: Php Programmers, Please Help!!! by romme2u: 2:57am On Jul 12, 2015
Onyiibazz:


Please sir o! Hope you wouldn't mind explaining those terms above please! Am really new to programming!

sori for the big big jargons, i can't just help cheesy grin.

there are patterns in which codes are written for ease of maintenance and extending purposes. the popular one is mvc (aka model-view-controller) though there are lot of them. u don't need worry about that, for a start;

1. separate all the code that are connecting to the database into one file.
2. put all ur data manipulation code (all the create, retrieve, update n delete operations) into another file.
3. let ur html n supporting php to print variables stay in yet another file.
4. add html id and class attributes to html tags u are printing in ur previous file (step 3) to ease styling via external stylesheet.
5. remove all css styling to an external file.
6. add comment to each line of ur code to give urself and others a hint of what the code is supposed to do.
7. then post back the code in different chunks so that people can read the post and give help.


what u posted is nearly unreadable . some people like dhtml grin wont have the time nor patience to go through that, n offer u help.

1 Like

Re: Php Programmers, Please Help!!! by Nobody: 5:11am On Jul 12, 2015
^^^Very true bro, I am always in a hurry. See today for example, I slept at around 2am and right now, I am rushing off somewhere again. If a code takes me like 30 minutes to read - and it is free work for that matter, how do i cope?

(1) (Reply)

How Flashshare Is Bad For Developers / My Phone Has Been Hacked / Nancy Fx: How To

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 35
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.