Web Hosting Talk







View Full Version : auto_increcment


brcolow
09-22-2002, 05:14 PM
Hey i have this code...


<?
if (!$title || !$about || !$title || !$source)
{
echo "You have not completed all of the required feilds in your article report.<br>"
."please go back and try again.";
exit;
}

$title = addslashes($title);
$about = addslashes($about);
$screenshots = addslashes($screenshots);
$source = addslashes($source);

@ $db = mysql_pconnect("localhost", "mike", "notshown");
if (!$db)
}
echo "Could not connect to database.";
exit;
}
mysql_select_db("news");

CREATE TABLE articles (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
article CHAR(100000) NOT NULL,
PRIMARY KEY (id)
);

$query = "inert into articles (article) values
('".$title"', '".$about."', '".$screenshots"', '".$source."')";
$result = mysql_query($query);
if ($result)
echo mysql_affected_rows()." Article insterted into database.";
?>


Now, i want to be able to make it so people can go to the page articles.php?id=whatever how do i do that?

CChard
09-22-2002, 05:49 PM
Well... to start i dont know why you have that CREATE TABLE there.

CHAR won't go any higher than 255. Use "TEXT" for that information.

To get an auto_increment to work you need to do this:

...values ("null", '".$title"', '".$about."', '".$screenshots"', '".$source."')";


mySQL will fill in the NULL as the next number in the ID.

Remeber to have the INSERT set up in the same order as your table. And you can't skip entering any. If you want to skip just put "NULL" or " ".

brcolow
09-22-2002, 06:34 PM
Ok now this is what i have

<?
if (!$title || !$about || !$title || !$source)
{
echo "You have not completed all of the required feilds in your article report.<br>"
."please go back and try again.";
exit;
}

$title = addslashes($title);
$about = addslashes($about);
$screenshots = addslashes($screenshots);
$source = addslashes($source);

@ $db = mysql_pconnect("localhost", "mike", "notshown");
if (!$db)
}
echo "Could not connect to database.";
exit;
}
mysql_select_db("news");

CREATE TABLE articles (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
TEXT,
PRIMARY KEY (id)
);

$query = "insert into articles (article) values
("null", '".$title"', '".$about."', '".$screenshots"', '".$source."')";

$result = mysql_query($query);
if ($result)
echo mysql_affected_rows()." Article insterted into database.";
?>

Is that right? and i am still unclear about how to make like articles.php?id=1 a real link and how to make articles.php?id=1 pull the information for the auto_increment of the corresponding number, thanks alot, mike

brcolow
09-22-2002, 09:40 PM
HELP ME!!! i really ned this!

brcolow
09-23-2002, 08:00 PM
another bump goes by DODODOODO

CChard
09-23-2002, 10:02 PM
I just took this code from my own program, so you will have to edit it... but:


$result = mysql_query("select * from files WHERE type='$type' AND status='0' ORDER BY '$order'");
}
if (!mysql_num_rows($result)==0)
{
while($row = mysql_fetch_array($result))
{
echo "<tr><td align='center'><a href='download.php?id=".stripslashes($row['id'])."' target='_blank'>".stripslashes($row['name'])."</a></td>";
echo "<td width='300' align='center'>".stripslashes($row['dis'])."</td>";
echo "<td align='center'>".stripslashes($row['div'])."</td>";
echo "<td align='center'>".stripslashes($row['version'])."</td>";
echo "<td align='center'>".stripslashes($row['updated'])."</td>";
echo "<td align='center'>".stripslashes($row['downloads'])."</td>";
echo "</tr>";
}
}
else
{
echo "<td width='100%' colspan='6' align='center'>No files of this type!</td>";
echo "</tr>";
}

It should get you started.

brcolow
09-23-2002, 10:15 PM
ok, ill just edit it to fit my needs, thanks alot