Hi all,
I'm having problems passing my variables using thru the url. Here's the code.

$connection = mysql_connect($dbhost, $dbusername, $dbpassword) or die (mysql_error());
		mysql_select_db($dbname, $connection);

//i use this line to test that variable id has been passed. 
 //this also happens to be the error point
		$test = "select * from jobpost where id=".$_GET['id'];
		echo $test;
		$run = mysql_query($test) or die(mysql_error());
		$row = mysql_fetch_assoc($run);
 		if ($_SERVER['REQUEST_METHOD'] == 'GET'){
<form method="post" enctype="application/x-www-form-urlencoded" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<legend>Edit Vacancy</legend>
    <label for="jobtitle">Job Title</label>
   	<input type="text" name="jobtitle"  value="<?php echo htmlentities($row['jobtitle']); ?>"/><br />
    <label for="jobdescription">Job Desription</label>
    <textarea name="jobdescription" cols="50" rows="10" ><?php echo strip_tags( nl2br (($row['jobdescription']))); ?></textarea><br />
   <label for="jobqualifications">Job Qualifications</label>
    <textarea name="jobqualifications" cols="50" rows="10" ><?php echo strip_tags(nl2br(($row['jobqualifications']))); ?></textarea>
    <input type="hidden" name="id2" value="<?php echo $_GET['id']; ?>" />
<input name="Submit" type="submit" value="Update" />
<?php  } else {							
		$jobtitle = $_POST['jobtitle'];
		$jobdescription = $_POST['jobdescription'];
		$jobqualifications = $_POST['jobqualifications'];
	 $query = "UPDATE jobpost SET jobtitle= '$jobtitle', jobdescription= '$jobdescription', jobqualifications= '$jobqualifications'  WHERE id=$_GET['id']";
 $result = mysql_query($query) or die (mysql_error());

running this code give the following error:
Notice: Undefined index: id in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\pmd\edit_vacancies.php on line 17
select * from jobpost where id=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Can someone please help!!!!!

Edited by simiking: n/a

8 Years
Discussion Span
Last Post by colweb
// test if the variable id has been passed
// if id is there, $id will be the id value otherwise it will be null.
$id = isset($_GET['id']) ? $id = $_GET['id'] : null
if ($id == "") {
	// no id - through in an error and exit.
	echo "<p>Didn't recieve an id from you.</p>";

// So we have an id (in $id)

$connection = mysql_connect($dbhost, $dbusername, $dbpassword) or die (mysql_error());
mysql_select_db($dbname, $connection);

// Don't use $_GET['id'] but use $id from this point on.
// -- rest of your code --

You should always use isset to see it a variable is passed. $_SERVER == 'GET' may not be populated on certain web-servers / configurations, whereas the $_GET array will always exist in PHP4 / 5.
I assume you now that using $_GET means your url should look like "http://localhost/edit_vacancies.php?id=123". If you forget to send the id this way, it will never be available in your php code (and isset will be false).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.