Jump to content

[SOLVED] 1st day of php/MySQL. I'm missing something here...


erikbeam

Recommended Posts

My goal is to send an email link to customers that includes their gallery number in the URL, so the website knows which information they get to see after they create an account.

 

Ex:  Click here to view your gallery:  www.xyz.com/form.php?gallery=123456

 

I've got /form.php setup to get username and password and send them to a dynamic page that will display their images based on the initial gallery number:

 

<form action="insert.php?gallery=<?php echo $gallery;?>" method="post">

 

Username: <input type="text" name="username" />

 

Password: <input type="password" name="password" />

 

Then in "/insert.php" I want to post the username, password, and gallery number to the MySQL database:

 

$sql="INSERT INTO customer (username, password, gallery)

VALUES

('$_POST[username]','$_POST[password]','$_POST[gallery]')";if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

 

The username and password both post to the database, but the gallery value is blank.  The "?gallery=123456" part passes to /insert.php just fine, and to double check that the gallery value is passed I put in an:

 

echo "Welcome to gallery " . $gallery . ", " . $username .".";

 

The gallery number shows up fine here.  I've tried declaring "gallery" in the MySQL table as both VARCHAR and INT.  VARCHAR will leave a blank value and INT leaves a value of 0.

 

Any idea where I went wrong?

Hey there,

 

Try this

 

$sql="INSERT INTO customer (username, password, gallery)
VALUES ('".$_POST["username"]"'."'$_POST["password"]'".'"$_POST["gallery"].'")";

if (!mysql_query($sql,$con))  //Do you have a varaible  $con  in your script somewhere's that actually performs a function (db connection, etc)
  {
  die('Error: ' . mysql_error());
  }

The problem you have lies in where you are trying to get the value of gallery from.

 

Try the following:

$sql="INSERT INTO customer (username, password, gallery)
VALUES
('$_POST[username]','$_POST[password]',$_GET[gallery])";

 

The reason for this is because although you are using the post method for the form, the url submitted is where you are passing the gallery variable, and as such it will be in the $_GET array, not the $_POST array.

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.