Jump to content

trying to add a id to a certain url


divinedesigns1

Recommended Posts

hello, im trying to add a id from the db to this url <a href="admin/admin.php?action=home">Home</a> but when i try doing <a href="admin/admin.php?action=home?id=' . $display['id'] . '">home</a> it doesnt work, im not good at these kind of links at all i only know the normal way of doing this, but this time i have 2 options on 1 page n this way suits it better, can anyone please teach me how to do this? i also tried <a href="admin/admin.php?action=home&id=' . $display['id'] . '">home</a> but that doesnt work either

Link to comment
Share on other sites

what does the link output?

Link to comment
Share on other sites

nothing it doesnt work, it suppose to pull the data from the db to be edit

Link to comment
Share on other sites

have you check the source code? you have posted partial code. it is possible that it breaks the html somewhere. also instead of mixing single,double quote and concatenation oprator you can do like

echo "<a href='admin/admin.php?action=home?id={$display['id'] }'>home</a>";

with better redability it reduces chances for typos and bugs.

Edited by birbal
Link to comment
Share on other sites

have you check the source code? you have posted partial code. it is possible that it breaks the html somewhere. also instead of mixing single,double quote and concatenation oprator you can do like
echo "<a href='admin/admin.php?action=home?id={$display['id'] }'>home</a>";

with better redability it reduces chances for typos and bugs.

ok ill try that now
Link to comment
Share on other sites

If you are echoing out the whole link
echo '<a href="admin/admin.php?action=home?id=' . $display['id'] . '">home</a>';

just echoing out the id into html

<a href="admin/admin.php?action=home?id=<?php echo $display['id']; ?>">home</a>

that doesnt work
Link to comment
Share on other sites

