Hi,
I've got a little further and now i'm stuck again
I've used some code that i found here, and adapted it to meet the needs of my site
The problem is that the submit button does not work properly, and the username cookie and link are not inserted into the table.
there are 2 pages used to acheive this, although i'd rather it just did it when you hit the buttin, rather than go to another page, then have to return to add more links
The Code - ignore the page names
add link page - http://www.everyonlinestore.co.uk/change_password.php
<?php
echo $_COOKIE["mysite_username"];
?>
<?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 "<FORM action=addlinks.php method=post><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><p align=center>$user2</p><p align=center>rating</p><p align=center><input type=submit></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></form>"; // end the table
?>
Sumit page query
// 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 (!$_POST['$mysite_username']) {
echo "You did not enter a Username.<br>";
echo $_COOKIE["mysite_username"];
echo "<a href=change_password.php>Please Try again</a>";
exit;
}
// check link entered
if (!$_POST['$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['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>";
}
?>
Thanks in advance
if you're gettign an error on the change_password page, it because you're not logged in.
click the banner and sign up if you like
then log in, and go back to the change_password page. refresh browser
Thankyou!