0

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>";
    }
    ?>
2
Contributors
4
Replies
32
Views
3 Years
Discussion Span
Last Post by Cristianh21
0
 $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

0

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

0

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>";
}

Edited by diafol

This question has already been answered. 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.