Hello, I am attempting to create a script where a user puts a text string into a form and clicking on submit. Then it adds that text string to a mysql database and gives the user a link back to it. Something like mysite.com/key.php?id=4 and when going to that link it will display the text string from the database but printed in an image. I wrote something up but I cannot get it to work. I may be a little in over my head. Any help is appreciated.
The way I coded this all to work is the user inputs the information into index.php which givekey.php inserts that into the database. I have not yet figure out how to do this in one single step. After that I wanted it to navigate directly to key.php which would display the key and the link to that page with the ?key=XX attribute. getkey.php
<?php
require_once 'dbinfo.php';
// database connection
$id = $_GET['id'];
// do some validation here to ensure id is safe
$link = mysql_connect($servername, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
@mysql_select_db($database) or die( "Unable to select database");
$sql = "SELECT ukey FROM keycode WHERE id=$id";
$result = mysql_query("$sql");
$row = mysql_fetch_assoc($result);
mysql_close($link);
header("Content-type: image/png");
echo $row['ukey'];
?>
key.php
<html>
<head>
<title>Your Key Is Ready</title>
</head>
<body>
<img src="getkey.php?id=1" width="175" height="200" />
</body>
</html>
index.php
<html>
<head>
<title></title>
</head>
<body>
<section id="mid_section">
<div id="boxes">
<h1>
Testing input key
</h1>
<br/>
<form id="myform" action="givekey.php" method="post">
Key:<br />
<input type="text" value="ukey">
Source:<br />
<input type="radio" value="hb">HB<br />
<input type="radio" value="ig">IG<br />
<input type="radio" value="other">Other<br />
<button id="sub">Submit</button>
</form>
</body>
</html>
givekey.php
<?php
include_once('dbinfo.php');
$conn = mysql_connect($servername, $username, $password);
$db= mysql_select_db($database);
$ukey =$_POST['ukey'];
$hb =$_POST['hb'];
$ig =$_POST['ig'];
$other =$_POST['other'];
if(mysql_query("INSERT INTO `keycode`(`ukey`) VALUES ([$ukey]); INSERT INTO `source`(`hb`,`ig`,`other`) VALUES ([$hb],[$ig],[$other]);"))
?>