Forum Moderators: coopster

Message Too Old, No Replies

problem with amendment script

not amending my data

         

togethercomms

11:47 am on Jul 2, 2009 (gmt 0)

10+ Year Member



I have this script that is supposed to edit the data from the form on the previous page, it works, but too well, it is amending all the data in the table so all entries look the same as each other.

How do i make it only amend the result i want it to?
also on the success screen it comes up with this error

Warning: mysqli_close() expects exactly 1 parameter, 0 given in /homepages/16/d88487104/htdocs/veritas/test/amend-script.php on line 64

Many Thanks

$title = $_POST['title'];
$salary = $_POST['salary'];
$desc = $_POST['description'];
$short = $_POST['short'];
$end = $_POST['end_date'];
$location = $_POST['location'];

$con = mysqli_connect("#*$!x", "#*$!x", "#*$!x", "#*$!x");

$query = "UPDATE job_board SET title = '$title', salary = '$salary', description = '$desc', short = '$short', end_date = '$end', location = '$location'";
mysqli_query($con, $query) or die("Can't execute insert query: " . mysqli_error());
?>

Pico_Train

2:39 pm on Jul 2, 2009 (gmt 0)

10+ Year Member



You need to tell which id to update I think.

$query = "UPDATE job_board SET title = '$title', salary = '$salary', description = '$desc', short = '$short', end_date = '$end', location = '$location'";

add a hidden input type for the job_board_id or whatever is the primary key of the job_board table and add this too at the end of $query

where job_board_id = $_POST['job_board_id']

togethercomms

2:59 pm on Jul 2, 2009 (gmt 0)

10+ Year Member



cheers, but now i'm getting the mysql error: no database selected.

II have done a little research and found this is usually because the user hasn't got privaledges to access the database.

I know this isn't true for me as it updated the fields before just not the right ones, so whats going on?

I'm stumped

togethercomms

3:19 pm on Jul 2, 2009 (gmt 0)

10+ Year Member



$query = "UPDATE job_board SET title = '$title', location = '$location', salary = '$salary', end_date = '$end', description = '$desc', short = '$short'";
mysql_query($query, $con) or die("Can't execute insert query: " . mysql_error());

$id = $_POST['id'];
$title = $_POST['title'];
$salary = $_POST['salary'];
$desc = $_POST['description'];
$short = $_POST['short'];
$end = $_POST['end_date'];
$location = $_POST['location'];

heres the new version of the code

Pico_Train

4:05 pm on Jul 2, 2009 (gmt 0)

10+ Year Member



$id = $_POST['id'];
$title = $_POST['title'];
$salary = $_POST['salary'];
$desc = $_POST['description'];
$short = $_POST['short'];
$end = $_POST['end_date'];
$location = $_POST['location'];

$con = mysqli_connect("#*$!x", "#*$!x", "#*$!x", "#*$!x");

$query = "UPDATE job_board SET title = '$title', location = '$location', salary = '$salary', end_date = '$end', description = '$desc', short = '$short' where job_board_id = '$id'";
mysql_query($query, $con) or die("Can't execute insert query: " . mysql_error());

change job_board_id for the column name in that table. Change the connection to the write username and db too.

togethercomms

4:13 pm on Jul 2, 2009 (gmt 0)

10+ Year Member



thanks, but still getting the 'no database selected' error.

In the connecting string i have 'host, username, password, database'

And i put in the id = $id string, i dunno where i'm going wrong.

thanks

Pico_Train

11:18 am on Jul 3, 2009 (gmt 0)

10+ Year Member



Try this:

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

$dbname = ('db_you_want_to_use',$link);
mysql_select_db($dbname);

?>

What does that say? Don't forget to change the username and password to the correct ones in the code above...Change db_you_want_to_us to the name of your database.

If that works all fine, try putting your query and stuff after that and give it a go...

[edited by: Pico_Train at 11:25 am (utc) on July 3, 2009]

Pico_Train

11:26 am on Jul 3, 2009 (gmt 0)

10+ Year Member



Put your query after the above like this within the php tags. Notice the $con is gone in mysql_query($query)

$query = "UPDATE job_board SET title = '$title', location = '$location', salary = '$salary', end_date = '$end', description = '$desc', short = '$short' where job_board_id = '$id'";
mysql_query($query) or die("Can't execute insert query: " . mysql_error());

togethercomms

2:27 pm on Jul 3, 2009 (gmt 0)

10+ Year Member



great worked like a treat, a little fiddling but i got it many thanks all

Pico_Train

4:58 pm on Jul 3, 2009 (gmt 0)

10+ Year Member



Good to hear! Keep at it.