Jump to content

need help with reading from a mysql database


gibigbig

Recommended Posts

ok i have made a script that takes information from a form and adds it to a database. it then displays the data the that was placed into the form with the $_POST[''] function. however, i want it to read off the data that was placed into the form, add it to a database, then in another file ("process.php"), the data will be read STRAIGHT from the database and NOT from the POST function. can anyone help me, this is my code:

<?php

$con = mysql_connect("localhost","USERNAME","PASSWORD");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }mysql_select_db("DATABASE", $con);$sql="INSERT INTO registration (nickname, password, email)
VALUES
('$_POST[nickname]','$_POST[password]','$_POST[email]')";if (!mysql_query($sql,$con))
 {
 die('Error: ' . mysql_error());
 }
$nickname = "$_POST[nickname]";
$password ="$_POST[password]";
$email = "$_POST[email]";

echo $nickname;
mysql_close($con)
?><p>Welcome to narutoking
</p>
<table width="611" border="1" cellspacing="0" cellpadding="0">
 <tr>
   <td>username</td>
   <td>password</td>
   <td>email</td>
 </tr>
 <tr>
   <td><?php echo $username ?></td>
   <td><?php echo $password ?></td>
   <td><?php echo $email ?></td>
 </tr>
</table>
<p> </p>

First of all, clean up your code, man!

 

Then put the resulting registration id into a session variable:

 

<?php

$con = mysql_connect("localhost","USERNAME","PASSWORD");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DATABASE", $con);

$sql="INSERT INTO registration (nickname, password, email) VALUES ('$_POST[nickname]','$_POST[password]','$_POST[email]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
else
  {
  $_SESSION['regID'] = mysql_insert_id($con);
  }
?>

 

Then just query from the other page:

 

<?php
$info = @mysql_fetch_row(@mysql_query("select nickname, password, email from registration where regID = ".$_SESSION['regID'],$con));

$nickname = $info[0];
$password = $info[1];
$email = $info[2];
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.