Dynadot โ€” .com Registration $8.99

Form help please.

Spaceship Spaceship
Watch

shanee86

Established Member
Impact
2
I am trying to program a script for one of my site's. It is pretty easy I guess alot would say but I am a noob at php but I am trying to learn. Anyway I own growlinks.com and I am trying to make a list of directorys were users can add they link to to help get inbound links. And well I tried to make a form and it is not working. What do I want a is a form that ads the varible $url to the database. And on the other page I am displaying the links from the database so when someone adds on it will be listed. But I can't get the form to work. Here is some code:

Directory Name:<br>
<form action="adddir.php" method="post" >
<INPUT NAME="$url" TYPE="text" size="50"><br>
<input type="submit" name="$url" value="Add">
</form>

^is the form to add the link.


<?php
$url = $_REQUEST['$url'];
mysql_connect("localhost", "edited", "edited") or die(mysql_error());
mysql_select_db("humorvid_directorys") or die(mysql_error());

// Insert a row of information into the table "directory1"
mysql_query("INSERT INTO directory1
(url) VALUES('$url')")
or die(mysql_error());

echo 'thanks';

^ is the php on adddir.php to handle the form input. But it is not adding the url to the database any ideas?


The below works and is the first attempt I made but I want a forum to do what the below does:

<?php
mysql_connect("localhost", "edited", "edited") or die(mysql_error());
echo "Connected to MySQL";
mysql_select_db("humorvid_directorys") or die(mysql_error());
echo "Connected to Database";

$id= '1';
$id1='2';
$id2='3';
$url='http://www.01webdirectory.com';
$url1='http://www.abilogic.com';
$url2='http://www.agada.info/web-directory';

echo "Table Created!";
// Insert a row of information into the table "directory1"
mysql_query("INSERT INTO directory1
(id1, url) VALUES('$id', '$url')")
or die(mysql_error());

mysql_query("INSERT INTO directory1
(id1, url) VALUES('$id1', '$url1')")
or die(mysql_error());

mysql_query("INSERT INTO directory1
(id1, url) VALUES('$id2', '$url2')")
or die(mysql_error());

echo "Data Inserted!";

?>
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Try this:
$url = $_POST['url'];

instead of:
$url = $_REQUEST['$url'];
 
0
•••
I changed what you said, and it didn't add it still maybe I made a mistake in the forum? I am sorry I am new to this but trying.

I think it added the entry because in phpmyadmin shows the entrys but the url column is blank.
 
0
•••
You might be able to call it without the explicit. Just use $url instead of:
$url = $_REQUEST['$url'];

This article explains more.
 
0
•••
Hey,

First of all, change the name for your submit button, its should be somehitng else then:
<INPUT NAME="link" TYPE="text" size="50"><br>

$url = $_Post['link'];
mysql_connect("localhost", "edited", "edited") or die(mysql_error());
mysql_select_db("humorvid_directorys") or die(mysql_error());

// Insert a row of information into the table "directory1"
mysql_query("INSERT INTO directory1 url VALUES '$url'") or die(mysql_error());

echo 'thanks';

Your errors is $_Request['$ur']; How can it request an unset variable $url?

Hope this helped!

-Moe
 
0
•••
if the form is gonna use the $url variable in it, it needs to be parsed by the php, meaning that the whole form has to be "echo"ed be the php. try doing it that way and concatenating the $url where its supposed to go.
 
0
•••
I don't get what you mean? Sorry I am noob but I am trying to learn please show me?
 
0
•••
Directory Name:<br>
<form action="adddir.php" method="post" >
<INPUT NAME="$url" TYPE="text" size="50"><br>
<input type="submit" name="$url" value="Add">
</form>

Bingo, there is your problem. Remove the $ before all the names so it looks like this:
Directory Name:<br>
<form action="adddir.php" method="post" >
<INPUT NAME="url" TYPE="text" size="50"><br>
<input type="submit" name="url" value="Add">
</form>

Also, rename the submit button. It isn't good to have it the same name as something else.

moe88 said:
Your errors is $_Request['$ur']; How can it request an unset variable $url?
Err, the REQUEST line is the same as POST and GET mixed togeather. It is normally ok to use it unless you have a get variable the same as a post veriable or vica versa. Though I don't reccomend using the request variable.

Also shane, change $url = $_REQUEST['$url']; to $url = $_REQUEST['url']; alopng with the change I said above. This should work. Never have $ within a variable name.
 
0
•••
WHat Josh said will work, but so will this. Cleaned it up a lil ;)

PHP:
Directory Name:
<br>
<form action="adddir.php" method="post">
<input name="url" type="text" size="50"><br>
<input type="submit" name="submit" value="Add">
</form>

<?php

if(isset($_POST['submit']))
{
  $url = $_POST['url'];

  $db = mysql_connect("localhost", "edited", "edited") or die(mysql_error());
  mysql_select_db("humorvid_directorys", $db) or die(mysql_error());

  // Insert a row of information into the table "directory1"
  $query = mysql_query("INSERT INTO directory1 (url) VALUES('$url')");
  
  if($query)
  {
    echo 'Thanks.';
  }
  else
  {
    die(mysql_error());
  }
}
?>
 
0
•••
I have one more question this is for a different script kind of I am making it all one script but anyway I get this:

Fatal error: Call to undefined function: efine() in /home/humorvid/public_html/growlinks/mysql_connect.php on line 7

When ever I try to sign up at my site at http://growlinks.com/register.php ?

Any ideas? I check the mysql_connect.php and that efine is not on that page on that line or on that page at all any ideas?
 
0
•••
Probably a typo. Should be define() instead of efine()
 
0
•••
Yep I fixed it, it was a typo opps. But now I have one more question ohm I get this now when I try to register:

Fatal error: Call to undefined function: escape_data() in /home/humorvid/public_html/growlinks/register.php on line 17

I checked line 17 and here is line 17 plus the top row bottom etc:



// Check for a first name.
if (eregi ('^[[:alpha:]\.\' \-]{2,15}$', stripslashes(trim($_POST['first_name'])))) {
$fn = escape_data($_POST['first_name']);
} else {

Any ideas? I looked over it and didn't see why?
 
0
•••
0
•••
I think it is a real funtion because I looked it up on google and found something. But I didn't right this script so I have no idea. I can post the code though one minute:

<?php # Script 13.6 - register.php
// This is the registration page for the site.

// Include the configuration file for error management and such.
require_once ('./includes/config.inc.php');

// Set the page title and include the HTML header.
$page_title = 'Register';
include ('./includes/header.html');

if (isset($_POST['submitted'])) { // Handle the form.

require_once ('mysql_connect.php'); // Connect to the database.

// Check for a first name.
if (eregi ('^[[:alpha:]\.\' \-]{2,15}$', stripslashes(trim($_POST['first_name'])))) {
$fn = escape_data($_POST['first_name']);
} else {
$fn = FALSE;
echo '<p><font color="red" size="+1">Please enter your first name!</font></p>';
}

// Check for a last name.
if (eregi ('^[[:alpha:]\.\' \-]{2,30}$', stripslashes(trim($_POST['last_name'])))) {
$ln = escape_data($_POST['last_name']);
} else {
$ln = FALSE;
echo '<p><font color="red" size="+1">Please enter your last name!</font></p>';
}

// Check for an email address.
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
$e = escape_data($_POST['email']);
} else {
$e = FALSE;
echo '<p><font color="red" size="+1">Please enter a valid email address!</font></p>';
}

// Check for a password and match against the confirmed password.
if (eregi ('^[[:alnum:]]{4,20}$', stripslashes(trim($_POST['password1'])))) {
if ($_POST['password1'] == $_POST['password2']) {
$p = escape_data($_POST['password1']);
} else {
$p = FALSE;
echo '<p><font color="red" size="+1">Your password did not match the confirmed password!</font></p>';
}
} else {
$p = FALSE;
echo '<p><font color="red" size="+1">Please enter a valid password!</font></p>';
}

if ($fn && $ln && $e && $p) { // If everything's OK.

// Make sure the email address is available.
$query = "SELECT user_id FROM users WHERE email='$e'";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());

if (mysql_num_rows($result) == 0) { // Available.

// Create the activation code.
$a = md5(uniqid(rand(), true));

// Add the user.
$query = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', SHA('$p'), '$fn', '$ln', '$a', NOW() )";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());

if (mysql_affected_rows() == 1) { // If it ran OK.

// Send the email.
$body = "Thank you for registering at the User Registration site. To activate your account, please click on this link:\n\n";
$body .= "http://www.whateveraddressyouwanthere.com/activate.php?x=" . mysql_insert_id() . "&y=$a";
mail($_POST['email'], 'Registration Confirmation', $body, 'From: [email protected]');

// Finish the page.
echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>';
include ('./includes/footer.html'); // Include the HTML footer.
exit();

} else { // If it did not run OK.
echo '<p><font color="red" size="+1">You could not be registered due to a system error. We apologize for any inconvenience.</font></p>';
}

} else { // The email address is not available.
echo '<p><font color="red" size="+1">That email address has already been registered. If you have forgotten your password, use the link to have your password sent to you.</font></p>';
}

} else { // If one of the data tests failed.
echo '<p><font color="red" size="+1">Please try again.</font></p>';
}

mysql_close(); // Close the database connection.

} // End of the main Submit conditional.
?>

<h1>Register</h1>
<form action="register.php" method="post">
<fieldset>

<p><b>First Name:</b> <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>

<p><b>Last Name:</b> <input type="text" name="last_name" size="30" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>

<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p>

<p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" /> <small>Use only letters and numbers. Must be between 4 and 20 characters long.</small></p>

<p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p>
</fieldset>

<div align="center"><input type="submit" name="submit" value="Register" /></div>
<input type="hidden" name="submitted" value="TRUE" />

</form>

<?php // Include the HTML footer.
include ('./includes/footer.html');
?>


This code came from the site of maker of the book I am learning from so I didn't right it. But any idea now the code is above.
 
0
•••
It's not a function. I did some searching as well. It's a custom function that the author wrote, I'd assume. /includes/config.inc.php ... If it came with a script for that. I'd venture to bet that is the file the function is in.

I found something for it, from somewhere. But basically all it is doing which pretty much does this:

PHP:
$variable = stripslashes(mysql_real_escape_string($_POST['whatever']));

Heh
 
Last edited:
0
•••
So I should just replace that with what you put?

Dang it is changed it to what you put but the error still says the same. I don't get that. The line is changed.

This is what I changed it to below: But still same error help please.

// Check for a password and match against the confirmed password.
if (eregi ('^[[:alnum:]]{4,20}$', stripslashes(trim($_POST['password1'])))) {
if ($_POST['password1'] == $_POST['password2']) {
$p = stripslashes(mysql_real_escape_string($_POST['password1']));
} else {
 
Last edited:
0
•••
I still need help it is not fixed I added the line you told me to please help? Any ideas?
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back