Jump to content

Is there a better way to do this?


drewbix

Recommended Posts

Hi everyone, I'm self taught and still learning. I have this code working just the way I want, but I feel like there must be a more efficient way of doing it. Basically my php document uses if ($_SERVER['REQUEST_METHOD'] == "POST"), then I collect a bunch of values from the form, connect to the database and insert them. Then just below that on the same page if the insert is successful, I want to have a link to now view the entry we just did, so I use this code:

 

$query = "SELECT * FROM entry ORDER BY ID DESC limit 0, 30";
$result=mysql_query($query) or die ( mysql_error() );
$entryID=mysql_result($result,0,"ID");
echo '<p><a href="view.php?id=' . $entryID . '" target="_blank">View your entry</a></p>';

 

It seems like there should be a way to know the ID without doing a new query, and I wonder if it might present problems if people insert entrys at the same time or something like that, I'm not sure exactly. Hopefully this makes sense, do you guys have any recommendations?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.