I am trying to create a system that adds $repeats amount of links to the database.
The only problem is that I need each "$query =" to have a different query number on the end.
I came up with this system.
<?
session_start();
?>
<? include ("user_details.php");?>
<?php
/* Connecting, selecting database */
$link = mysql_connect("localhost", "$dbusername", "$dbpassword")
or die("Could not connect");
mysql_select_db("$dbname") or die("Could not select database");
$insert = "INSERT INTO pages (name,type)
VALUES ('$page_name','links')";
mysql_query($insert) or die ("Could not add data to the table");
?>
<?php
/* Connecting, selecting database */
$link2 = mysql_connect("localhost", "$dbusername", "$dbpassword")
or die("Could not connect");
mysql_select_db("$dbname") or die("Could not select database");
$query2 = "SELECT * FROM pages WHERE name = '$page_name'";
$result2 = mysql_query($query2) or die("Query failed");
$foo=mysql_fetch_array($result2);
$page_id=$foo['page_id'];
mysql_close($link2);
?>
<?
$loop=0;
while ($loop<$repeats)
{
$loop++
?>
<?php
/* Connecting, selecting database */
$link3_$loop = mysql_connect("localhost", "$dbusername", "$dbpassword")
or die("Could not connect");
mysql_select_db("$dbname") or die("Could not select database");
//The next line is line 41
$insert3_$loop = "INSERT INTO page_links (page_id,name,link_url)
VALUES ('$page_id','$link_name_$loop','$link_url_$loop')";
mysql_query($insert3_$loop) or die ("Could not add data to the table");
?>
<?
}
?>
Congrats; link <?=$page_name?> added to the database. <br>
Click <a href="main.php">here</a> to return to the homepage
I get the following error:
Parse error: parse error, unexpected T_VARIABLE in C:\apache_server\Apache2\htdocs\burgate\php\admin\add_links_page_process.php on line 41
I have pointed out line 41 for you...
U also need to know that the adding links form is looped as well. Hense "$repeats" is from the form to tell the script how many times to repeat.
Also, the names of the form link_name_$loop etc are there and co-incide with the numbers from the form so everything gets placed in the right place..
Alex.