Jump to content

Recommended Posts

Hi,

 

i'm so close but it doesn't work!

 

what i would like to do is press the button, and it inserts the username from their cookie, and the link (full text) into a sql table...

 

This code displays my links nicely on the page,in a grid,  in their own seperate forms.

 

see - http://www.everyonlinestore.co.uk/change_password.php   (ignore the name)

 

Code1

<?php


$conn = mysql_connect($server, $db_user, $db_pass)
or die ("could not connect to mysql");  #Connect to mysql
$rs = mysql_select_db( $database, $conn )
or die ("Could not select database"); #select database 

$sql = "Select link FROM links";  //pull the users from the table

$result= mysql_query($sql)
or die(" Could not add style facts");

echo "<table align=center border=1>";        // display the users in table
$c = 0;
while($row = mysql_fetch_array($result)) { 
  $user2 = $row['link'];
  if($c%5 == 0) echo "<tr height=\"100px\">"; // If the counter has ticked 6 times, start a new row.
echo "<td><FORM action=addlinks.php method=post><p align=center>$user2</p><p align=center>rating script here</p><p align=center><input type=submit></form></p>";

  if($c%5 == 4) echo "</tr>"; // If we're drawing the 6th pic, end this row.
  $c++;
}
if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row
echo "</table>"; // end the table

?>

end of code1

 

Then this bit of php should insert them into the table.

 

however the variables are undefined...?

 

probably becaused they're not named in code1, but i can't name them inside the " "'s

 

I'm so stuck...!

 

code2

<?php 

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

// check if the link has already been added to username
$mysite_username = $_COOKIE["mysite_username"];
$check = "SELECT link FROM memberlinks WHERE username = '$mysite_username'"; 

$qry = mysql_query($check)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) { 
echo "you have already added that link.<br>";
echo "<a href=Change_password.php>Back</a>";
exit; 
}

// check username entered
if (!$mysite_username) {
echo "You did not enter a Username.<br>";
echo "<a href=change_password.php>Please Try again</a>";
exit;
}

// check link entered
if (!$user2) {
echo "You did not enter a link.<br>";
echo "<a href=change_password.php>Please Try again</a>";
exit;
}

else {



// insert the data
$insert = mysql_query("insert into memberlinks values ('".$_POST[$_COOKIE[mysite_username]]."', '".$_POST['$user2']."')")
or die("Could not insert data because ".mysql_error());

// print a success message
echo $_COOKIE["mysite_username"];
echo "Your link has been added!<br>"; 
echo "Now you can <a href=change_password.php>add another link</a>"; 
}

?>

end of code2

 

Thanks in advance for all your help

 

I'd love to get this sorted out, and no-one i know does PHP.... ::)

Link to comment
https://forums.phpfreaks.com/topic/95634-why-doesnt-my-code-work-please-help/
Share on other sites

your form doesn't have any form elements except a button so $_POST['user2'] won't be passed (i assume you mean $_POST['user2'] and not $_POST['$user2']);

 

also

$_POST[$_COOKIE[mysite_username]]

should be probably be

$_COOKIE['mysite_username']

 

thats after a quick look..

Thanks

 

well...it's not hidden

 

basically this is what i'm trying to do:

 

When you click the button i want it to insert your username from the cookie, and the link into an sql table

 

e.g.

 

username    link_id

johnsmith        link

 

 

Thanks

http://www.everyonlinestore.co.uk/change_password.php

 

this is how it came out

 

it's odd that after you state <..... value='$user2'>

 

it's no longer enclosed in the < >.   it stops and displays the '>

 

have a look

 

cheers

Hey,

 

thanks for helping me out.  i really appreciate it!

 

Here's the entire code.  it's a bit scrappy and hard to look at.

 

i've also put the username bit in with the same method

 

<?php


$conn = mysql_connect($server, $db_user, $db_pass)
or die ("could not connect to mysql");  #Connect to mysql
$rs = mysql_select_db( $database, $conn )
or die ("Could not select database"); #select database 

$sql = "Select link FROM links";  //pull the users from the table

$result= mysql_query($sql)
or die(" Could not add style facts");

echo "<table align=center border=1>";        // display the users in table
$c = 0;
while($row = mysql_fetch_array($result)) { 
  $user2 = $row['link'];
  if($c%5 == 0) echo "<tr height=\"100px\">"; // If the counter has ticked 6 times, start a new row.
echo "<td><FORM action='addlinks.php' method='post'><p><input type=HIDDEN name='user' value='mysite_username'></p><p><input type=HIDDEN name='user2' value='$user2'></p><p align=center>rating script here</p><p align=center><input type=submit></form></p>";

  if($c%5 == 4) echo "</tr>"; // If we're drawing the 6th pic, end this row.
  $c++;
}
if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row
echo "</table>"; // end the table

?>

hmm...

 

this is what the links look like in the table

 

<a href="http://www.dpbolvw.net/click-2804964-5590692" target="_blank" onmouseover="window.status='http://www.argos.co.uk';return true;" onmouseout="window.status=' ';return true;"><img src="http://www.awltovhc.com/image-2804964-5590692" width="120" height="60" alt="Argos.co.uk 120x60" border="0"/></a>

 

is it the

</a>

on the end...?

 

are you saying like:

 

\"$user2"\

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.