Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to give a user's question a URL based on it's ID in MySQL, so one may access it in the future?
    primarykey
    data
    text
    <p>For some reason, I just can't seem to get my head around this concept. Any advice/hints will be appreciated. As of now, I have this code:</p> <pre><code>if(isset($_GET['ID'])) {//Check if ID exists in $_GET $ID = mysql_real_escape_string($_GET['ID']); //prevent sql injection $resc = mysql_query("SELECT Message, Title, Type FROM Discussion WHERE ID='$ID' LIMIT 1");//Query the db for record if(mysql_num_rows($resc) == 1) { //make sure the question exists $ques = mysql_fetch_assoc($resc); //convert mysql resource into array that can be used throughout script } } </code></pre> <p>Ok, so the above code simply allows me to access a particular <code>row</code> in this case, and from it, acquire the necessary information I may need. But what I want to know is, what if I want to give that question a URL? For example, when I post my(this) question on Stackoverflow, it will most likely be saved in a database, and will adopt an ID or something similar, so members of the community and I can reference to it at a later time. This will allow everyone to click on 'this' question because it will have a specific ID/reference. Similarly, I do have a specific ID in the MySQL table for the unique rows/questions, but how can I access a URL with that specific ID? I.e. be directed to that actual question when I click on it.<br> For example, the code that I have illustrated above comes from <code>savedisc.php</code>, which is simply saving a user's discussion acquired by a form in simple text into a MySQL table. So at a later time, when I do decide to access this discussion, how can I 'click' on it. I of course don't want to be directed to <code>savedisc.php</code> to see the user's discussion, but maybe something like <code>savedisc.php?id=115521</code>, considering that the actual question's information is indeed associated with the <code>primary key ID=115521</code>. Will I have to make another field or something?</p> <p>Maybe I am doing something wrong in the code below? This comes from <code>savedisc.php</code>:</p> <pre><code>$message = $_POST['message']; $title = $_POST['title']; $represents = $_POST['represents']; $ID = $_GET['ID']; $sql="INSERT INTO Discussion (ID, Message, Title, Type) VALUES ('','$message','$title','$represents')"; </code></pre> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload