THIS CODE IS TO DISPLAY THE DATA FROM THE DATABASE AFTER THE FORM HAS BEEN SUBMITTED.
THE PROBLEM I'M HAVING HERE IS THAT WHEN I SUBMIT THE FORM THE LINK IS NOT WORKING.
IT GIVES ME THIS : http://yourweb.com/test2.php?id= INSTEAD OF : http://yourweb.com/test2.php?id=23
HOW CAN I FIX THIS?
THANK YOU!

<?php
    if (isset($_POST['mytext'])) {
    $myt = $_POST['mytext'];
    $mymysql = mysql_connect("","","") or die ("can't connect");
    mysql_select_db("", $mymysql );
    $sql = "INSERT INTO content (content) VALUES ('$myt')";
    mysql_query( $sql, $mymysql );
    $sql = mysql_insert_id();
    $row = mysql_query($sql, $mymysql);
    $myid=$row['id'];
    mysql_close ($mymysql);
    echo "<a href='http://yourweb.com/test2.php?id='.$myid>Link</a>";
    }
    ?>
Member Avatar for diafol
 $sql = mysql_insert_id();
    $row = mysql_query($sql, $mymysql);
    $myid=$row['id'];
    mysql_close ($mymysql);
    echo "<a href='http://yourweb.com/test2.php?id='.$myid>Link</a>";

Where's the mysql_fetch_array/mysql_fetch_assoc etc?

$row['id'];

doesn't exist

I NEED HELP ON THIS BECAUSE I HAVE NO CLUE WHAT IM DOING!
HOW CAN I USE THIS: mysql_fetch_array/mysql_fetch_assoc TO SOLVE THIS PROBLEM?
Thank you for your help

Member Avatar for diafol

Doh! My mistake sorry - no need for that

$sql = mysql_insert_id();
$row = mysql_query($sql, $mymysql);
$myid=$row['id'];

You seem to be running a query on a number. Why not just cut all that out

if (isset($_POST['mytext'])) {
    $mymysql = mysql_connect("","","") or die ("can't connect");
    mysql_select_db("", $mymysql );
    $myt = mysql_real_escape_string($_POST['mytext']);
    $sql = "INSERT INTO content (content) VALUES ('$myt')";
    mysql_query( $sql, $mymysql );
    $id = mysql_insert_id();
    mysql_close ($mymysql);
    echo "<a href='http://yourweb.com/test2.php?id=$id'>Link</a>";
}

THANK YOU! THIS SOLVED MY PROBLEM

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.