if($action == "edit"){   // edit the blog created   echo '<h3>Edit Blog</h3>';   if(isset($_GET['id'])){	$id = $_GET['id'];	$sql = "SELECT * FROM article WHERE id='$id'";	$result = mysqli_query($con, $sql);   }elseif(isset($_POST['id'])){	$id = $_POST['id'];	$newquery = "SELECT * FROM article WHERE id='$id'";	$result = mysqli_query($con, $result);   }else{	echo 'Please choose a blog to edit';   }   if(isset($_POST['submit'])){	// making sure all fields are filled if not give out a error	if(empty($_POST['tite'])){	 // check to make sure the title is not empty	 echo 'Title is required';	}else{	 $title = $_POST['title'];	}	if(empty($_POST['message'])){	 // check to make sure the message isnt empty	 echo 'The Body Needs Some Test';	}else{	 $message = $_POST['message'];	}	if(!empty($title) && !empty($message)){	 // if both fields are fill	 $title = mysqli_real_escape_string($con, $title);	 $message - mysqli_real_escape_string($con, $message);		 $query1 = "UPDATE article SET title='$title', body='$message', user_id='" . $_SESSION['uid'] . "' WHERE id='$id'";	 $result = mysqli_query($con, $query1);	 if($result){	  echo 'Blog has been updated';	 }else{	  echo 'Blog was not updated' . '<br/>';	  echo $title . '<br/>';	  echo $message . '<br/>';	 }	}else{	 $query2 = "SELECT * FROM article WHERE user_id='" . $_SESSION['uid'] . "' AND id='$id'";	 $result = mysqli_query($con, $query2);	 $count = mysqli_num_rows($result);		 if($result){	  while($grab = mysqli_fetch_array($result, MYSQLI_ASSOC)){	   echo '<table><tr><td>';	   echo '<form action="admin.php?action=edit=' . $grab['id'] . '" method="post">';	   echo '<table><tr>';	   echo '<td>Title: </td>';	   echo '<td><input type="text" name="title" size="25" maxlength="255" value="'. $grab['title'] .'" /></td>';	   echo '</tr>';	   echo '<tr><td>Article: </td>';	   echo '<td><textarea row="5" cols="40" name="message">' . $grab['body'] . '</textarea></td>';	   echo '</tr><tr>' . '<td></td>';	   echo '<td><input type="submit" name="submit" vaule="submit" /></td>';	   echo '</tr><tr>';	   echo '<td><input type="hidden" name="id" value="'. $grab['id'] .'" /></td>';	   echo '</tr></table>' . '</form></td></tr></table>';	  }	 }else{	  echo 'Blog Could not be edit';	 }	}   }   // this is where editing a blog ends  }elseif($action == "delete"){   // delete a blog created   echo '<h3>Delete Blog</h3>';  }  // this is where the deleting of any blog ends}else{  // if no action is set  echo '<a href="admin.php?action=news">Create</a>' . '   ';  echo '<a href="admin.php?action=edit">Edit</a>' . '   ';  echo '<a href="admin.php?action=delete">Delete</a>' . '   ';  echo '<hr/>';  $display = "SELECT * FROM article";  $result = mysqli_query($con, $display);  if($result){   while($show = mysqli_fetch_array($result, MYSQLI_ASSOC)){	echo $show['title'] . '  -  ' . $show['body'] . '  -  ' . '<a href="admin.php?action=edit?id=' . $show['id'] .'">Edit</a>' . '<br/>';   }  } // this is where the script to show the rows stop}}else{// check to see if the user is logged inif(!isset($_SESSION['uid'])){  echo 'Your Not Log In';}}

the first part of this code, works perfectly fine no error nothing no suppression, etc. but it all wend down hill when i get to here

Edited by DDs1
Link to comment
Share on other sites

The script above holds the scripts that delete, create and edit, and displays the news also but getting the edit part to work, im not sure how to pull this off, i went around on other websites to see if i can fine an ideal in the url. lol you know those websites that always have some extra in its url

Link to comment
Share on other sites

what problem are you facing now? is it still the same issue?

Link to comment
Share on other sites

check result without out if condition or on its own page to test if it retrieves and shows correctly without if else.also

 echo $show['title'] . '  -  ' . $show['body'] . '  -  ' . '<a href="admin.php?action=edit?id=' . $show['id'] .'">Edit</a>' . '<br/>';

should be echo $show['title'] . ' - ' . $show['body'] . ' - ' . '<a href="admin.php?action=edit&id=' . $show['id'] .'">Edit</a>' . '<br/>';

Link to comment
Share on other sites

what problem are you facing now? is it still the same issue?
yup same problem
check result without out if condition or on its own page to test if it retrieves and shows correctly without if else. also
 echo $show['title'] . '  -  ' . $show['body'] . '  -  ' . '<a href="admin.php?action=edit?id=' . $show['id'] .'">Edit</a>' . '<br/>';

should be echo $show['title'] . ' - ' . $show['body'] . ' - ' . '<a href="admin.php?action=edit&id=' . $show['id'] .'">Edit</a>' . '<br/>';

that & is not work, but ill take it off of that page and place it onto a different page and see what happen, sorry about the late reply im also trying to do another project also
Link to comment
Share on other sites

did you check the source of htm to see what does it print?

Link to comment
Share on other sites

did you check the source of htm to see what does it print?
yeah it prints out http://localhost/blog/admin/admin.php?action=edit?id=2 and when i use the & sign inside of the url it prints http://localhost/blog/admin.php?action=edit&id=2 but nothing shows up
Link to comment
Share on other sites

name value pairs should be seperated with & like dsonusk said. what do you mean it does not show anything? if your link is building up correctly next step will be to check edit.php why it is not working.

Link to comment
Share on other sites

The first querystring name/value always start with '?' before it, any additional querystring name/value from there on has a '&' before it.
ok thanks dsone, but imma put this on hold going to try complete the photo album project, since i figure out how to do it without the confusion hehehehehe
Link to comment
Share on other sites

name value pairs should be seperated with & like dsonusk said. what do you mean it does not show anything? if your link is building up correctly next step will be to check edit.php why it is not working.
birbal, that script is in 1 file with the create script and delete script and the display script suppose to be on there also, but ill come back with to this topic, in a bit
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...