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>

Link to comment
Share on other sites

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];
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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